| Conditions | 10 |
| Paths | 42 |
| Total Lines | 51 |
| Code Lines | 26 |
| 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 |
||
| 62 | protected function httpBrowser(array $kernelOptions = [], array $pantherOptions = []): HttpBrowser |
||
| 63 | { |
||
| 64 | $class = $_SERVER['HTTP_BROWSER_CLASS'] ?? HttpBrowser::class; |
||
| 65 | |||
| 66 | if (!\is_a($class, HttpBrowser::class, true)) { |
||
| 67 | throw new \RuntimeException(\sprintf('"HTTP_BROWSER_CLASS" env variable must reference a class that extends %s.', HttpBrowser::class)); |
||
| 68 | } |
||
| 69 | |||
| 70 | $baseUri = $_SERVER['HTTP_BROWSER_URI'] ?? null; |
||
| 71 | |||
| 72 | if (!$baseUri && !$this instanceof PantherTestCase) { |
||
| 73 | throw new \RuntimeException(\sprintf('If not using "HTTP_BROWSER_URI", your TestCase must extend "%s".', PantherTestCase::class)); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!$baseUri) { |
||
| 77 | self::startWebServer($pantherOptions); |
||
| 78 | |||
| 79 | $baseUri = self::$baseUri; |
||
| 80 | } |
||
| 81 | |||
| 82 | // copied from PantherTestCaseTrait::createHttpBrowserClient() |
||
| 83 | $client = new HttpBrowserClient(); |
||
| 84 | $urlComponents = \parse_url($baseUri); |
||
| 85 | $host = $urlComponents['host']; |
||
| 86 | |||
| 87 | if (isset($urlComponents['port'])) { |
||
| 88 | $host .= ":{$urlComponents['port']}"; |
||
| 89 | } |
||
| 90 | |||
| 91 | $client->setServerParameter('HTTP_HOST', $host); |
||
| 92 | |||
| 93 | if ('https' === ($urlComponents['scheme'] ?? 'http')) { |
||
| 94 | $client->setServerParameter('HTTPS', 'true'); |
||
| 95 | } |
||
| 96 | |||
| 97 | $browser = new $class(self::$httpBrowserClients[] = $client); |
||
| 98 | |||
| 99 | if ($this instanceof KernelTestCase) { |
||
| 100 | if (!static::$booted) { |
||
| 101 | static::bootKernel($kernelOptions); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (static::$container->has('profiler')) { |
||
| 105 | $browser->setProfiler(static::$container->get('profiler')); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | BrowserExtension::registerBrowser($browser); |
||
| 110 | |||
| 111 | return $browser |
||
| 112 | ->setSourceDir($_SERVER['BROWSER_SOURCE_DIR'] ?? './var/browser/source') |
||
| 113 | ; |
||
| 150 |