Conditions | 2 |
Paths | 1 |
Total Lines | 114 |
Code Lines | 80 |
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 |
||
20 | public function __construct( |
||
21 | EntityManager $entityManager, |
||
22 | Config|null $config = null, |
||
23 | array $metadata = [], |
||
24 | ) { |
||
25 | $metadata = new ArrayObject($metadata); |
||
26 | |||
27 | $this |
||
28 | ->set(EntityManager::class, $entityManager) |
||
29 | ->set( |
||
30 | Config::class, |
||
31 | static function () use ($config) { |
||
32 | if (! $config) { |
||
33 | $config = new Config(); |
||
34 | } |
||
35 | |||
36 | return $config; |
||
37 | }, |
||
38 | ) |
||
39 | ->set(EventDispatcher::class, static fn () => new EventDispatcher()) |
||
40 | ->set(Type\TypeContainer::class, static fn () => new Type\TypeContainer()) |
||
41 | ) |
||
|
|||
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(EventDispatcher::class), |
||
86 | $container->get('metadata'), |
||
87 | ); |
||
88 | }, |
||
89 | ) |
||
90 | ->set( |
||
91 | Resolve\ResolveEntityFactory::class, |
||
92 | static function (Container $container) { |
||
93 | return new Resolve\ResolveEntityFactory( |
||
94 | $container->get(Config::class), |
||
95 | $container->get(EntityManager::class), |
||
96 | $container->get(EventDispatcher::class), |
||
97 | $container->get('metadata'), |
||
98 | ); |
||
99 | }, |
||
100 | ) |
||
101 | ->set( |
||
102 | Filter\FilterFactory::class, |
||
103 | static function (Container $container) { |
||
104 | return new Filter\FilterFactory( |
||
105 | $container->get(Config::class), |
||
106 | $container->get(EntityManager::class), |
||
107 | $container->get(Type\TypeContainer::class), |
||
108 | $container->get(EventDispatcher::class), |
||
109 | ); |
||
110 | }, |
||
111 | ) |
||
112 | ->set( |
||
113 | Hydrator\HydratorContainer::class, |
||
114 | static function (Container $container) { |
||
115 | return new Hydrator\HydratorContainer( |
||
116 | $container->get(EntityManager::class), |
||
117 | $container->get(Type\Entity\EntityTypeContainer::class), |
||
118 | ); |
||
119 | }, |
||
120 | ) |
||
121 | ->set( |
||
122 | Input\InputFactory::class, |
||
123 | static function (Container $container) { |
||
124 | return new Input\InputFactory( |
||
125 | $container->get(Config::class), |
||
126 | $container->get(EntityManager::class), |
||
127 | $container->get(Type\Entity\EntityTypeContainer::class), |
||
128 | $container->get(Type\TypeContainer::class), |
||
129 | ); |
||
130 | }, |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | abstract public function set(string $id, mixed $value): mixed; |
||
136 |