Failed Conditions
Pull Request — dev (#12)
by Steve
02:20 queued 12s
created

VersionsCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * Magedownload CLI
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageDownload
8
 * @package   MageDownload
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/magedownload-cli
13
 */
14
15
namespace MageDownload\Command;
16
17
use MageDownload\Info;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * Versions command
25
 *
26
 * @category  MageDownload
27
 * @package   MageDownload
28
 * @author    Steve Robbins <[email protected]>
29
 * @copyright 2015 Steve Robbins
30
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
31
 * @link      https://github.com/steverobbins/magedownload-cli
32
 */
33
class VersionsCommand extends AbstractCommand
34
{
35
    const NAME = 'versions';
36
37
    const API_ACTION = 'versions';
38
39
    /**
40
     * Configure command
41
     *
42
     * @return void
43
     */
44
    protected function configure()
45
    {
46
        $this
47
            ->setName(self::NAME)
48
            ->setDescription('List files available for download');
49
        parent::configure();
50
    }
51
52
    /**
53
     * Execute command
54
     *
55
     * @param InputInterface  $input
56
     * @param OutputInterface $output
57
     *
58
     * @return void
59
     */
60
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $info = new Info;
63
        return $this->render($info->sendCommand(
64
            self::API_ACTION,
65
            $this->getAccountId(),
1 ignored issue
show
Bug introduced by
It seems like $this->getAccountId() targeting MageDownload\Command\Abs...Command::getAccountId() can also be of type boolean; however, MageDownload\Info::sendCommand() 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...
66
            $this->getAccessToken()
1 ignored issue
show
Bug introduced by
It seems like $this->getAccessToken() targeting MageDownload\Command\Abs...mmand::getAccessToken() can also be of type boolean; however, MageDownload\Info::sendCommand() 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...
67
        ));
68
    }
69
70
    /**
71
     * Render the versions action
72
     *
73
     * @param string $result
74
     *
75
     * @return void
76
     */
77
    protected function render($result)
78
    {
79
        $editions = preg_split('/\n{2}/', $result);
80
        foreach ($editions as $info) {
81
            $bits = preg_split('/\-{5,}/', $info);
82
            $versions = explode("\n", trim($bits[1]));
83
            usort($versions, 'version_compare');
84
            array_walk($versions, function (&$value) {
85
                $value = array($value);
86
            });
87
            $this->out(array(array(
88
                'type' => 'table',
89
                'data' => array(
90
                    array(trim($bits[0])),
91
                    $versions
92
                )
93
            )));
94
        }
95
    }
96
}
97