Completed
Push — master ( d217d7...395774 )
by
unknown
26s queued 11s
created

UpdateDealerTables::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Dealer\Commands;
5
6
7
use Dealer\Service\UpdateTablesService;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Thelia\Command\ContainerAwareCommand;
12
13
class UpdateDealerTables extends ContainerAwareCommand
14
{
15
    /**
16
     * Sets the command name and description
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->setName("dealer:update:tables")
22
            ->setDescription("Update dealer tables from dealer_tab to dealer")
23
        ;
24
    }
25
26
    /**
27
     * @param InputInterface $input
28
     * @param OutputInterface $output
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        /** @var UpdateTablesService $service */
33
        $service = $this->getContainer()->get(UpdateTablesService::SERVICE_ID);
34
        $response = $service->updateTables();
35
36
        if (!is_array($response)) {
37
            $output->writeln($response);
38
        }
39
40
        $output->writeln('Update successful');
41
        if (!empty($response)) {
42
            $output->writeln('However these countries were not found and defaulted as France');
43
            foreach ($response as $countryNotFound) {
0 ignored issues
show
Bug introduced by
The expression $response of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
44
                $output->writeln($countryNotFound);
45
            }
46
        }
47
    }
48
}