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