| Conditions | 6 |
| Paths | 7 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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, $requestedName, array $options = null) |
||
| 40 | { |
||
| 41 | $options = $options ?? $this->getServiceOptions($container, $requestedName, 'entity_repositories'); |
||
| 42 | |||
| 43 | $className = $options['class_name'] ?? null; |
||
| 44 | $entityName = $options['entity_name'] ?? $requestedName; |
||
| 45 | |||
| 46 | if (! is_a($entityName, EntityInterface::class, true)) { |
||
| 47 | throw new ServiceNotCreatedException( |
||
| 48 | sprintf( |
||
| 49 | 'The \'entity_name\' configuration option must reference a class ' . |
||
| 50 | 'of type \'%s\' : \'%s\' provided for service \'%s\'', |
||
| 51 | EntityInterface::class, |
||
| 52 | $entityName, |
||
| 53 | $requestedName |
||
| 54 | ) |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | // Attempt to automatically find a value custom repository or otherwise fallback to the default. |
||
| 59 | if (null === $className) { |
||
| 60 | $customClassName = $this->generateCustomClassName($entityName); |
||
| 61 | $className = $this->defaultClassName; |
||
| 62 | |||
| 63 | if (null !== $customClassName && class_exists($customClassName)) { |
||
| 64 | $className = $customClassName; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (! is_a($className, EntityRepositoryInterface::class, true)) { |
||
| 69 | throw new ServiceNotCreatedException( |
||
| 70 | sprintf( |
||
| 71 | 'The \'class_name\' option must be of type \'%s\'; \'%s\' provided for entity repository \'%s\'', |
||
| 72 | EntityRepositoryInterface::class, |
||
| 73 | $className, |
||
| 74 | $requestedName |
||
| 75 | ) |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | |||
| 79 | $queryService = $container->build(QueryService::class, ['entity_name' => $entityName]); |
||
|
|
|||
| 80 | |||
| 81 | $listenerProvider = $options['listener_provider'] ?? ListenerProvider::class; |
||
| 82 | $persistService = $container->build( |
||
| 83 | PersistService::class, |
||
| 84 | ['entity_name' => $entityName, 'listener_provider' => $listenerProvider] |
||
| 85 | ); |
||
| 86 | |||
| 87 | /** @var LoggerInterface $logger */ |
||
| 88 | $logger = $this->getService($container, $options['logger'] ?? NullLogger::class, $requestedName); |
||
| 89 | |||
| 90 | return new $className($entityName, $queryService, $persistService, $logger); |
||
| 91 | } |
||
| 111 |