Completed
Push — master ( 25fd19...64a20d )
by Nikolas
03:08
created

Parameter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4286
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
namespace rtens\domin;
3
4
use watoki\reflect\Type;
5
6
class Parameter {
7
8
    /** @var string */
9
    private $name;
10
11
    /** @var Type */
12
    private $type;
13
14
    /** @var boolean */
15
    private $required;
16
17
    /** @var string */
18
    private $description = null;
19
20
    public function __construct($name, Type $type, $required = false) {
21
        $this->name = $name;
22
        $this->required = $required;
23
        $this->type = $type;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getName() {
30
        return $this->name;
31
    }
32
33
    /**
34
     * @return string|null
35
     */
36
    public function getDescription() {
37
        return $this->description;
38
    }
39
40
    /**
41
     * @param string $description
42
     * @return static
43
     */
44
    public function setDescription($description) {
45
        $this->description = $description;
46
        return $this;
47
    }
48
49
    /**
50
     * @return boolean
51
     */
52
    public function isRequired() {
53
        return $this->required;
54
    }
55
56
    /**
57
     * @return Type
58
     */
59
    public function getType() {
60
        return $this->type;
61
    }
62
63
    public function __toString() {
64
        return $this->name . ':' . $this->type;
65
    }
66
67
    public function withType(Type $type) {
68
        return (new Parameter($this->getName(), $type, $this->isRequired()))
69
            ->setDescription($this->getDescription());
70
    }
71
}