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 |
||
25 | class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var EventDispatcherInterface |
||
29 | */ |
||
30 | protected $dispatcher; |
||
31 | |||
32 | /** |
||
33 | * Optional parameters. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $options = [ |
||
38 | 'identifier' => 'id', |
||
39 | 'index' => '', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * PropertyAccessor instance. |
||
44 | * |
||
45 | * @var PropertyAccessorInterface |
||
46 | */ |
||
47 | protected $propertyAccessor; |
||
48 | |||
49 | /** |
||
50 | * Instanciates a new Mapper. |
||
51 | * |
||
52 | * @param array $options |
||
53 | * @param EventDispatcherInterface $dispatcher |
||
54 | */ |
||
55 | 45 | View Code Duplication | public function __construct(array $options = [], EventDispatcherInterface $dispatcher = null) |
56 | { |
||
57 | 45 | $this->options = array_merge($this->options, $options); |
|
58 | 45 | $this->dispatcher = $dispatcher; |
|
59 | |||
60 | 45 | if (class_exists(LegacyEventDispatcherProxy::class)) { |
|
61 | $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); |
||
62 | } |
||
63 | 45 | } |
|
64 | |||
65 | /** |
||
66 | * Set the PropertyAccessor. |
||
67 | * |
||
68 | * @param PropertyAccessorInterface $propertyAccessor |
||
69 | */ |
||
70 | 45 | public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor) |
|
74 | |||
75 | /** |
||
76 | * Transforms an object into an elastica object having the required keys. |
||
77 | * |
||
78 | * @param object $object the object to convert |
||
79 | * @param array $fields the keys we want to have in the returned array |
||
80 | * |
||
81 | * @return Document |
||
82 | **/ |
||
83 | 30 | public function transform($object, array $fields) |
|
92 | |||
93 | /** |
||
94 | * transform a nested document or an object property into an array of ElasticaDocument. |
||
95 | * |
||
96 | * @param array|\Traversable|\ArrayAccess $objects the object to convert |
||
97 | * @param array $fields the keys we want to have in the returned array |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 6 | protected function transformNested($objects, array $fields) |
|
119 | |||
120 | /** |
||
121 | * Attempts to convert any type to a string or an array of strings. |
||
122 | * |
||
123 | * @param mixed $value |
||
124 | * |
||
125 | * @return string|array |
||
126 | */ |
||
127 | protected function normalizeValue($value) |
||
146 | |||
147 | /** |
||
148 | * Transforms the given object to an elastica document. |
||
149 | * |
||
150 | * @param object $object the object to convert |
||
151 | * @param array $fields the keys we want to have in the returned array |
||
152 | * @param string $identifier the identifier for the new document |
||
153 | * |
||
154 | * @return Document |
||
155 | */ |
||
156 | 30 | protected function transformObjectToDocument($object, array $fields, $identifier = '') |
|
219 | } |
||
220 |
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: