| Conditions | 3 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 31 |
| 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 |
||
| 19 | public static function append(Application $app) |
||
| 20 | { |
||
| 21 | $app->appendCommand('product:view', 'Consulta a situação de um produto') |
||
| 22 | ->addArgument('productId', InputArgument::REQUIRED, 'Product ID') |
||
| 23 | ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
||
| 24 | $list = $app->processInputParameters([], $input, $output); |
||
| 25 | |||
| 26 | $p = $app->factorySdk($list)->factoryManager('product')->findById($input->getArgument('productId')); |
||
| 27 | |||
| 28 | $app->displayTableResults($output, [[ |
||
| 29 | 'Id' => $p->getProductId(), |
||
| 30 | 'Brand' => $p->getBrand(), |
||
| 31 | 'Department' => $p->getDepartment(), |
||
| 32 | 'Product Type' => $p->getProductType(), |
||
| 33 | ]]); |
||
| 34 | |||
| 35 | $output->writeln('<fg=yellow>Skus</>'); |
||
| 36 | |||
| 37 | $app->displayTableResults($output, $p->getSkus()); |
||
| 38 | |||
| 39 | }); |
||
| 40 | |||
| 41 | $insertOptions = [ |
||
| 42 | ['key' => 'file'], |
||
| 43 | ]; |
||
| 44 | |||
| 45 | $app->appendCommand('product:insert', 'Insere um produto a partir do Json de um arquivo') |
||
| 46 | ->setDefinition($app->factoryDefinition($insertOptions)) |
||
| 47 | ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { |
||
| 48 | $list = $app->processInputParameters($insertOptions, $input, $output); |
||
| 49 | |||
| 50 | $data = json_decode(file_get_contents($list['file']), true); |
||
| 51 | $sdk = $app->factorySdk($list); |
||
| 52 | $product = $sdk->createProduct($data); |
||
| 53 | |||
| 54 | try { |
||
| 55 | $operation = $sdk->factoryManager('product')->save($product); |
||
| 56 | |||
| 57 | if (202 === $operation->getHttpStatusCode()) { |
||
| 58 | $output->writeln('<info>Successo!</info>'); |
||
| 59 | } |
||
| 60 | |||
| 61 | } catch (\Exception $e) { |
||
| 62 | $output->writeln('<error>Erro na criação</error>'); |
||
| 63 | $output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); |
||
| 64 | $output->writeln('Code: <comment>'.$e->getCode().'</comment>'); |
||
| 65 | } |
||
| 66 | }); |
||
| 67 | |||
| 68 | return $app; |
||
| 69 | } |
||
| 70 | } |
||
| 71 |