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 (#96)
by Patrick
02:14
created

DiffCommand::printJobDiff()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 38
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
rs 6.7272
cc 7
eloc 20
nc 13
nop 1
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 = explode(PHP_EOL, $diff);
65
66
            // the first line might be missing some leading whitespace
67
            if (count($diffLines) > 1) {
68
                $lastLine = $diffLines[count($diffLines) - 1];
69
70
                if (strpos($lastLine, ' ') === 0) {
71
                    $length = strspn($lastLine, ' ');
72
73
                    $diffLines[0] = substr($lastLine, 0, $length) . $diffLines[0];
74
                }
75
            }
76
77
            foreach ($diffLines as $diffLine) {
78
                $diffSign = substr($diffLine, 0, 1);
79
80
                if ($diffSign == '+') {
81
                    $this->output->writeln(sprintf("<info>%s\t%s: %s</info>", $diffSign, $property, substr($diffLine, 1)));
82
                } elseif ($diffSign == '-') {
83
                    $this->output->writeln(sprintf("<fg=red>%s\t%s: %s</>", $diffSign, $property, substr($diffLine, 1)));
84
                } else {
85
                    $this->output->writeln(sprintf("\t%s: %s", $property, $diffLine));
86
                }
87
            }
88
        }
89
90
        $this->output->writeln("\n");
91
    }
92
}
93