Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
8 | class Detector |
||
9 | { |
||
10 | const STATE_UNCHECKED = 'unckecked'; |
||
11 | const STATE_PASSED = 'checkPassed'; |
||
12 | const STATE_FAILED = 'checkFailed'; |
||
13 | |||
14 | private $state = self::STATE_UNCHECKED; |
||
15 | |||
16 | /** |
||
17 | * |
||
18 | * @var mixed key to identify unique user |
||
19 | */ |
||
20 | private $key; |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | * @var \Sokil\DataType\PriorityList |
||
25 | */ |
||
26 | private $processorDeclarationList; |
||
27 | |||
28 | private $processorList = array(); |
||
29 | |||
30 | private $processorNamespaces = array( |
||
31 | '\Sokil\FraudDetector\Processor', |
||
32 | ); |
||
33 | |||
34 | private $collectorNamespaces = array( |
||
35 | '\Sokil\FraudDetector\Processor\RequestRate\Collector', |
||
36 | ); |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
||
41 | */ |
||
42 | private $eventDispatcher; |
||
43 | |||
44 | public function __construct() |
||
49 | |||
50 | /** |
||
51 | * Key that uniquely identify user |
||
52 | * @param type $key |
||
53 | * @return \Sokil\FraudDetector\Detector |
||
54 | */ |
||
55 | public function setKey($key) |
||
60 | |||
61 | public function getKey() |
||
69 | |||
70 | /** |
||
71 | * Check if request is not fraud |
||
72 | */ |
||
73 | public function check() |
||
94 | |||
95 | public function registerProcessorNamespace($namespace) |
||
100 | |||
101 | /** |
||
102 | * Add processor identified by its name. |
||
103 | * If processor already added, it will be replaced by new instance. |
||
104 | * |
||
105 | * @param string $name name of processor |
||
106 | * @param callable $callable configurator callable |
||
107 | * @return \Sokil\FraudDetector\Detector |
||
108 | */ |
||
109 | public function declareProcessor($name, $callable = null, $priority = 0) |
||
114 | |||
115 | public function addProcssor($name, ProcessorInterface $processor, $priority = 0) |
||
122 | |||
123 | public function isProcessorDeclared($name) |
||
127 | |||
128 | /** |
||
129 | * Factory method to create new check condition |
||
130 | * |
||
131 | * @param string $name name of check condition |
||
132 | * @return \Sokil\FraudDetector\ProcessorInterface |
||
133 | * @throws \Exception |
||
134 | */ |
||
135 | private function getProcessorClassName($name) |
||
148 | |||
149 | public function getProcessor($processorName) |
||
173 | |||
174 | public function registerCollectorNamespace($namespace) |
||
179 | |||
180 | public function getCollectorClassName($type) |
||
199 | |||
200 | private function on($stateName, $callable) |
||
210 | |||
211 | public function onCheckPassed($callable) |
||
217 | |||
218 | public function onCheckFailed($callable) |
||
224 | |||
225 | public function isUnchecked() |
||
229 | |||
230 | public function isPassed() |
||
234 | |||
235 | public function isFailed() |
||
239 | |||
240 | private function hasState($state) |
||
244 | |||
245 | public function subscribe($eventName, $callable, $priority = 0) |
||
250 | |||
251 | /** |
||
252 | * |
||
253 | * @param string $eventName |
||
254 | * @param mixed $target |
||
255 | * @return \Sokil\FraudDetector\Event |
||
256 | */ |
||
257 | public function trigger($eventName, $target = null) |
||
267 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: