| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 42 | public function with($file_link, PyStringNode $command) |
||
| 43 | { |
||
| 44 | $filename = PidFileTestCase::generateTempFile(); |
||
| 45 | $do_seconds = 3; |
||
| 46 | |||
| 47 | foreach ($this->varList as $var_name => $var_value) { |
||
| 48 | if (is_array($var_value)) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (is_string($var_value)) { |
||
| 53 | $var_value = '"' . $var_value . '"'; |
||
| 54 | } |
||
| 55 | |||
| 56 | $command = str_replace($var_name, $var_value, $command); |
||
| 57 | } |
||
| 58 | |||
| 59 | |||
| 60 | $file_content = <<<CONTENT |
||
| 61 | <?php |
||
| 62 | require "$this->pathAutoload"; |
||
| 63 | $command |
||
| 64 | sleep($do_seconds); |
||
| 65 | CONTENT; |
||
| 66 | |||
| 67 | file_put_contents($filename, $file_content); |
||
| 68 | |||
| 69 | $this->mainFile = $filename; |
||
| 70 | $this->mainCommand = $command; |
||
| 71 | |||
| 72 | $this->varList[$file_link] = [ |
||
| 73 | 'filename' => $filename |
||
| 74 | , 'time' => $do_seconds |
||
| 75 | ]; |
||
| 76 | |||
| 77 | static $descriptor_spec = [ |
||
| 78 | 0 => ['pipe', 'r'], |
||
| 79 | 1 => ['pipe', 'w'], |
||
| 80 | 2 => ['pipe', 'w'], |
||
| 81 | 3 => ['pipe', 'w'] // for return result code |
||
| 82 | ]; |
||
| 83 | $shell_command = "php -f {$filename}; echo $? >&3"; |
||
| 84 | $process_res = proc_open($shell_command, $descriptor_spec, $pipes, null, []); |
||
| 85 | /** @var array $proc_details */ |
||
| 86 | $proc_details = proc_get_status($process_res); |
||
| 87 | |||
| 88 | $this->varList[$file_link] = [ |
||
| 89 | 'filename' => $filename |
||
| 90 | , 'time' => $do_seconds |
||
| 91 | , 'pid' => $proc_details['pid'] |
||
| 92 | , 'resource' => $process_res |
||
| 93 | , 'pipes' => $pipes |
||
| 94 | ]; |
||
| 181 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.