| Conditions | 13 |
| Paths | 112 |
| Total Lines | 75 |
| Code Lines | 47 |
| 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 |
||
| 142 | private function generateServices($rootDir) |
||
| 143 | { |
||
| 144 | $this->output->writeln('<info>Generating folder structure for services.</info>'); |
||
| 145 | $fileSystem = new Filesystem(); |
||
| 146 | if ($fileSystem->exists($this->destinationDir)) { |
||
| 147 | $this->output->writeln('<comment> - > Removing old services.</comment>'); |
||
| 148 | $fileSystem->remove($this->destinationDir); |
||
| 149 | } |
||
| 150 | $fileSystem->mkdir($this->destinationDir); |
||
| 151 | $fileSystem->mkdir($this->destinationDir . '/definition/'); |
||
| 152 | $fileSystem->mkdir($this->destinationDir . '/schema/'); |
||
| 153 | |||
| 154 | // Let get all definition files |
||
| 155 | if ('CORE' == $this->contextMode) { |
||
| 156 | $rootDir = realpath( $rootDir . '/../'); |
||
| 157 | $directories = [ |
||
| 158 | $rootDir . '/src/Graviton', |
||
| 159 | $rootDir . '/vendor/libgraviton' |
||
| 160 | ]; |
||
| 161 | } else { |
||
| 162 | $rootDir = realpath($rootDir . '/../../../../vendor/'); |
||
| 163 | $directories = [ |
||
| 164 | $rootDir . '/graviton', |
||
| 165 | $rootDir . '/grv', |
||
| 166 | ]; |
||
| 167 | } |
||
| 168 | $this->output->writeln('<info>Scanning for services in.</info>'); |
||
| 169 | foreach ($directories as $dir) { |
||
| 170 | $this->output->writeln('<comment> - > '. $dir . '</comment>'); |
||
| 171 | } |
||
| 172 | |||
| 173 | $finder = new Finder(); |
||
| 174 | $finder->files()->in($directories) |
||
| 175 | ->name('*.json') |
||
| 176 | ->notName('_*') |
||
| 177 | ->path('/(^|\/)resources\/definition($|\/)/i'); |
||
| 178 | if ('WRAPPER' == $this->contextMode) { |
||
| 179 | $finder->notPath('/(^|\/)Tests($|\/)/i'); |
||
| 180 | } |
||
| 181 | |||
| 182 | $routes = []; |
||
| 183 | |||
| 184 | $progress = new ProgressBar($this->output, $finder->count()); |
||
| 185 | |||
| 186 | foreach ($finder as $file) { |
||
| 187 | $progress->advance(); |
||
| 188 | $path = $file->getRealPath(); |
||
| 189 | |||
| 190 | $json = json_decode($file->getContents()); |
||
| 191 | if (!$json || json_last_error()) { |
||
| 192 | throw new InvalidConfigurationException('Failure: ' . $path . ': ' . json_last_error_msg()); |
||
| 193 | } elseif (!property_exists($json, 'id')) { |
||
| 194 | throw new InvalidConfigurationException('Failure: ' . $path . ': id field is required'); |
||
| 195 | } |
||
| 196 | |||
| 197 | // Routes |
||
| 198 | if (property_exists($json, 'service' ) && property_exists($json->service, 'routerBase' )) { |
||
| 199 | $routes[$json->id] = trim( $json->service->routerBase, "/" ); |
||
| 200 | } |
||
| 201 | |||
| 202 | // Copy definition |
||
| 203 | if (property_exists($json, 'service') && property_exists($json->service, 'fixtures')) { |
||
| 204 | unset($json->service->fixtures); |
||
| 205 | } |
||
| 206 | $fileSystem->dumpFile($this->destinationDir . '/definition/' . $file->getFilename(), json_encode($json, JSON_PRETTY_PRINT)); |
||
| 207 | |||
| 208 | // Generate Schema |
||
| 209 | $schema = $this->generateSchema($file); |
||
| 210 | $fileSystem->dumpFile($this->destinationDir . '/schema/' . $file->getFilename(), $schema); |
||
| 211 | } |
||
| 212 | |||
| 213 | // Save routing |
||
| 214 | $fileSystem->dumpFile($this->destinationDir . '/routes.json', json_encode($routes, JSON_PRETTY_PRINT)); |
||
| 215 | |||
| 216 | } |
||
| 217 | |||
| 241 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..