Conditions | 11 |
Paths | 9 |
Total Lines | 42 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
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 |
||
39 | public function __invoke(ContainerInterface $container, string $requestedName, array $options = null) |
||
40 | { |
||
41 | $options = $options ?? $this->getServiceOptions($container, $requestedName, 'hydrators'); |
||
42 | |||
43 | $entityManager = $options['entity_manager'] ?? null; |
||
44 | if (null === $entityManager) { |
||
45 | throw new ServiceNotCreatedException( |
||
46 | sprintf( |
||
47 | 'The required \'entity_manager\' configuration option is missing for service \'%s\'', |
||
48 | $requestedName |
||
49 | ) |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | $inflector = isset($options['inflector']) |
||
54 | ? $this->getService($container, $options['inflector'], $requestedName) |
||
55 | : null; |
||
56 | |||
57 | $hydrator = new EntityHydrator( |
||
58 | $this->getEntityManager($container, $entityManager, $requestedName), |
||
59 | !isset($options['by_value']) || $options['by_value'], |
||
60 | $inflector |
||
61 | ); |
||
62 | |||
63 | $namingStrategy = $options['naming_strategy'] ?? null; |
||
64 | if (!empty($namingStrategy) && $hydrator instanceof NamingStrategyEnabledInterface) { |
||
65 | $hydrator->setNamingStrategy($this->getService($container, $namingStrategy, $requestedName)); |
||
66 | } |
||
67 | |||
68 | $strategies = $options['strategies'] ?? []; |
||
69 | if (!empty($strategies) && $hydrator instanceof StrategyEnabledInterface) { |
||
70 | foreach ($strategies as $name => $strategy) { |
||
71 | if (is_string($strategy)) { |
||
72 | $strategy = $this->getService($container, $strategy, $requestedName); |
||
73 | } |
||
74 | if ($strategy instanceof StrategyInterface) { |
||
75 | $hydrator->addStrategy($name, $strategy); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | return $hydrator; |
||
81 | } |
||
83 |