1 | <?php |
||
15 | class SimpleHtmlDomNode extends \ArrayObject implements SimpleHtmlDomNodeInterface |
||
16 | { |
||
17 | /** @noinspection MagicMethodsValidityInspection */ |
||
18 | /** |
||
19 | * @param string $name |
||
20 | * |
||
21 | * @return array|null |
||
22 | */ |
||
23 | 3 | public function __get($name) |
|
24 | { |
||
25 | 3 | $name = strtolower($name); |
|
26 | |||
27 | 3 | if ($this->count() > 0) { |
|
28 | 3 | $return = array(); |
|
29 | |||
30 | 3 | foreach ($this as $node) { |
|
31 | 3 | if ($node instanceof SimpleHtmlDom) { |
|
32 | 3 | $return[] = $node->{$name}; |
|
33 | } |
||
34 | } |
||
35 | |||
36 | 3 | return $return; |
|
37 | } |
||
38 | |||
39 | return null; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * alias for "$this->innerHtml()" (added for compatibly-reasons with v1.x) |
||
44 | */ |
||
45 | public function outertext() |
||
46 | { |
||
47 | $this->innerHtml(); |
||
|
|||
48 | } |
||
49 | |||
50 | /** |
||
51 | * alias for "$this->innerHtml()" (added for compatibly-reasons with v1.x) |
||
52 | */ |
||
53 | public function innertext() |
||
54 | { |
||
55 | $this->innerHtml(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string $selector |
||
60 | * @param int $idx |
||
61 | * |
||
62 | * @return SimpleHtmlDomNode[]|SimpleHtmlDomNode|null |
||
63 | */ |
||
64 | public function __invoke($selector, $idx = null) |
||
65 | { |
||
66 | return $this->find($selector, $idx); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | 1 | public function __toString() |
|
81 | |||
82 | /** |
||
83 | * Find list of nodes with a CSS selector. |
||
84 | * |
||
85 | * @param string $selector |
||
86 | * @param int $idx |
||
87 | * |
||
88 | * @return SimpleHtmlDomNode[]|SimpleHtmlDomNode|null |
||
89 | */ |
||
90 | 11 | public function find(string $selector, $idx = null) |
|
91 | { |
||
92 | 11 | $elements = new self(); |
|
93 | 11 | foreach ($this as $node) { |
|
94 | 11 | foreach ($node->find($selector) as $res) { |
|
95 | 11 | $elements->append($res); |
|
96 | } |
||
97 | } |
||
98 | |||
99 | // return all elements |
||
100 | 11 | if (null === $idx) { |
|
101 | 11 | return $elements; |
|
102 | } |
||
103 | |||
104 | // handle negative values |
||
105 | if ($idx < 0) { |
||
106 | $idx = \count($elements) + $idx; |
||
107 | } |
||
108 | |||
109 | // return one element |
||
110 | if (isset($elements[$idx])) { |
||
111 | return $elements[$idx]; |
||
112 | } |
||
113 | |||
114 | return null; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Get html of elements. |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | 1 | public function innerHtml(): array |
|
131 | |||
132 | /** |
||
133 | * Get plain text. |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 1 | public function text(): array |
|
146 | } |
||
147 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: