| Conditions | 2 |
| Paths | 1 |
| Total Lines | 100 |
| Code Lines | 68 |
| 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 |
||
| 30 | public function __construct( |
||
| 31 | EntityManager $entityManager, |
||
| 32 | Config|null $config = null, |
||
| 33 | array|null $metadataConfig = null, |
||
| 34 | ) { |
||
| 35 | $this |
||
| 36 | // Plain classes |
||
| 37 | ->set(EntityManager::class, $entityManager) |
||
| 38 | ->set( |
||
| 39 | Config::class, |
||
| 40 | static function () use ($config) { |
||
| 41 | if (! $config) { |
||
| 42 | $config = new Config(); |
||
| 43 | } |
||
| 44 | |||
| 45 | return $config; |
||
| 46 | }, |
||
| 47 | ) |
||
| 48 | ->set( |
||
| 49 | EventDispatcher::class, |
||
| 50 | static fn () => new EventDispatcher() |
||
| 51 | ) |
||
| 52 | ->set( |
||
| 53 | Type\TypeManager::class, |
||
| 54 | static fn (ContainerInterface $container) => new Type\TypeManager($container) |
||
| 55 | ) |
||
| 56 | ->set( |
||
| 57 | Metadata\Metadata::class, |
||
| 58 | static function (ContainerInterface $container) use ($metadataConfig) { |
||
| 59 | return (new Metadata\MetadataFactory($container, $metadataConfig))->getMetadata(); |
||
| 60 | }, |
||
| 61 | ) |
||
| 62 | ->set( |
||
| 63 | Metadata\GlobalEnable::class, |
||
| 64 | static function (ContainerInterface $container) { |
||
| 65 | return new Metadata\GlobalEnable( |
||
| 66 | $container->get(EntityManager::class), |
||
| 67 | $container->get(Config::class), |
||
| 68 | ); |
||
| 69 | }, |
||
| 70 | ) |
||
| 71 | ->set( |
||
| 72 | Resolve\FieldResolver::class, |
||
| 73 | static function (ContainerInterface $container) { |
||
| 74 | return new Resolve\FieldResolver( |
||
| 75 | $container->get(Config::class), |
||
| 76 | $container->get(Type\TypeManager::class), |
||
| 77 | ); |
||
| 78 | }, |
||
| 79 | ) |
||
| 80 | ->set( |
||
| 81 | Resolve\ResolveCollectionFactory::class, |
||
| 82 | static function (ContainerInterface $container) { |
||
| 83 | return new Resolve\ResolveCollectionFactory( |
||
| 84 | $container->get(EntityManager::class), |
||
| 85 | $container->get(Config::class), |
||
| 86 | $container->get(Resolve\FieldResolver::class), |
||
| 87 | $container->get(Type\TypeManager::class), |
||
| 88 | $container->get(EventDispatcher::class), |
||
| 89 | $container->get(Metadata\Metadata::class), |
||
| 90 | ); |
||
| 91 | }, |
||
| 92 | ) |
||
| 93 | ->set( |
||
| 94 | Resolve\ResolveEntityFactory::class, |
||
| 95 | static function (ContainerInterface $container) { |
||
| 96 | return new Resolve\ResolveEntityFactory( |
||
| 97 | $container->get(Config::class), |
||
| 98 | $container->get(EntityManager::class), |
||
| 99 | $container->get(EventDispatcher::class), |
||
| 100 | ); |
||
| 101 | }, |
||
| 102 | ) |
||
| 103 | ->set( |
||
| 104 | Criteria\CriteriaFactory::class, |
||
| 105 | static function (ContainerInterface $container) { |
||
| 106 | return new Criteria\CriteriaFactory( |
||
| 107 | $container->get(Config::class), |
||
| 108 | $container->get(EntityManager::class), |
||
| 109 | $container->get(Type\TypeManager::class), |
||
| 110 | $container->get(EventDispatcher::class), |
||
| 111 | ); |
||
| 112 | }, |
||
| 113 | ) |
||
| 114 | ->set( |
||
| 115 | Hydrator\HydratorFactory::class, |
||
| 116 | static function (ContainerInterface $container) { |
||
| 117 | return new Hydrator\HydratorFactory( |
||
| 118 | $container->get(EntityManager::class), |
||
| 119 | $container->get(Type\TypeManager::class), |
||
| 120 | ); |
||
| 121 | }, |
||
| 122 | ) |
||
| 123 | ->set( |
||
| 124 | Input\InputFactory::class, |
||
| 125 | static function (ContainerInterface $container) { |
||
| 126 | return new Input\InputFactory( |
||
| 127 | $container->get(Config::class), |
||
| 128 | $container->get(EntityManager::class), |
||
| 129 | $container->get(Type\TypeManager::class), |
||
| 130 | ); |
||
| 137 |