1 | <?php |
||
8 | class Runner |
||
9 | { |
||
10 | /** |
||
11 | * The behavior to use for ACF function calls. |
||
12 | * |
||
13 | * @var \Samrap\Acf\Behaviors\BehaviorInterface |
||
14 | */ |
||
15 | protected $behavior; |
||
16 | |||
17 | /** |
||
18 | * The \Samrap\Acf\Fluent\Builder components to run. |
||
19 | * |
||
20 | * The components will be executed in the order defined in this array. Only |
||
21 | * the components defined on the \Samrap\Acf\Fluent\Builder will be run. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $components = [ |
||
26 | 'expect', |
||
27 | 'matches', |
||
28 | 'default', |
||
29 | 'shortcodes', |
||
30 | 'escape', |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Create a new Runner instance. |
||
35 | * |
||
36 | * @param \Samrap\Acf\Behaviors\BehaviorInterface $behavior |
||
37 | */ |
||
38 | public function __construct(BehaviorInterface $behavior) |
||
42 | |||
43 | /** |
||
44 | * Get the behavior instance. |
||
45 | * |
||
46 | * @return \Samrap\Acf\Behaviors\BehaviorInterface |
||
47 | */ |
||
48 | public function getBehavior() |
||
52 | |||
53 | /** |
||
54 | * Set the behavior. |
||
55 | * |
||
56 | * @param \Samrap\Acf\Behaviors\BehaviorInterface $behavior |
||
57 | * @return void |
||
58 | */ |
||
59 | public function setBehavior(BehaviorInterface $behavior) |
||
63 | |||
64 | /** |
||
65 | * Run the ACF 'get' behavior from the given builder. |
||
66 | * |
||
67 | * @param \Samrap\Acf\Fluent\Builder $builder |
||
68 | * @return mixed |
||
69 | */ |
||
70 | public function get(Builder $builder) |
||
91 | |||
92 | /** |
||
93 | * Run the ACF 'update' behavior from the given builder. |
||
94 | * |
||
95 | * @param \Samrap\Acf\Fluent\Builder $builder |
||
96 | * @param mixed $value |
||
97 | * @return void |
||
98 | */ |
||
99 | public function update(Builder $builder, $value) |
||
103 | |||
104 | /** |
||
105 | * Ensure that the value is of the expected type. |
||
106 | * |
||
107 | * @param string $expected |
||
108 | * @param mixed $value |
||
109 | * @return mixed |
||
110 | */ |
||
111 | protected function runExpect($expected, $value) |
||
115 | |||
116 | /** |
||
117 | * Check that the value matches the given pattern. |
||
118 | * |
||
119 | * @param string $pattern |
||
120 | * @param string $value |
||
121 | * @return mixed |
||
122 | */ |
||
123 | protected function runMatches($pattern, $value) |
||
127 | |||
128 | /** |
||
129 | * Return the default value if the given value is empty or null. |
||
130 | * |
||
131 | * @param mixed $default |
||
132 | * @param mixed $value |
||
133 | * @return mixed |
||
134 | */ |
||
135 | protected function runDefault($default, $value) |
||
145 | |||
146 | /** |
||
147 | * Escape the value with the given function. |
||
148 | * |
||
149 | * @param callable $func |
||
150 | * @param string $value |
||
151 | * @return string |
||
152 | */ |
||
153 | protected function runEscape($func, $value) |
||
173 | |||
174 | /** |
||
175 | * Do shortcodes on the given value. |
||
176 | * |
||
177 | * @param bool $_ |
||
178 | * @param mixed $value |
||
179 | * @return mixed |
||
180 | */ |
||
181 | protected function runShortcodes($_, $value) |
||
191 | } |
||
192 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.