| Conditions | 11 |
| Paths | 15 |
| Total Lines | 65 |
| Code Lines | 34 |
| 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 |
||
| 83 | public function __construct(?string $header = null, Config $config = null) |
||
| 84 | { |
||
| 85 | if (empty($header)) { |
||
| 86 | throw new BadRequestException($config->getHeader() . ' header is missing'); |
||
|
|
|||
| 87 | } |
||
| 88 | |||
| 89 | if (!$config) { |
||
| 90 | $config = Config::createDefault(); |
||
| 91 | } |
||
| 92 | |||
| 93 | $this->platforms = $config->getPlatforms(); |
||
| 94 | $this->environments = $config->getEnvironments(); |
||
| 95 | |||
| 96 | $format = 'platform;environment;version;os-version;device'; // ios;local;1.0.0;10.1;iphone-x |
||
| 97 | |||
| 98 | $headerArr = explode(';', $header); |
||
| 99 | |||
| 100 | // Parse platform |
||
| 101 | if (!isset($headerArr[0]) || !in_array($headerArr[0], $this->platforms)) { |
||
| 102 | throw new BadRequestException($config->getHeader() . ' header: Platform is not supported, should be: ' . |
||
| 103 | implode(',', $this->platforms) . |
||
| 104 | ' - format:' . $format); |
||
| 105 | } |
||
| 106 | |||
| 107 | $this->platform = $headerArr[0]; |
||
| 108 | |||
| 109 | // Parse env |
||
| 110 | if (!isset($headerArr[1]) || !in_array($headerArr[1], $this->environments)) { |
||
| 111 | throw new BadRequestException($config->getHeader() . ' header: Environment is not supported, should be: ' . |
||
| 112 | implode(',', $this->environments) . |
||
| 113 | ' - format:' . $format); |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->environment = $headerArr[1]; |
||
| 117 | |||
| 118 | // Web does not have further requirements, since they have a normal User-Agent header |
||
| 119 | if ($this->platform == 'web') { |
||
| 120 | return; |
||
| 121 | } |
||
| 122 | |||
| 123 | // Parse Build number |
||
| 124 | if (!isset($headerArr[2])) { |
||
| 125 | throw new BadRequestException('Meta header: Missing version' . ' - format:' . $format); |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->version = $headerArr[2]; |
||
| 129 | $versionArr = explode('.', $this->version); |
||
| 130 | $this->majorVersion = $versionArr[0] ?? 0; |
||
| 131 | $this->minorVersion = $versionArr[1] ?? 0; |
||
| 132 | $this->patchVersion = $versionArr[2] ?? 0; |
||
| 133 | |||
| 134 | // Parse device os version |
||
| 135 | if (!isset($headerArr[3])) { |
||
| 136 | throw new BadRequestException('Meta header: Missing device os version' . |
||
| 137 | ' - format:' . $format); |
||
| 138 | } |
||
| 139 | |||
| 140 | $this->deviceOsVersion = $headerArr[3]; |
||
| 141 | |||
| 142 | // Parse device |
||
| 143 | if (!isset($headerArr[4])) { |
||
| 144 | throw new BadRequestException('Meta header: Missing device' . ' - format:' . $format); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->device = $headerArr[4]; |
||
| 148 | } |
||
| 278 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.