Conditions | 12 |
Paths | 63 |
Total Lines | 63 |
Code Lines | 43 |
Lines | 12 |
Ratio | 19.05 % |
Changes | 1 | ||
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 |
||
145 | public function buildWorkflowManagerConfig(ConfigurationOptions $config, ServiceLocatorInterface $serviceLocator) |
||
146 | { |
||
147 | $resolverServiceName = $config->getResolver(); |
||
148 | $resolver = null; |
||
149 | if ($resolverServiceName) { |
||
150 | View Code Duplication | if ($serviceLocator->has($resolverServiceName)) { |
|
151 | $resolver = $serviceLocator->get($resolverServiceName); |
||
152 | } elseif (class_exists($resolverServiceName)) { |
||
153 | $r = new \ReflectionClass($resolverServiceName); |
||
154 | $resolver = $r->newInstance(); |
||
155 | } |
||
156 | |||
157 | if (!$resolver instanceof VariableResolverInterface) { |
||
158 | $errMsg = sprintf('Resolver not implements %s', VariableResolverInterface::class); |
||
159 | throw new Exception\InvalidVariableResolverException($errMsg); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | $factory = null; |
||
164 | if ($config->hasFactoryOptions()) { |
||
165 | $factoryServiceName = $config->getFactoryOptions()->getName(); |
||
166 | View Code Duplication | if ($serviceLocator->has($factoryServiceName)) { |
|
167 | $factory = $serviceLocator->get($factoryServiceName); |
||
168 | } elseif (class_exists($resolverServiceName)) { |
||
169 | $r = new \ReflectionClass($factoryServiceName); |
||
170 | $factory = $r->newInstance(); |
||
171 | } |
||
172 | |||
173 | if (!$factory instanceof WorkflowFactoryInterface) { |
||
174 | $errMsg = sprintf('Factory not implements %s', WorkflowFactoryInterface::class); |
||
175 | throw new Exception\InvalidWorkflowFactoryException($errMsg); |
||
176 | } |
||
177 | $factoryOptions = $config->getFactoryOptions()->getOptions(); |
||
178 | $properties = new Properties(); |
||
179 | foreach ($factoryOptions as $key => $value) { |
||
180 | $properties->setProperty($key, $value); |
||
181 | } |
||
182 | $factory->init($properties); |
||
183 | } |
||
184 | |||
185 | $options = [ |
||
186 | ArrayConfiguration::PERSISTENCE => $config->getPersistenceOptions()->getName(), |
||
187 | ArrayConfiguration::PERSISTENCE_ARGS => $config->getPersistenceOptions()->getOptions(), |
||
188 | ArrayConfiguration::VARIABLE_RESOLVER => $resolver, |
||
189 | ArrayConfiguration::WORKFLOW_FACTORY => $factory |
||
190 | |||
191 | ]; |
||
192 | |||
193 | $configServiceName = $this->getWorkflowConfigurationName(); |
||
194 | if (!class_exists($configServiceName)) { |
||
195 | $errMsg = sprintf('Class %s not found', $configServiceName); |
||
196 | throw new Exception\RuntimeException($errMsg); |
||
197 | } |
||
198 | $r = new \ReflectionClass($configServiceName); |
||
199 | $workflowManagerConfig = $r->newInstance($options); |
||
200 | |||
201 | if (!$workflowManagerConfig instanceof ConfigurationInterface) { |
||
202 | $errMsg = sprintf('Class not implement %s', ConfigurationInterface::class); |
||
203 | throw new Exception\RuntimeException($errMsg); |
||
204 | } |
||
205 | |||
206 | return $workflowManagerConfig; |
||
207 | } |
||
208 | |||
229 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.