GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#78)
by Marc
04:42
created

StatusCommand::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 21
c 1
b 0
f 0
rs 9.3142
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-28
7
 *
8
 */
9
10
namespace Chapi\Commands;
11
12
use Chapi\BusinessCase\Comparison\JobComparisonInterface;
13
use Chapi\Service\JobIndex\JobIndexServiceInterface;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class StatusCommand extends AbstractCommand
18
{
19
    const LABEL_CHRONOS = 'chronos';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20
    const LABEL_MARATHON = 'marathon';
21
22
    /** @var JobIndexServiceInterface  */
23
    private $oJobIndexService;
24
25
    /**
26
     * Configures the current command.
27
     */
28
    protected function configure()
29
    {
30
        $this->setName('status')
31
            ->setDescription('Show the working tree status')
32
        ;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    protected function initialize(InputInterface $oInput, OutputInterface $oOutput)
39
    {
40
        parent::initialize($oInput, $oOutput);
41
42
        $this->oJobIndexService = $this->getContainer()->get(JobIndexServiceInterface::DIC_NAME);
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    protected function process()
49
    {
50
        $_aChangedJobs = $this->getChangedAppJobs();
51
52
        // tracked jobs
53
        $this->oOutput->writeln("\nChanges to be committed");
54
        $this->oOutput->writeln("  (use 'chapi reset <job>...' to unstage)");
55
        $this->oOutput->writeln('');
56
57
        $this->printStatusView($_aChangedJobs, true);
58
59
        // untracked jobs
60
        $this->oOutput->writeln("\nChanges not staged for commit");
61
        $this->oOutput->writeln("  (use 'chapi add <job>...' to update what will be committed)");
62
        $this->oOutput->writeln("  (use 'chapi checkout <job>...' to discard changes in local repository)");
63
        $this->oOutput->writeln('');
64
65
        $this->printStatusView($_aChangedJobs, false);
66
67
        return 0;
68
    }
69
70
    /**
71
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,array>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
72
     */
73
    private function getChangedAppJobs()
74
    {
75
        $_aResult = [
76
            'new' => [
77
                self::LABEL_CHRONOS => [],
78
                self::LABEL_MARATHON => [],
79
            ],
80
            'missing' => [
81
                self::LABEL_CHRONOS => [],
82
                self::LABEL_MARATHON => [],
83
            ],
84
            'updates' => [
85
                self::LABEL_CHRONOS => [],
86
                self::LABEL_MARATHON => [],
87
            ],
88
        ];
89
90
        /** @var JobComparisonInterface  $_oJobComparisonBusinessCaseChronos */
91
        /** @var JobComparisonInterface  $_oJobComparisonBusinessCaseMarathon */
92
        $_oJobComparisonBusinessCaseChronos = $this->getContainer()->get(JobComparisonInterface::DIC_NAME_CHRONOS);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
93
        $_oJobComparisonBusinessCaseMarathon = $this->getContainer()->get(JobComparisonInterface::DIC_NAME_MARATHON);
94
95
        $_aResult['new'][self::LABEL_MARATHON] = $_oJobComparisonBusinessCaseMarathon->getRemoteMissingJobs();
96
        $_aResult['new'][self::LABEL_CHRONOS] = $_oJobComparisonBusinessCaseChronos->getRemoteMissingJobs();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
97
98
        $_aResult['missing'][self::LABEL_MARATHON] = $_oJobComparisonBusinessCaseMarathon->getLocalMissingJobs();
99
        $_aResult['missing'][self::LABEL_CHRONOS] = $_oJobComparisonBusinessCaseChronos->getLocalMissingJobs();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
100
101
        $_aResult['updates'][self::LABEL_MARATHON] = $_oJobComparisonBusinessCaseMarathon->getLocalJobUpdates();
102
        $_aResult['updates'][self::LABEL_CHRONOS] = $_oJobComparisonBusinessCaseChronos->getLocalJobUpdates();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
103
104
105
        return $_aResult;
106
    }
107
108
    /**
109
     * @param array $aChangedJobs
110
     * @param bool $bFilterIsInIndex
111
     */
112
    private function printStatusView($aChangedJobs, $bFilterIsInIndex)
113
    {
114
        $_aFormatMap = [
115
            'new' => ['title' => 'New jobs in local repository', 'format' => "\t<comment>new %s job:\t%s</comment>"],
116
            'missing' => ['title' => 'Missing jobs in local repository', 'format' => "\t<fg=red>delete %s job:\t%s</>"],
117
            'updates' => ['title' => 'Updated jobs in local repository', 'format' => "\t<info>modified %s job:\t%s</info>"]
118
        ];
119
120
        foreach ($aChangedJobs as $_sJobStatus => $_aJobList)
121
        {
122
            $_aFilteredJobList = $this->filterJobListWithIndex($_aJobList, $bFilterIsInIndex);
123
            if (!empty($_aFilteredJobList))
124
            {
125
                $this->printJobList($_aFormatMap[$_sJobStatus]['title'], $_aFilteredJobList, $_aFormatMap[$_sJobStatus]['format']);
126
            }
127
        }
128
    }
129
130
    /**
131
     * @param array $aJobLists
132
     * @param bool $bFilterIsInIndex
133
     * @return array
134
     */
135
    private function filterJobListWithIndex($aJobLists, $bFilterIsInIndex)
136
    {
137
        $_aFilteredJobList = [];
138
139
        foreach ($aJobLists as $sAppLabel => $aJobList)
140
        {
141
            foreach ($aJobList as $_sJobName)
142
            {
143
                if ($bFilterIsInIndex == $this->oJobIndexService->isJobInIndex($_sJobName))
144
                {
145
                    $_aFilteredJobList[$sAppLabel][] = $_sJobName;
146
                }
147
            }
148
        }
149
150
        return $_aFilteredJobList;
151
    }
152
153
154
    /**
155
     * @param $sTitle
156
     * @param $aJobLists
157
     * @param $sListFormat
158
     * @return $this
159
     */
160
    private function printJobList($sTitle, $aJobLists, $sListFormat)
161
    {
162
        $this->oOutput->writeln(sprintf('  %s:', $sTitle));
163
164
        foreach ($aJobLists as $sLabel => $aJobList)
165
        {
166
            foreach ($aJobList as $_sJobName)
167
            {
168
                $this->oOutput->writeln(
169
                    sprintf($sListFormat, $sLabel, $_sJobName)
170
                );
171
            }
172
        }
173
174
        $this->oOutput->writeln("\n");
175
176
        return $this;
177
    }
178
}