Conditions | 10 |
Paths | 65 |
Total Lines | 51 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
64 | public function __invoke(EntityInterface $entity, array $options) |
||
65 | { |
||
66 | if (is_string($this->_repository)) { |
||
67 | $alias = $this->_repository; |
||
68 | $this->_repository = $options['repository']->association($alias); |
||
69 | |||
70 | if (empty($this->_repository)) { |
||
71 | throw new RuntimeException(sprintf( |
||
72 | "ExistsIn rule for '%s' is invalid. The '%s' association is not defined.", |
||
73 | implode(', ', $this->_fields), |
||
74 | $alias |
||
75 | )); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | $source = $target = $this->_repository; |
||
80 | if (!empty($options['repository'])) { |
||
81 | $source = $options['repository']; |
||
82 | } |
||
83 | if ($source instanceof Association) { |
||
84 | $source = $source->source(); |
||
85 | } |
||
86 | if ($target instanceof Association) { |
||
87 | $bindingKey = (array)$target->bindingKey(); |
||
88 | $target = $target->target(); |
||
89 | } else { |
||
90 | $bindingKey = (array)$target->primaryKey(); |
||
91 | } |
||
92 | |||
93 | if (!empty($options['_sourceTable']) && $target === $options['_sourceTable']) { |
||
94 | return true; |
||
95 | } |
||
96 | |||
97 | if (!$entity->extract($this->_fields, true)) { |
||
98 | return true; |
||
99 | } |
||
100 | |||
101 | if ($this->_fieldsAreNull($entity, $source)) { |
||
102 | return true; |
||
103 | } |
||
104 | |||
105 | $primary = array_map( |
||
106 | [$target, 'aliasField'], |
||
107 | $bindingKey |
||
108 | ); |
||
109 | $conditions = array_combine( |
||
110 | $primary, |
||
111 | $entity->extract($this->_fields) |
||
112 | ); |
||
113 | return $target->exists($conditions); |
||
114 | } |
||
115 | |||
135 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..