Conditions | 10 |
Paths | 16 |
Total Lines | 55 |
Code Lines | 22 |
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 |
||
67 | public function parseVariable($value, $collector) |
||
68 | { |
||
69 | $this->checkLength($value); |
||
70 | |||
71 | $collector = $collector->getArrayCopy(); |
||
72 | |||
73 | if (preg_match_all('#\$\{([a-zA-Z0-9]+)\}#', $value, $matches, PREG_SET_ORDER)) { |
||
74 | |||
75 | if (is_array($matches)) { |
||
76 | |||
77 | foreach ($matches as $match) { |
||
78 | |||
79 | $origin = $match[0]; |
||
80 | $nameVar = $match[1]; |
||
81 | |||
82 | if (isset($collector[$nameVar])) { |
||
83 | |||
84 | $value = str_replace($origin, $collector[$nameVar], $value); |
||
85 | |||
86 | } else { |
||
87 | throw new Exception(sprintf('Unknown %s variable. Please check environment "%s" variable', $origin, $nameVar)); |
||
88 | } |
||
89 | |||
90 | } |
||
91 | |||
92 | } |
||
93 | } |
||
94 | |||
95 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
||
96 | |||
97 | if (preg_match_all('/\%([a-zA-Z0-9]+)\%/i', $value, $matches, PREG_SET_ORDER)) { |
||
98 | |||
99 | if (is_array($matches)) { |
||
100 | |||
101 | foreach ($matches as $match) { |
||
102 | |||
103 | $origin = $match[0]; |
||
104 | $nameVar = $match[1]; |
||
105 | |||
106 | if (isset($collector[$nameVar])) { |
||
107 | |||
108 | $value = str_replace($origin, $collector[$nameVar], $value); |
||
109 | |||
110 | } else { |
||
111 | throw new Exception(sprintf('Unknown %s variable. Please check environment "%s" variable', $origin, $nameVar)); |
||
112 | } |
||
113 | |||
114 | } |
||
115 | |||
116 | } |
||
117 | } |
||
118 | |||
119 | } |
||
120 | |||
121 | return $value; |
||
122 | } |
||
123 | } |