1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\Types; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use phpDocumentor\Reflection\Type; |
19
|
|
|
use function strpos; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Value Object representing an object. |
23
|
|
|
* |
24
|
|
|
* An object can be either typed or untyped. When an object is typed it means that it has an identifier, the FQSEN, |
25
|
|
|
* pointing to an element in PHP. Object types that are untyped do not refer to a specific class but represent objects |
26
|
|
|
* in general. |
27
|
|
|
* |
28
|
|
|
* @psalm-immutable |
29
|
|
|
*/ |
30
|
|
|
final class Object_ implements Type |
31
|
|
|
{ |
32
|
|
|
/** @var Fqsen|null */ |
33
|
|
|
private $fqsen; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'. |
37
|
|
|
* |
38
|
|
|
* @throws InvalidArgumentException When provided $fqsen is not a valid type. |
39
|
|
|
*/ |
40
|
|
|
public function __construct(?Fqsen $fqsen = null) |
41
|
|
|
{ |
42
|
|
|
if (strpos((string) $fqsen, '::') !== false || strpos((string) $fqsen, '()') !== false) { |
43
|
|
|
throw new InvalidArgumentException( |
44
|
|
|
'Object types can only refer to a class, interface or trait but a method, function, constant or ' |
45
|
|
|
. 'property was received: ' . (string) $fqsen |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->fqsen = $fqsen; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the FQSEN associated with this object. |
54
|
|
|
*/ |
55
|
|
|
public function getFqsen() : ?Fqsen |
56
|
|
|
{ |
57
|
|
|
return $this->fqsen; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function __toString() : string |
61
|
|
|
{ |
62
|
|
|
if ($this->fqsen) { |
63
|
|
|
return (string) $this->fqsen; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return 'object'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|