Conditions | 10 |
Paths | 12 |
Total Lines | 79 |
Code Lines | 37 |
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 |
||
112 | protected function execCommand($mode, $path=null, $params=array()) |
||
113 | { |
||
114 | $relative = $this->helper->relativizePath($path); |
||
115 | |||
116 | $this->log(sprintf( |
||
117 | '[%s] | Executing ['.$mode.'].', |
||
118 | $relative |
||
119 | )); |
||
120 | |||
121 | $cmd = $this->buildCommand($mode, $path, $params); |
||
122 | |||
123 | $output = array(); |
||
124 | exec($cmd, $output); |
||
125 | |||
126 | $lines = array(); |
||
127 | foreach($output as $line) { |
||
128 | $lines[] = mb_strtolower(trim(utf8_encode($line))); |
||
129 | } |
||
130 | |||
131 | $errorMessages = array(); |
||
132 | |||
133 | // command was skipped for some reason. We have to check |
||
134 | // for it this way, because this error is not shown like |
||
135 | // other regular errors. |
||
136 | // |
||
137 | // Can happen for example when the path is not under version |
||
138 | // control. |
||
139 | if(isset($lines[0]) && substr($lines[0], 0, 7) == 'skipped') |
||
140 | { |
||
141 | $tokens = explode('--', $lines[0]); |
||
142 | $message = trim(array_pop($tokens)); |
||
143 | |||
144 | $error = new SVNHelper_CommandError( |
||
145 | $this, |
||
146 | self::SVN_ERROR_TYPE_ERROR, |
||
147 | $message, |
||
148 | self::SVN_ERROR_IGNORED |
||
149 | ); |
||
150 | |||
151 | $errorMessages[] = $error; |
||
152 | } |
||
153 | // search for error codes. SVN adds lines in |
||
154 | // the following format: |
||
155 | // |
||
156 | // svn: e123456: error message |
||
157 | // svn: w123456: warning message |
||
158 | else |
||
159 | { |
||
160 | foreach($lines as $line) |
||
161 | { |
||
162 | if(strstr($line, 'svn:')) |
||
163 | { |
||
164 | $result = array(); |
||
165 | preg_match_all('/svn:[ ]*(e|warning:[ ]*w)([0-9]+):(.*)/', $line, $result, PREG_PATTERN_ORDER); |
||
166 | |||
167 | if(isset($result[1]) && isset($result[1][0])) |
||
168 | { |
||
169 | $message = trim($result[3][0]); |
||
170 | $code = trim($result[2][0]); |
||
171 | $type = self::SVN_ERROR_TYPE_ERROR; |
||
172 | |||
173 | if($result[1][0] != 'e') { |
||
174 | $type = self::SVN_ERROR_TYPE_WARNING; |
||
175 | } |
||
176 | |||
177 | $error = new SVNHelper_CommandError($this, $type, $message, $code); |
||
178 | $errorMessages[] = $error; |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | $result = new SVNHelper_CommandResult($this, $cmd, $lines, $errorMessages); |
||
185 | |||
186 | if($result->isError()) { |
||
187 | $this->log(sprintf('[%s] | Command returned errors.', $relative)); |
||
188 | } |
||
189 | |||
190 | return $result; |
||
191 | } |
||
284 | } |