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