-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.php
50 lines (40 loc) · 922 Bytes
/
example2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Kundennummer (positiver int)
*/
$customerNumber = new CustomerNumber(-4711);
doSomethingElse($customerNumber);
function doSomething(CustomerNumber $customerNumber)
{
doSomethingElse($customerNumber);
}
function doSomethingElse(CustomerNumber $customerNumber)
{
var_dump($customerNumber);
}
class CustomerNumber
{
private $customerNumber;
public function __construct(int $customerNumber)
{
$this->ensureIsPositive($customerNumber);
$this->customerNumber = $customerNumber;
}
public function increment(): void
{
$this->customerNumber++;
}
public function asInt(): int
{
return $this->customerNumber;
}
/**
* @param int $customerNumber
*/
private function ensureIsPositive(int $customerNumber): void
{
if ($customerNumber < 0) {
throw new OutOfBoundsException;
}
}
}