Conditions | 24 |
Paths | > 20000 |
Total Lines | 126 |
Code Lines | 79 |
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 |
||
74 | private function doResolveDefinition(ChildDefinition $definition): Definition |
||
75 | { |
||
76 | if (!$this->container->has($parent = $definition->getParent())) { |
||
77 | throw new RuntimeException(\sprintf('Parent definition "%s" does not exist.', $parent)); |
||
78 | } |
||
79 | |||
80 | $searchKey = array_search($parent, $this->currentPath); |
||
81 | $this->currentPath[] = $parent; |
||
82 | |||
83 | if (false !== $searchKey) { |
||
84 | throw new ServiceCircularReferenceException($parent, \array_slice($this->currentPath, $searchKey)); |
||
85 | } |
||
86 | |||
87 | $parentDef = $this->container->findDefinition($parent); |
||
88 | if ($parentDef instanceof ChildDefinition) { |
||
89 | $id = $this->currentId; |
||
90 | $this->currentId = $parent; |
||
91 | $parentDef = $this->resolveDefinition($parentDef); |
||
92 | $this->container->setDefinition($parent, $parentDef); |
||
93 | $this->currentId = $id; |
||
94 | } |
||
95 | |||
96 | $this->container->log($this, \sprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent)); |
||
97 | $def = new Definition(); |
||
98 | |||
99 | // merge in parent definition |
||
100 | // purposely ignored attributes: abstract, shared, tags, autoconfigured |
||
101 | $def->setClass($parentDef->getClass()); |
||
102 | $def->setArguments($parentDef->getArguments()); |
||
103 | $def->setMethodCalls($parentDef->getMethodCalls()); |
||
104 | $def->setProperties($parentDef->getProperties()); |
||
105 | if ($parentDef->isDeprecated()) { |
||
106 | $deprecation = $parentDef->getDeprecation('%service_id%'); |
||
107 | $def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']); |
||
108 | } |
||
109 | $def->setFactory($parentDef->getFactory()); |
||
110 | $def->setConfigurator($parentDef->getConfigurator()); |
||
111 | $def->setFile($parentDef->getFile()); |
||
112 | $def->setPublic($parentDef->isPublic()); |
||
113 | $def->setLazy($parentDef->isLazy()); |
||
114 | $def->setAutowired($parentDef->isAutowired()); |
||
115 | $def->setChanges($parentDef->getChanges()); |
||
116 | |||
117 | $def->setBindings($definition->getBindings() + $parentDef->getBindings()); |
||
118 | |||
119 | $def->setSynthetic($definition->isSynthetic()); |
||
120 | |||
121 | // overwrite with values specified in the decorator |
||
122 | $changes = $definition->getChanges(); |
||
123 | if (isset($changes['class'])) { |
||
124 | $def->setClass($definition->getClass()); |
||
125 | } |
||
126 | if (isset($changes['factory'])) { |
||
127 | $def->setFactory($definition->getFactory()); |
||
128 | } |
||
129 | if (isset($changes['configurator'])) { |
||
130 | $def->setConfigurator($definition->getConfigurator()); |
||
131 | } |
||
132 | if (isset($changes['file'])) { |
||
133 | $def->setFile($definition->getFile()); |
||
134 | } |
||
135 | if (isset($changes['public'])) { |
||
136 | $def->setPublic($definition->isPublic()); |
||
137 | } else { |
||
138 | $def->setPublic($parentDef->isPublic()); |
||
139 | } |
||
140 | if (isset($changes['lazy'])) { |
||
141 | $def->setLazy($definition->isLazy()); |
||
142 | } |
||
143 | if (isset($changes['deprecated']) && $definition->isDeprecated()) { |
||
144 | $deprecation = $definition->getDeprecation('%service_id%'); |
||
145 | $def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']); |
||
146 | } |
||
147 | if (isset($changes['autowired'])) { |
||
148 | $def->setAutowired($definition->isAutowired()); |
||
149 | } |
||
150 | if (isset($changes['shared'])) { |
||
151 | $def->setShared($definition->isShared()); |
||
152 | } |
||
153 | if (isset($changes['decorated_service'])) { |
||
154 | $decoratedService = $definition->getDecoratedService(); |
||
155 | if (null === $decoratedService) { |
||
156 | $def->setDecoratedService($decoratedService); |
||
157 | } else { |
||
158 | $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2], $decoratedService[3] ?? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | // merge arguments |
||
163 | foreach ($definition->getArguments() as $k => $v) { |
||
164 | if (is_numeric($k)) { |
||
165 | $def->addArgument($v); |
||
166 | } elseif (str_starts_with($k, 'index_')) { |
||
167 | $def->replaceArgument((int) substr($k, \strlen('index_')), $v); |
||
168 | } else { |
||
169 | $def->setArgument($k, $v); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | // merge properties |
||
174 | foreach ($definition->getProperties() as $k => $v) { |
||
175 | $def->setProperty($k, $v); |
||
176 | } |
||
177 | |||
178 | // append method calls |
||
179 | if ($calls = $definition->getMethodCalls()) { |
||
180 | $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls)); |
||
181 | } |
||
182 | |||
183 | $def->addError($parentDef); |
||
184 | $def->addError($definition); |
||
185 | |||
186 | // these attributes are always taken from the child |
||
187 | $def->setAbstract($definition->isAbstract()); |
||
188 | $def->setTags($definition->getTags()); |
||
189 | // autoconfigure is never taken from parent (on purpose) |
||
190 | // and it's not legal on an instanceof |
||
191 | $def->setAutoconfigured($definition->isAutoconfigured()); |
||
192 | |||
193 | if (!$def->hasTag('proxy')) { |
||
194 | foreach ($parentDef->getTag('proxy') as $v) { |
||
195 | $def->addTag('proxy', $v); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | return $def; |
||
200 | } |
||
202 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.