Conditions | 11 |
Paths | 5 |
Total Lines | 50 |
Code Lines | 26 |
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 |
||
76 | protected function resolve($value) |
||
77 | { |
||
78 | if (null === $this->container) { |
||
79 | return $value; |
||
80 | } |
||
81 | |||
82 | if (\is_array($value)) { |
||
83 | foreach ($value as $key => $val) { |
||
84 | $value[$key] = $this->resolve($val); |
||
85 | } |
||
86 | |||
87 | return $value; |
||
88 | } |
||
89 | |||
90 | if (!\is_string($value)) { |
||
91 | return $value; |
||
92 | } |
||
93 | |||
94 | $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($value) { |
||
95 | $parameter = $match[1]; |
||
96 | |||
97 | // skip %% |
||
98 | if (!isset($parameter)) { |
||
99 | return '%%'; |
||
100 | } |
||
101 | |||
102 | if (preg_match('/^env\(\w+\)$/', $parameter)) { |
||
103 | throw new \RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $parameter)); |
||
104 | } |
||
105 | |||
106 | if (\array_key_exists($parameter, $this->collectedParameters)) { |
||
107 | return $this->collectedParameters[$parameter]; |
||
108 | } |
||
109 | |||
110 | if ($this->container instanceof SymfonyContainerInterface) { |
||
111 | $resolved = $this->container->getParameter($parameter); |
||
112 | } else { |
||
113 | $resolved = $this->container->get($parameter); |
||
|
|||
114 | } |
||
115 | |||
116 | if (\is_string($resolved) || is_numeric($resolved)) { |
||
117 | $this->collectedParameters[$parameter] = $resolved; |
||
118 | |||
119 | return (string) $resolved; |
||
120 | } |
||
121 | |||
122 | throw new\ RuntimeException(sprintf('The container parameter "%s", used in the resource configuration value "%s", must be a string or numeric, but it is of type %s.', $parameter, $value, \gettype($resolved))); |
||
123 | }, $value); |
||
124 | |||
125 | return str_replace('%%', '%', $escapedValue); |
||
126 | } |
||
128 |
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.