| Conditions | 10 |
| Paths | 384 |
| Total Lines | 48 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 54 | private function initProcess( |
||
| 55 | Config $config |
||
| 56 | ): Process { |
||
| 57 | $path = $config->getPhiremockPath(); |
||
| 58 | $phiremockPath = is_file($path) ? $path : $path . DIRECTORY_SEPARATOR . 'phiremock'; |
||
| 59 | $path = $config->getExpectationsPath(); |
||
| 60 | $expectationsPath = is_dir($path) ? $path : ''; |
||
| 61 | $path = $config->getLogsPath(); |
||
| 62 | $logFile = is_dir($path) ? $path . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME : $path; |
||
| 63 | |||
| 64 | $commandline = [ |
||
| 65 | $this->getCommandPrefix() . $phiremockPath, |
||
| 66 | '-i', |
||
| 67 | $config->getInterface(), |
||
| 68 | '-p', |
||
| 69 | $config->getPort(), |
||
| 70 | ]; |
||
| 71 | if ($config->isDebugMode()) { |
||
| 72 | $commandline[] = '-d'; |
||
| 73 | } |
||
| 74 | if ($expectationsPath) { |
||
| 75 | $commandline[] = '-e'; |
||
| 76 | $commandline[] = $expectationsPath; |
||
| 77 | } |
||
| 78 | if ($config->getServerFactory()) { |
||
| 79 | $commandline[] = '-f'; |
||
| 80 | $commandline[] = escapeshellarg($config->getServerFactory()); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($config->getCertificatePath()) { |
||
| 84 | $commandline[] = '-t'; |
||
| 85 | $commandline[] = $config->getCertificatePath(); |
||
| 86 | $commandline[] = '-k'; |
||
| 87 | $commandline[] = $config->getCertificateKeyPath(); |
||
| 88 | if ($config->getCertificatePassphrase()) { |
||
| 89 | $commandline[] = '-s'; |
||
| 90 | $commandline[] = $config->getCertificatePassphrase(); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | $commandline[] = '>'; |
||
| 95 | $commandline[] = $logFile; |
||
| 96 | $commandline[] = '2>&1'; |
||
| 97 | |||
| 98 | if (method_exists(Process::class, 'fromShellCommandline')) { |
||
| 99 | return Process::fromShellCommandline(implode(' ', $commandline)); |
||
| 100 | } |
||
| 101 | return new Process(implode(' ', $commandline)); |
||
|
1 ignored issue
–
show
|
|||
| 102 | } |
||
| 121 |