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

Parameter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 8
c 3
b 0
f 2
lcom 1
cbo 0
dl 0
loc 66
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 3 1
A getDescription() 0 3 1
A setDescription() 0 4 1
A isRequired() 0 3 1
A getType() 0 3 1
A __toString() 0 3 1
A withType() 0 4 1
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
}