Skip to content

Commit 6ba94b6

Browse files
authored
Merge pull request #20 from ashnazg/strict
add strict typing
2 parents 00f872a + 6fee272 commit 6ba94b6

File tree

4 files changed

+84
-148
lines changed

4 files changed

+84
-148
lines changed

src/phpDocumentor/GraphViz/Attribute.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* phpDocumentor
46
*
@@ -34,7 +36,7 @@ class Attribute
3436
* @param string $key Id for the new attribute.
3537
* @param string $value Value for this attribute,
3638
*/
37-
public function __construct($key, $value)
39+
public function __construct(string $key, string $value)
3840
{
3941
$this->key = $key;
4042
$this->value = $value;
@@ -44,21 +46,17 @@ public function __construct($key, $value)
4446
* Sets the key for this attribute.
4547
*
4648
* @param string $key The new name of this attribute.
47-
*
48-
* @return \phpDocumentor\GraphViz\Attribute
4949
*/
50-
public function setKey($key)
50+
public function setKey(string $key): self
5151
{
5252
$this->key = $key;
5353
return $this;
5454
}
5555

5656
/**
5757
* Returns the name for this attribute.
58-
*
59-
* @return string
6058
*/
61-
public function getKey()
59+
public function getKey(): string
6260
{
6361
return $this->key;
6462
}
@@ -67,31 +65,25 @@ public function getKey()
6765
* Sets the value for this attribute.
6866
*
6967
* @param string $value The new value.
70-
*
71-
* @return \phpDocumentor\GraphViz\Attribute
7268
*/
73-
public function setValue($value)
69+
public function setValue(string $value): self
7470
{
7571
$this->value = $value;
7672
return $this;
7773
}
7874

7975
/**
8076
* Returns the value for this attribute.
81-
*
82-
* @return string
8377
*/
84-
public function getValue()
78+
public function getValue(): string
8579
{
8680
return $this->value;
8781
}
8882

8983
/**
9084
* Returns the attribute definition as is requested by GraphViz.
91-
*
92-
* @return string
9385
*/
94-
public function __toString()
86+
public function __toString(): string
9587
{
9688
$key = $this->getKey();
9789
if ($key === 'url') {
@@ -110,10 +102,8 @@ public function __toString()
110102

111103
/**
112104
* Returns whether the value contains HTML.
113-
*
114-
* @return bool
115105
*/
116-
public function isValueInHtml()
106+
public function isValueInHtml(): bool
117107
{
118108
$value = $this->getValue();
119109

@@ -122,10 +112,8 @@ public function isValueInHtml()
122112

123113
/**
124114
* Checks whether the value contains any any special characters needing escaping.
125-
*
126-
* @return bool
127115
*/
128-
public function isValueContainingSpecials()
116+
public function isValueContainingSpecials(): bool
129117
{
130118
return strstr($this->getValue(), '\\') !== false;
131119
}
@@ -134,9 +122,8 @@ public function isValueContainingSpecials()
134122
* Encode special characters so the escape sequences aren't removed
135123
*
136124
* @see http://www.graphviz.org/doc/info/attrs.html#k:escString
137-
* @return string
138125
*/
139-
protected function encodeSpecials()
126+
protected function encodeSpecials(): string
140127
{
141128
$value = $this->getValue();
142129
$regex = '(\'|"|\\x00|\\\\(?![\\\\NGETHLnlr]))';

src/phpDocumentor/GraphViz/Edge.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* phpDocumentor
46
*
@@ -22,20 +24,20 @@
2224
*/
2325
class Edge
2426
{
25-
/** @var \phpDocumentor\GraphViz\Node Node from where to link */
27+
/** @var Node Node from where to link */
2628
protected $from = null;
2729

28-
/** @var \phpDocumentor\GraphViz\Node Node where to to link */
30+
/** @var Node Node where to to link */
2931
protected $to = null;
3032

31-
/** @var \phpDocumentor\GraphViz\Attribute[] List of attributes for this edge */
33+
/** @var Attribute[] List of attributes for this edge */
3234
protected $attributes = [];
3335

3436
/**
3537
* Creates a new Edge / Link between the given nodes.
3638
*
37-
* @param \phpDocumentor\GraphViz\Node $from Starting node to create an Edge from.
38-
* @param \phpDocumentor\GraphViz\Node $to Destination node where to create and
39+
* @param Node $from Starting node to create an Edge from.
40+
* @param Node $to Destination node where to create and
3941
* edge to.
4042
*/
4143
public function __construct(Node $from, Node $to)
@@ -49,33 +51,27 @@ public function __construct(Node $from, Node $to)
4951
*
5052
* See the examples for more details.
5153
*
52-
* @param \phpDocumentor\GraphViz\Node $from Starting node to create an Edge from.
53-
* @param \phpDocumentor\GraphViz\Node $to Destination node where to create and
54-
* edge to.
55-
*
56-
* @return \phpDocumentor\GraphViz\Edge
54+
* @param Node $from Starting node to create an Edge from.
55+
* @param Node $to Destination node where to create and
56+
* edge to.
5757
*/
58-
public static function create(Node $from, Node $to)
58+
public static function create(Node $from, Node $to): self
5959
{
6060
return new self($from, $to);
6161
}
6262

6363
/**
6464
* Returns the source Node for this Edge.
65-
*
66-
* @return \phpDocumentor\GraphViz\Node
6765
*/
68-
public function getFrom()
66+
public function getFrom(): Node
6967
{
7068
return $this->from;
7169
}
7270

7371
/**
7472
* Returns the destination Node for this Edge.
75-
*
76-
* @return \phpDocumentor\GraphViz\Node
7773
*/
78-
public function getTo()
74+
public function getTo(): Node
7975
{
8076
return $this->to;
8177
}
@@ -94,13 +90,13 @@ public function getTo()
9490
* setX or getX.
9591
* @param mixed[] $arguments Arguments for the setter, only 1 is expected: value
9692
*
97-
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Edge|null
93+
* @return Attribute|Edge|null
9894
*/
99-
public function __call($name, $arguments)
95+
public function __call(string $name, array $arguments)
10096
{
10197
$key = strtolower(substr($name, 3));
10298
if (strtolower(substr($name, 0, 3)) === 'set') {
103-
$this->attributes[$key] = new Attribute($key, $arguments[0]);
99+
$this->attributes[$key] = new Attribute($key, (string) $arguments[0]);
104100

105101
return $this;
106102
}
@@ -114,10 +110,8 @@ public function __call($name, $arguments)
114110

115111
/**
116112
* Returns the edge definition as is requested by GraphViz.
117-
*
118-
* @return string
119113
*/
120-
public function __toString()
114+
public function __toString(): string
121115
{
122116
$attributes = [];
123117
foreach ($this->attributes as $value) {

0 commit comments

Comments
 (0)