| Conditions | 11 |
| Paths | 8 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 54 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 55 | { |
||
| 56 | $io = new SymfonyStyle($input, $output); |
||
| 57 | |||
| 58 | $resource = $input->getArgument('resource'); |
||
| 59 | $itemOperation = $input->getOption('itemOperation'); |
||
| 60 | $collectionOperation = $input->getOption('collectionOperation'); |
||
| 61 | $format = $input->getOption('format'); |
||
| 62 | $outputType = $input->getOption('output'); |
||
| 63 | |||
| 64 | if (!isset($this->formats[$format])) { |
||
| 65 | throw new InvalidOptionException(sprintf('The response format "%s" is not supported. Supported formats are : %s.', $format, implode(', ', array_keys($this->formats)))); |
||
|
|
|||
| 66 | } |
||
| 67 | |||
| 68 | $operationType = null; |
||
| 69 | $operationName = null; |
||
| 70 | |||
| 71 | if ($itemOperation && $collectionOperation) { |
||
| 72 | throw new InvalidOptionException('You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.'); |
||
| 73 | } |
||
| 74 | |||
| 75 | if (null !== $itemOperation || null !== $collectionOperation) { |
||
| 76 | $operationType = $itemOperation ? OperationType::ITEM : OperationType::COLLECTION; |
||
| 77 | $operationName = $itemOperation ?? $collectionOperation; |
||
| 78 | } |
||
| 79 | |||
| 80 | $schema = $this->schemaFactory->buildSchema($resource, $format, $outputType , $operationType, $operationName); |
||
| 81 | |||
| 82 | if (null !== $operationType && null !== $operationName && !$schema->isDefined()) { |
||
| 83 | $io->error(sprintf('There is no %s defined for the operation "%s" of the resource "%s".', $outputType ? 'outputs': 'inputs', $operationName, $resource)); |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | |||
| 87 | $io->text(json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
| 88 | } |
||
| 90 |