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 (#68)
by Bidesh
02:54
created

InfoCommand::process()   D

Complexity

Conditions 10
Paths 18

Size

Total Lines 41
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 10.0406

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 41
ccs 25
cts 27
cp 0.9259
rs 4.8196
c 2
b 1
f 0
cc 10
eloc 23
nc 18
nop 0
crap 10.0406

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
        $_sJobName = $this->oInput->getArgument('jobName');
35
36 1
        $_oChronosJobEntity = $this->checkInChronos($_sJobName);
37 1
        $_oJobEntity = $_oChronosJobEntity == null ? $this->checkInMarathon($_sJobName) : $_oChronosJobEntity;
38
39 1
        if (!$_oJobEntity) {
40
            $this->oOutput->writeln(sprintf('<fg=red>%s</>', 'Could not find the job.'));
41
            return 1;
42
        }
43
44 1
        $this->oOutput->writeln(sprintf("\n<comment>info '%s'</comment>\n", $_oJobEntity->getKey()));
45
46 1
        $_oTable = new Table($this->oOutput);
47 1
        $_oTable->setHeaders(array('Property', 'Value'));
48
49 1
        foreach ($_oJobEntity as $_sKey => $_mValue)
50
        {
51 1
            if (is_array($_mValue) || is_object($_mValue))
52 1
            {
53 1
                $_sEmptyString = (is_object($_mValue)) ? '{ }' : '[ ]';
54
55 1
                $_mValue = (!empty($_mValue))
56 1
                    ? json_encode($_mValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
57 1
                    : $_sEmptyString;
58 1
            }
59 1
            elseif (is_bool($_mValue))
60
            {
61 1
                $_mValue = (true === $_mValue)
62 1
                    ? 'true'
63 1
                    : 'false';
64 1
            }
65
66 1
            $_oTable->addRow(array($_sKey, $_mValue));
67 1
        }
68
69 1
        $_oTable->render();
70
71 1
        return 0;
72
    }
73
74 1
    private function checkInChronos($sJobName)
75
    {
76
        /** @var JobRepositoryInterface  $_oJobRepositoryChronos */
77 1
        $_oJobRepositoryChronos = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_CHRONOS);
78 1
        return $_oJobRepositoryChronos->getJob($sJobName);
79
    }
80
81
    private function checkInMarathon($sJobName)
82
    {
83
        /** @var JobRepositoryInterface  $_oJobRepositoryMarathon */
84
        $_oJobRepositoryMarathon = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_MARATHON);
85
        return $_oJobRepositoryMarathon->getJob($sJobName);
86
    }
87
}