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
Push — master ( 42287f...fba610 )
by Andy
03:33
created

DiffCommand::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 3
nop 0
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-30
7
 *
8
 */
9
10
namespace Chapi\Commands;
11
12
use Chapi\BusinessCase\Comparison\JobComparisonInterface;
13
use Symfony\Component\Console\Input\InputArgument;
14
15
class DiffCommand extends AbstractCommand
16
{
17
    /**
18
     * Configures the current command.
19
     */
20
    protected function configure()
21
    {
22
        $this->setName('diff')
23
            ->setDescription('Show changes between jobs and working tree, etc')
24
            ->addArgument('jobName', InputArgument::OPTIONAL, 'Show changes for specific job')
25
        ;
26
    }
27
28
    /**
29
     * @return int
30
     */
31
    protected function process()
32
    {
33
        /** @var JobComparisonInterface  $jobComparisonBusinessCase */
34
        $jobComparisonBusinessCase = $this->getContainer()->get(JobComparisonInterface::DIC_NAME);
35
        $jobName = $this->input->getArgument('jobName');
36
37
        if (!empty($jobName)) {
38
            $this->printJobDiff($jobName);
39
        } else {
40
            $localJobUpdates = $jobComparisonBusinessCase->getLocalJobUpdates();
41
            if (!empty($localJobUpdates)) {
42
                foreach ($localJobUpdates as $jobName) {
43
                    $this->printJobDiff($jobName);
44
                }
45
            }
46
        }
47
48
        return 0;
49
    }
50
51
    /**
52
     * @param string $jobName
53
     */
54
    private function printJobDiff($jobName)
55
    {
56
        /** @var JobComparisonInterface  $jobComparisonBusinessCase */
57
        $jobComparisonBusinessCase = $this->getContainer()->get(JobComparisonInterface::DIC_NAME);
58
59
        $this->output->writeln(sprintf("\n<comment>diff %s</comment>", $jobName));
60
61
        $jobDiff = $jobComparisonBusinessCase->getJobDiff($jobName);
62
63
        foreach ($jobDiff as $property => $diff) {
64
            $diffLines = array_reverse(explode(PHP_EOL, $diff));
65
66
            foreach ($diffLines as $diffLine) {
67
                $diffSign = substr($diffLine, 0, 1);
68
69
                if ($diffSign == '+') {
70
                    $this->output->writeln(sprintf("<info>%s\t%s: %s</info>", $diffSign, $property, substr($diffLine, 1)));
71
                } elseif ($diffSign == '-') {
72
                    $this->output->writeln(sprintf("<fg=red>%s\t%s: %s</>", $diffSign, $property, substr($diffLine, 1)));
73
                } else {
74
                    $this->output->writeln(sprintf("\t%s: %s", $property, $diffLine));
75
                }
76
            }
77
        }
78
79
        $this->output->writeln("\n");
80
    }
81
}
82