Conditions | 13 |
Paths | 21 |
Total Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
98 | public function load(ConfigurationInterface $instance) |
||
99 | { |
||
100 | |||
101 | // we need the reflection properties of the configuration |
||
102 | $reflectionClass = new \ReflectionClass($instance); |
||
103 | $reflectionProperties = $reflectionClass->getProperties(); |
||
104 | |||
105 | // load the annoation reader |
||
106 | $reader = new AnnotationReader(); |
||
107 | |||
108 | // iterate over the properties to initialize the configuration |
||
109 | /** @var \ReflectionProperty $reflectionProperty */ |
||
110 | foreach ($reflectionProperties as $reflectionProperty) { |
||
111 | // try to load the annotations of the properties |
||
112 | /** @var \JMS\Serializer\Annotation\SerializedName $serializedName */ |
||
113 | $serializedName = $reader->getPropertyAnnotation($reflectionProperty, SerializedName::class); |
||
114 | /** @var \JMS\Serializer\Annotation\SerializedName $accessors */ |
||
115 | $accessor = $reader->getPropertyAnnotation($reflectionProperty, Accessor::class); |
||
116 | |||
117 | // intialize the option value (which equals the property name by default) |
||
118 | $name = $reflectionProperty->getName(); |
||
119 | |||
120 | // if we've an JMS serializer annotation, we use the configured name instead |
||
121 | if ($serializedName instanceof SerializedName) { |
||
122 | $name = $serializedName->name; |
||
123 | } |
||
124 | |||
125 | // query whether or not the name matches an input option and is NOT on the blacklist |
||
126 | if ($this->inputOptionKeys->isInputOption($name) && in_array($name, $this->blacklist) === false) { |
||
127 | // query whether or not the @Accessor annotion with a setter has been specified |
||
128 | if ($accessor instanceof Accessor && isset($accessor->getter) && isset($accessor->setter)) { |
||
129 | // initialize the value |
||
130 | $newValue = null; |
||
131 | |||
132 | // try to load the new value from the command line |
||
133 | if ($this->input->hasOption($name)) { |
||
134 | $newValue = $this->input->getOption($name); |
||
135 | } |
||
136 | |||
137 | // query whether or not we've a new value |
||
138 | if ($newValue === null) { |
||
139 | continue; |
||
140 | } |
||
141 | |||
142 | // this is the case where we may have a value from the configuration |
||
143 | // which may collate with the default value one from the command line |
||
144 | if (in_array($name, $this->overrideIfEmpty)) { |
||
145 | // first we try load the existing value from the configuration |
||
146 | $val = call_user_func(array($instance, $accessor->getter)); |
||
147 | // query whether or not the command line option has REALLY been specified otherwise it'll |
||
148 | // be the default value and in that case the one from the configuration has precedence |
||
149 | if ($val === null || $this->input->hasOptionSpecified($name)) { |
||
|
|||
150 | call_user_func(array($instance, $accessor->setter), $newValue); |
||
151 | } |
||
152 | } else { |
||
153 | call_user_func(array($instance, $accessor->setter), $newValue); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.