PatchCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 29.09 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 16
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 16 31 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Mage Scan
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageScan
8
 * @package   MageScan
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright 2015 Steve Robbins
11
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
12
 * @link      https://github.com/steverobbins/magescan
13
 */
14
15
namespace MageScan\Command\Scan;
16
17
use MageScan\Check\Patch;
18
use MageScan\Url;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Scan path command
24
 *
25
 * @category  MageScan
26
 * @package   MageScan
27
 * @author    Steve Robbins <[email protected]>
28
 * @copyright 2015 Steve Robbins
29
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
30
 * @link      https://github.com/steverobbins/magescan
31
 */
32
class PatchCommand extends AbstractCommand
33
{
34
    /**
35
     * Configure command
36
     *
37
     * @return void
38
     */
39
    protected function configure()
40
    {
41
        $this
42
            ->setName('scan:patch')
43
            ->setDescription('Get patch information');
44
        parent::configure();
45
    }
46
47
    /**
48
     * Execute command
49
     *
50
     * @param InputInterface  $input
51
     * @param OutputInterface $output
52
     *
53
     * @return void
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $rows  = [];
58
        $patch = new Patch;
59
        $url = new Url;
60
        $patch->setRequest($this->request);
61
        $patches = $patch->checkAll($url->clean($input->getArgument('url')));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('url') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string>; however, MageScan\Url::clean() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
62 View Code Duplication
        foreach ($patches as $name => $result) {
63
            switch ($result) {
64
                case PATCH::PATCHED:
65
                    $status = '<bg=green>Patched</bg=green>';
66
                    break;
67
                case PATCH::UNPATCHED:
68
                    $status = '<error>Unpatched</error>';
69
                    break;
70
                default:
71
                    $status = 'Unknown';
72
            }
73
            $rows[] = [
74
                $name,
75
                $status
76
            ];
77
        }
78
        $this->out('Patches', [[
79
            'type' => 'table',
80
            'data' => [
81
                ['Name', 'Status'],
82
                $rows
83
            ]
84
        ]]);
85
    }
86
}
87