| Conditions | 10 |
| Paths | 14 |
| Total Lines | 70 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 118 | public static function setUpTestRunner(): void |
||
| 119 | { |
||
| 120 | echo "\33[33mSetting up test runner...\33[0m This may take a while.\n"; |
||
| 121 | |||
| 122 | $archive = 'https://github.com/hydephp/hyde/archive/refs/heads/master.zip'; |
||
| 123 | $target = self::getRunnerPath(); |
||
| 124 | if (file_exists($target)) { |
||
| 125 | rmdir($target); |
||
| 126 | } |
||
| 127 | |||
| 128 | echo "\33[33mDownloading test runner scaffolding...\33[0m\n"; |
||
| 129 | $raw = file_get_contents($archive); |
||
| 130 | |||
| 131 | if ($raw === false) { |
||
| 132 | throw new RuntimeException('Failed to download test runner.'); |
||
| 133 | } |
||
| 134 | |||
| 135 | echo "\33[33mExtracting archive...\33[0m\n"; |
||
| 136 | $zipPath = tempnam(sys_get_temp_dir(), 'hyde-master'); |
||
| 137 | |||
| 138 | if ($zipPath === false) { |
||
| 139 | throw new RuntimeException('Failed to create temporary file.'); |
||
| 140 | } |
||
| 141 | |||
| 142 | file_put_contents($zipPath, $raw); |
||
| 143 | |||
| 144 | $zip = new ZipArchive(); |
||
| 145 | |||
| 146 | if ($zip->open($zipPath) !== true) { |
||
| 147 | throw new RuntimeException('Failed to open zip archive.'); |
||
| 148 | } |
||
| 149 | |||
| 150 | // Get the name of the root directory in the zip file |
||
| 151 | $rootDir = $zip->getNameIndex(0); |
||
| 152 | |||
| 153 | // Extract to a temporary directory |
||
| 154 | $tempExtractPath = $target.'_temp'; |
||
| 155 | $zip->extractTo($tempExtractPath); |
||
| 156 | |||
| 157 | $zip->close(); |
||
| 158 | |||
| 159 | // Move the contents of the extracted directory to the target directory |
||
| 160 | rename($tempExtractPath.'/'.$rootDir, $target); |
||
| 161 | |||
| 162 | // Remove the temporary extraction directory |
||
| 163 | rmdir($tempExtractPath); |
||
| 164 | |||
| 165 | unlink($zipPath); |
||
| 166 | |||
| 167 | $runner = realpath($target); |
||
| 168 | |||
| 169 | if ($runner === false) { |
||
| 170 | throw new RuntimeException('Failed to get the real path of the test runner.'); |
||
| 171 | } |
||
| 172 | |||
| 173 | $workDir = getcwd(); |
||
| 174 | |||
| 175 | // Junction the package source of hyde/realtime-compiler to the test runner |
||
| 176 | $branch = getenv('HYDE_RC_BRANCH') ?: trim(shell_exec('git rev-parse --abbrev-ref HEAD') ?: 'master'); |
||
| 177 | echo "\33[33mInstalling hyde/realtime-compiler:dev-$branch...\33[0m\n"; |
||
| 178 | chdir($runner); |
||
| 179 | exec('composer config repositories.realtime-compiler path '.realpath(__DIR__.'/../../'), $output, $return); |
||
| 180 | if ($return !== 0) { |
||
| 181 | throw new RuntimeException('Failed to add repository path.'); |
||
| 182 | } |
||
| 183 | exec("composer require --dev hyde/realtime-compiler:dev-$branch --no-progress", $output, $return); |
||
| 184 | if ($return !== 0) { |
||
| 185 | throw new RuntimeException('Failed to install hyde/realtime-compiler.'); |
||
| 186 | } |
||
| 187 | chdir($workDir); |
||
| 188 | } |
||
| 200 |