1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Reflection; |
11
|
|
|
|
12
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
13
|
|
|
use Railt\Reflection\Contracts\Dictionary; |
14
|
|
|
use Railt\Reflection\Contracts\Document as DocumentInterface; |
15
|
|
|
use Railt\Reflection\Contracts\Reflection as ReflectionInterface; |
16
|
|
|
use Railt\Reflection\Dictionary\ProxyDictionary; |
17
|
|
|
use Railt\Reflection\Dictionary\SimpleDictionary; |
18
|
|
|
use Railt\Reflection\Exception\ReflectionException; |
19
|
|
|
use Railt\Reflection\Stack\ProvidesCallStack; |
20
|
|
|
use Railt\Reflection\Stdlib\GraphQLDocument; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Reflection |
24
|
|
|
*/ |
25
|
|
|
class Reflection extends ProxyDictionary implements ReflectionInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array|DocumentInterface[] |
29
|
|
|
*/ |
30
|
|
|
protected $documents = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Reflection constructor. |
34
|
|
|
* @param Dictionary|null $parent |
35
|
|
|
* @throws ReflectionException |
36
|
|
|
*/ |
37
|
9 |
|
public function __construct(Dictionary $parent = null) |
38
|
|
|
{ |
39
|
9 |
|
parent::__construct($parent ?? new SimpleDictionary()); |
40
|
|
|
|
41
|
9 |
|
$this->wrap(function () { |
42
|
9 |
|
$this->boot(); |
43
|
9 |
|
}); |
44
|
9 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param \Closure $then |
48
|
|
|
* @return mixed |
49
|
|
|
* @throws ReflectionException |
50
|
|
|
*/ |
51
|
9 |
|
private function wrap(\Closure $then) |
52
|
|
|
{ |
53
|
|
|
try { |
54
|
9 |
|
return $then(); |
55
|
|
|
} catch (ReflectionException $e) { |
56
|
|
|
$parent = $this->getParentDictionary(); |
57
|
|
|
|
58
|
|
|
if ($parent instanceof ProvidesCallStack) { |
|
|
|
|
59
|
|
|
$e = $e->withCallStack($parent->getCallStack()); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
throw $e; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return void |
68
|
|
|
* @throws Exception\TypeConflictException |
69
|
|
|
*/ |
70
|
9 |
|
private function boot(): void |
71
|
|
|
{ |
72
|
9 |
|
$this->addDocument(new GraphQLDocument($this)); |
73
|
9 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param DocumentInterface $document |
77
|
|
|
*/ |
78
|
17 |
|
public function addDocument(DocumentInterface $document): void |
79
|
|
|
{ |
80
|
17 |
|
$this->documents[$document->getName()] = $document; |
81
|
17 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return iterable |
85
|
|
|
*/ |
86
|
4 |
|
public function getDocuments(): iterable |
87
|
|
|
{ |
88
|
4 |
|
return \array_values($this->documents); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param TypeDefinition $type |
93
|
|
|
* @return Dictionary |
94
|
|
|
*/ |
95
|
17 |
|
public function add(TypeDefinition $type): Dictionary |
96
|
|
|
{ |
97
|
17 |
|
$this->addDocument($type->getDocument()); |
98
|
|
|
|
99
|
17 |
|
return parent::add($type); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.