Skip to content

Commit 323b731

Browse files
committed
add strict typing, return types, and more typehints;
1 parent 6fa0469 commit 323b731

31 files changed

+262
-192
lines changed

src/phpDocumentor/Reflection/Exception.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* This file is part of phpDocumentor.
46
*

src/phpDocumentor/Reflection/File/LocalFile.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* This file is part of phpDocumentor.
46
*
@@ -29,7 +31,7 @@ final class LocalFile implements File
2931
* LocalFile constructor.
3032
* @param string $path
3133
*/
32-
public function __construct($path)
34+
public function __construct(string $path)
3335
{
3436
$this->path = $path;
3537
}
@@ -39,7 +41,7 @@ public function __construct($path)
3941
*
4042
* @return string
4143
*/
42-
public function getContents()
44+
public function getContents(): string
4345
{
4446
return file_get_contents($this->path);
4547
}
@@ -49,7 +51,7 @@ public function getContents()
4951
*
5052
* @return string
5153
*/
52-
public function md5()
54+
public function md5(): string
5355
{
5456
return md5_file($this->path);
5557
}
@@ -59,7 +61,7 @@ public function md5()
5961
*
6062
* @return string
6163
*/
62-
public function path()
64+
public function path(): string
6365
{
6466
return $this->path;
6567
}

src/phpDocumentor/Reflection/Middleware/ChainFactory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
3-
* phpDocumentor
5+
* This file is part of phpDocumentor.
46
*
5-
* PHP Version 5.5
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
69
*
710
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
811
* @license http://www.opensource.org/licenses/mit-license.php MIT
@@ -21,7 +24,7 @@ final class ChainFactory
2124
* @param callable $lastCallable
2225
* @return callable
2326
*/
24-
public static function createExecutionChain($middlewareList, callable $lastCallable)
27+
public static function createExecutionChain(array $middlewareList, callable $lastCallable): callable
2528
{
2629
while ($middleware = array_pop($middlewareList)) {
2730
if (!$middleware instanceof Middleware) {

src/phpDocumentor/Reflection/Middleware/Middleware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* This file is part of phpDocumentor.
46
*

src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* This file is part of phpDocumentor.
46
*
@@ -15,7 +17,6 @@
1517
use phpDocumentor\Reflection\Fqsen;
1618
use PhpParser\Node;
1719
use PhpParser\Node\Const_;
18-
use PhpParser\Node\Name;
1920
use PhpParser\Node\Stmt\Class_;
2021
use PhpParser\Node\Stmt\ClassConst;
2122
use PhpParser\Node\Stmt\ClassMethod;
@@ -26,26 +27,27 @@
2627
use PhpParser\Node\Stmt\Trait_;
2728
use PhpParser\NodeTraverser;
2829
use PhpParser\NodeVisitorAbstract;
30+
use SplDoublyLinkedList;
2931

3032
final class ElementNameResolver extends NodeVisitorAbstract
3133
{
3234
/**
33-
* @var \SplDoublyLinkedList
35+
* @var SplDoublyLinkedList
3436
*/
3537
private $parts = null;
3638

3739
/**
3840
* Resets the object to a known state before start processing.
3941
*/
40-
public function beforeTraverse(array $nodes)
42+
public function beforeTraverse(array $nodes): void
4143
{
4244
$this->resetState('\\');
4345
}
4446

4547
/**
4648
* Performs a reset of the added element when needed.
4749
*/
48-
public function leaveNode(Node $node)
50+
public function leaveNode(Node $node): void
4951
{
5052
switch (get_class($node)) {
5153
case Namespace_::class:
@@ -65,7 +67,7 @@ public function leaveNode(Node $node)
6567
/**
6668
* Adds fqsen property to a node when applicable.
6769
*/
68-
public function enterNode(Node $node)
70+
public function enterNode(Node $node): ?int
6971
{
7072
switch (get_class($node)) {
7173
case Namespace_::class:
@@ -103,16 +105,17 @@ public function enterNode(Node $node)
103105
$node->fqsen = new Fqsen($this->buildName());
104106
break;
105107
}
108+
return null;
106109
}
107110

108111
/**
109112
* Resets the state of the object to an empty state.
110113
*
111114
* @param string $namespace
112115
*/
113-
private function resetState($namespace = null)
116+
private function resetState(string $namespace = null): void
114117
{
115-
$this->parts = new \SplDoublyLinkedList();
118+
$this->parts = new SplDoublyLinkedList();
116119
$this->parts->push($namespace);
117120
}
118121

@@ -121,7 +124,7 @@ private function resetState($namespace = null)
121124
*
122125
* @return null|string
123126
*/
124-
private function buildName()
127+
private function buildName(): ?string
125128
{
126129
$name = null;
127130
foreach ($this->parts as $part) {

src/phpDocumentor/Reflection/Php/Argument.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* This file is part of phpDocumentor.
46
*
@@ -42,7 +44,7 @@ final class Argument
4244
* @param bool $byReference
4345
* @param bool $isVariadic
4446
*/
45-
public function __construct($name, $default = null, $byReference = false, $isVariadic = false)
47+
public function __construct(string $name, string $default = null, bool $byReference = false, bool $isVariadic = false)
4648
{
4749
$this->name = $name;
4850
$this->default = $default;
@@ -55,40 +57,40 @@ public function __construct($name, $default = null, $byReference = false, $isVar
5557
*
5658
* @return string
5759
*/
58-
public function getName()
60+
public function getName(): string
5961
{
6062
return $this->name;
6163
}
6264

6365
/**
6466
* {@inheritDoc}
6567
*/
66-
public function getTypes()
68+
public function getTypes(): array
6769
{
6870
return $this->types;
6971
}
7072

7173
/**
7274
* Add a type.
73-
* @param string $type
75+
* @param mixed $type
7476
*/
75-
public function addType($type)
77+
public function addType($type): void
7678
{
7779
$this->types[] = $type;
7880
}
7981

8082
/**
8183
* {@inheritDoc}
8284
*/
83-
public function getDefault()
85+
public function getDefault(): ?string
8486
{
8587
return $this->default;
8688
}
8789

8890
/**
8991
* {@inheritDoc}
9092
*/
91-
public function isByReference()
93+
public function isByReference(): bool
9294
{
9395
return $this->byReference;
9496
}
@@ -98,7 +100,7 @@ public function isByReference()
98100
*
99101
* @return boolean
100102
*/
101-
public function isVariadic()
103+
public function isVariadic(): bool
102104
{
103105
return $this->isVariadic;
104106
}

0 commit comments

Comments
 (0)