| Conditions | 11 |
| Paths | 9 |
| Total Lines | 52 |
| Code Lines | 25 |
| 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 |
||
| 63 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 64 | { |
||
| 65 | $io = new SymfonyStyle($input, $output); |
||
| 66 | |||
| 67 | /** @var string $resource */ |
||
| 68 | $resource = $input->getArgument('resource'); |
||
| 69 | /** @var ?string $itemOperation */ |
||
| 70 | $itemOperation = $input->getOption('itemOperation'); |
||
| 71 | /** @var ?string $collectionOperation */ |
||
| 72 | $collectionOperation = $input->getOption('collectionOperation'); |
||
| 73 | /** @var string $format */ |
||
| 74 | $format = $input->getOption('format'); |
||
| 75 | /** @var string $type */ |
||
| 76 | $type = $input->getOption('type'); |
||
| 77 | |||
| 78 | if (!\in_array($type, [Schema::TYPE_INPUT, Schema::TYPE_OUTPUT], true)) { |
||
| 79 | $io->error(sprintf('You can only use "%s" or "%s" for the "type" option', Schema::TYPE_INPUT, Schema::TYPE_OUTPUT)); |
||
| 80 | |||
| 81 | return 1; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!\in_array($format, $this->formats, true)) { |
||
| 85 | throw new InvalidOptionException(sprintf('The response format "%s" is not supported. Supported formats are : %s.', $format, implode(', ', $this->formats))); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** @var ?string $operationType */ |
||
| 89 | $operationType = null; |
||
| 90 | /** @var ?string $operationName */ |
||
| 91 | $operationName = null; |
||
| 92 | |||
| 93 | if ($itemOperation && $collectionOperation) { |
||
| 94 | $io->error('You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.'); |
||
| 95 | |||
| 96 | return 1; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (null !== $itemOperation || null !== $collectionOperation) { |
||
| 100 | $operationType = $itemOperation ? OperationType::ITEM : OperationType::COLLECTION; |
||
| 101 | $operationName = $itemOperation ?? $collectionOperation; |
||
| 102 | } |
||
| 103 | |||
| 104 | $schema = $this->schemaFactory->buildSchema($resource, $format, $type, $operationType, $operationName); |
||
| 105 | |||
| 106 | if (null !== $operationType && null !== $operationName && !$schema->isDefined()) { |
||
| 107 | $io->error(sprintf('There is no %s defined for the operation "%s" of the resource "%s".', $type, $operationName, $resource)); |
||
| 108 | |||
| 109 | return 1; |
||
| 110 | } |
||
| 111 | |||
| 112 | $io->text((string) json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
| 113 | |||
| 114 | return 0; |
||
| 115 | } |
||
| 117 |