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

InfoCommand::process()   D

Complexity

Conditions 10
Paths 18

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 10

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 37
ccs 20
cts 20
cp 1
rs 4.8196
c 1
b 1
f 0
cc 10
eloc 23
nc 18
nop 0
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Service\JobRepository\JobRepositoryInterface;
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Input\InputArgument;
15
16
class InfoCommand extends AbstractCommand
17
{
18
    /**
19
     * Configures the current command.
20
     */
21 1
    protected function configure()
22
    {
23 1
        $this->setName('info')
24 1
            ->setDescription('Display your job information from chronos')
25 1
            ->addArgument('jobName', InputArgument::REQUIRED, 'selected job')
26
        ;
27 1
    }
28
29
    /**
30
     * @return int
31
     */
32 1
    protected function process()
33
    {
34 1
        $jobName = $this->input->getArgument('jobName');
35
36 1
        $chronosJobEntity = $this->checkInChronos($jobName);
37 1
        $jobEntity = $chronosJobEntity == null ? $this->checkInMarathon($jobName) : $chronosJobEntity;
38
39 1
        if (!$jobEntity) {
40
            $this->output->writeln(sprintf('<fg=red>%s</>', 'Could not find the job.'));
41
            return 1;
42
        }
43
44 1
        $this->output->writeln(sprintf("\n<comment>info '%s'</comment>\n", $jobEntity->getKey()));
45
46 1
        $table = new Table($this->output);
47 1
        $table->setHeaders(array('Property', 'Value'));
48
49 1
        foreach ($jobEntity as $key => $value) {
50 1
            if (is_array($value) || is_object($value)) {
51 1
                $emptyString = (is_object($value)) ? '{ }' : '[ ]';
52
53 1
                $value = (!empty($value))
54
                    ? json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
55 1
                    : $emptyString;
56 1
            } elseif (is_bool($value)) {
57 1
                $value = (true === $value)
58 1
                    ? 'true'
59 1
                    : 'false';
60
            }
61
62 1
            $table->addRow(array($key, $value));
63
        }
64
65 1
        $table->render();
66
67 1
        return 0;
68
    }
69
70 1
    private function checkInChronos($jobName)
71
    {
72
        /** @var JobRepositoryInterface  $jobRepositoryChronos */
73 1
        $jobRepositoryChronos = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_CHRONOS);
74 1
        return $jobRepositoryChronos->getJob($jobName);
75
    }
76
77
    private function checkInMarathon($jobName)
78
    {
79
        /** @var JobRepositoryInterface  $jobRepositoryMarathon */
80
        $jobRepositoryMarathon = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_MARATHON);
81
        return $jobRepositoryMarathon->getJob($jobName);
82
    }
83
}
84