1 | <?php |
||
18 | class Graph { |
||
19 | /** |
||
20 | * @var array<string, array<int, Node>> |
||
21 | */ |
||
22 | protected $nodes = []; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $id_counter = 0; |
||
28 | |||
29 | /** |
||
30 | * Create a new node in the graph. |
||
31 | * |
||
32 | * @param string $type |
||
33 | * @param array<string,mixed>|null $properties |
||
34 | * @return Node |
||
35 | */ |
||
36 | 80 | public function create_node($type, array $properties = null) { |
|
45 | |||
46 | 80 | protected function build_node($id, $type, array $properties = null) { |
|
49 | |||
50 | /** |
||
51 | * Add a relation to the graph. |
||
52 | * |
||
53 | * @param Node $left |
||
54 | * @param string $type |
||
55 | * @param array<string,mixed> $properties |
||
56 | * @param Node $right |
||
57 | * @return Relation |
||
58 | */ |
||
59 | 52 | public function add_relation(Node $left, $type, array $properties, Node $right) { |
|
62 | |||
63 | /** |
||
64 | * Get nodes from the graph, maybe filtered by a filter. |
||
65 | * |
||
66 | * @param Predicate|null $filter |
||
67 | * @return Iterator <Node> |
||
68 | */ |
||
69 | 64 | public function nodes(Predicate $filter = null) { |
|
77 | |||
78 | 9 | protected function all_nodes() { |
|
85 | |||
86 | 55 | protected function filtered_nodes(Predicate $filter) { |
|
98 | |||
99 | /** |
||
100 | * Get the node with the given id. |
||
101 | * |
||
102 | * @param int $id |
||
103 | * @throws \InvalidArgumentException if $id is unknown |
||
104 | * @return Node |
||
105 | */ |
||
106 | 2 | public function node($id) { |
|
115 | |||
116 | /** |
||
117 | * Build a query on the graph. |
||
118 | * |
||
119 | * @return Query |
||
120 | */ |
||
121 | 61 | public function query() { |
|
124 | } |
||
125 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.