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
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Represetns a data type which must be an instance of an object |
21
|
|
|
* |
22
|
|
|
* @property-read string $classname |
23
|
|
|
*/ |
24
|
|
|
class ObjectType extends AbstractType |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The name of the class this must be an instance of |
28
|
|
|
* |
29
|
|
|
* @readable |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $classname; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Generic types for this object |
36
|
|
|
* |
37
|
|
|
* @readable |
38
|
|
|
* @var ArrayList |
39
|
|
|
*/ |
40
|
|
|
protected $generics; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Creates this ObjectType with the given classname |
44
|
|
|
* |
45
|
|
|
* @param string $class The name of the class this must be an |
|
|
|
|
46
|
|
|
* instance of |
47
|
|
|
*/ |
48
|
27 |
|
public function __construct(string $classname) |
49
|
|
|
{ |
50
|
27 |
|
$this->classname = $classname; |
51
|
27 |
|
$this->generics = new ArrayList(); |
52
|
27 |
|
} |
53
|
|
|
|
54
|
|
|
public function compare($type) : int |
55
|
|
|
{ |
56
|
|
|
if |
57
|
|
|
( |
58
|
|
|
$type instanceof ObjectType && |
59
|
|
|
$type->classname === $this->classname && |
60
|
|
|
$type->generics->size() <= $this->generics->size() |
61
|
|
|
) |
62
|
|
|
{ |
63
|
|
|
foreach ($type->generics as $i => $generic) |
64
|
|
|
{ |
65
|
|
|
if (!$this->generics[$i]->compatible($generic)) |
66
|
|
|
{ |
67
|
|
|
return -1; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->generics->size() - $type->generics->size(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return -1; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function equals($object) : bool |
78
|
|
|
{ |
79
|
|
|
return $this->compare($type) === 0; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.