| Conditions | 5 |
| Paths | 4 |
| Total Lines | 107 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 43 | public function __construct( |
||
| 44 | EntityManager $entityManager, |
||
| 45 | Config|null $config = null, |
||
| 46 | array|null $metadataConfig = null, |
||
| 47 | ) { |
||
| 48 | $this->clearTypeManagerLocal = self::$clearTypeManager; |
||
| 49 | |||
| 50 | if (! self::$typeManagerShared) { |
||
| 51 | self::$typeManagerShared = new Type\TypeManager(); |
||
| 52 | } |
||
| 53 | |||
| 54 | $this |
||
| 55 | // Plain classes |
||
| 56 | ->set(EntityManager::class, $entityManager) |
||
| 57 | ->set( |
||
| 58 | Config::class, |
||
| 59 | static function () use ($config) { |
||
| 60 | if (! $config) { |
||
| 61 | $config = new Config(); |
||
| 62 | } |
||
| 63 | |||
| 64 | return $config; |
||
| 65 | }, |
||
| 66 | ) |
||
| 67 | ->set( |
||
| 68 | EventDispatcher::class, |
||
| 69 | static fn () => new EventDispatcher() |
||
| 70 | ) |
||
| 71 | ->set( |
||
| 72 | Type\TypeManager::class, |
||
| 73 | fn () => $this->clearTypeManagerLocal ? |
||
| 74 | new Type\TypeManager() |
||
| 75 | : self::$typeManagerShared, |
||
| 76 | ) |
||
| 77 | ->set( |
||
| 78 | Metadata\Metadata::class, |
||
| 79 | static function (ContainerInterface $container) use ($metadataConfig) { |
||
| 80 | return (new Metadata\MetadataFactory($container, $metadataConfig))->getMetadata(); |
||
| 81 | }, |
||
| 82 | ) |
||
| 83 | ->set( |
||
| 84 | Resolve\FieldResolver::class, |
||
| 85 | static function (ContainerInterface $container) { |
||
| 86 | return new Resolve\FieldResolver( |
||
| 87 | $container->get(Config::class), |
||
| 88 | $container->get(Metadata\Metadata::class), |
||
| 89 | ); |
||
| 90 | }, |
||
| 91 | ) |
||
| 92 | ->set( |
||
| 93 | Resolve\ResolveCollectionFactory::class, |
||
| 94 | static function (ContainerInterface $container) { |
||
| 95 | return new Resolve\ResolveCollectionFactory( |
||
| 96 | $container->get(EntityManager::class), |
||
| 97 | $container->get(Config::class), |
||
| 98 | $container->get(Resolve\FieldResolver::class), |
||
| 99 | $container->get(Type\TypeManager::class), |
||
| 100 | ); |
||
| 101 | }, |
||
| 102 | ) |
||
| 103 | ->set( |
||
| 104 | Resolve\ResolveEntityFactory::class, |
||
| 105 | static function (ContainerInterface $container) { |
||
| 106 | return new Resolve\ResolveEntityFactory( |
||
| 107 | $container->get(Config::class), |
||
| 108 | $container->get(EntityManager::class), |
||
| 109 | $container->get(EventDispatcher::class), |
||
| 110 | ); |
||
| 111 | }, |
||
| 112 | ) |
||
| 113 | ->set( |
||
| 114 | Criteria\CriteriaFactory::class, |
||
| 115 | static function (ContainerInterface $container) { |
||
| 116 | return new Criteria\CriteriaFactory( |
||
| 117 | $container->get(Config::class), |
||
| 118 | $container->get(EntityManager::class), |
||
| 119 | $container->get(Type\TypeManager::class), |
||
| 120 | $container->get(EventDispatcher::class), |
||
| 121 | ); |
||
| 122 | }, |
||
| 123 | ) |
||
| 124 | ->set( |
||
| 125 | Hydrator\HydratorFactory::class, |
||
| 126 | static function (ContainerInterface $container) { |
||
| 127 | return new Hydrator\HydratorFactory( |
||
| 128 | $container->get(EntityManager::class), |
||
| 129 | $container->get(Metadata\Metadata::class), |
||
| 130 | ); |
||
| 131 | }, |
||
| 132 | ) |
||
| 133 | ->set( |
||
| 134 | Input\InputFactory::class, |
||
| 135 | static function (ContainerInterface $container) { |
||
| 136 | return new Input\InputFactory( |
||
| 137 | $container->get(Config::class), |
||
| 138 | $container->get(EntityManager::class), |
||
| 139 | $container->get(Type\TypeManager::class), |
||
| 140 | $container->get(Metadata\Metadata::class), |
||
| 141 | ); |
||
| 142 | }, |
||
| 143 | ); |
||
| 144 | |||
| 145 | if (! $this->get(Config::class)->getGlobalEnable()) { |
||
|
|
|||
| 146 | return; |
||
| 147 | } |
||
| 148 | |||
| 149 | $this->set(Type\TypeManager::class, new Type\TypeManager()); |
||
| 150 | } |
||
| 154 |