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