1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Composite Utils package. |
4
|
|
|
* |
5
|
|
|
* (c) Emily Shepherd <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the |
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @package spaark/composite-utils |
11
|
|
|
* @author Emily Shepherd <[email protected]> |
12
|
|
|
* @license MIT |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Spaark\CompositeUtils\Model\Reflection\Type; |
16
|
|
|
|
17
|
|
|
use Spaark\CompositeUtils\Model\Collection\ArrayList; |
18
|
|
|
use Spaark\CompositeUtils\Model\ClassName; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Represents a data type which must be an instance of an object |
22
|
|
|
* |
23
|
|
|
* @property-read string $classname |
24
|
|
|
*/ |
25
|
|
|
class ObjectType extends AbstractType |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* The name of the class this must be an instance of |
29
|
|
|
* |
30
|
|
|
* @readable |
31
|
|
|
* @var ClassName |
32
|
|
|
*/ |
33
|
|
|
protected $classname; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Generic types for this object |
37
|
|
|
* |
38
|
|
|
* @readable |
39
|
|
|
* @var ArrayList |
40
|
|
|
*/ |
41
|
|
|
protected $generics; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates this ObjectType with the given classname |
45
|
|
|
* |
46
|
|
|
* @param mixed $class The name of the class this must be an |
|
|
|
|
47
|
|
|
* instance of |
48
|
|
|
*/ |
49
|
39 |
|
public function __construct($classname) |
50
|
|
|
{ |
51
|
39 |
|
$this->generics = new ArrayList(); |
52
|
39 |
|
$this->classname = $classname instanceof ClassName |
53
|
|
|
? $classname |
54
|
39 |
|
: new ClassName($classname); |
55
|
39 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
2 |
|
public function equals($type) : bool |
61
|
|
|
{ |
62
|
|
|
if |
63
|
|
|
( |
64
|
2 |
|
$type instanceof ObjectType && |
65
|
2 |
|
$type->classname->equals($this->classname) && |
|
|
|
|
66
|
2 |
|
$type->generics->size() === $this->generics->size() |
67
|
|
|
) |
68
|
|
|
{ |
69
|
2 |
|
foreach ($type->generics as $i => $generic) |
70
|
|
|
{ |
71
|
2 |
|
if (!$this->generics[$i]->equals($generic)) |
72
|
|
|
{ |
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns a string representation of the object |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
2 |
|
public function __toString() : string |
89
|
|
|
{ |
90
|
2 |
|
$return = (string)$this->classname; |
91
|
|
|
|
92
|
2 |
|
if ($this->generics->count()) |
93
|
|
|
{ |
94
|
|
|
$return .= |
95
|
1 |
|
'<' . implode(',', $this->generics->toArray()) . '>'; |
96
|
|
|
} |
97
|
|
|
|
98
|
2 |
|
return $return; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.