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.

PushCommand   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 13.64 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 81.08%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 4
dl 12
loc 88
ccs 30
cts 37
cp 0.8108
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 18 2
A getOptionLog() 12 12 4
A setClient() 0 4 1
A getClient() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Softius\JenkinsJobMonitor;
4
5
use GuzzleHttp\ClientInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Class PushCommand
14
 * @package Softius\JenkinsJobMonitor
15
 */
16
class PushCommand extends Command
17
{
18
    /**
19
     * @var GuzzleHttp\ClientInterface
20
     */
21
    private $client;
22
23
    /**
24
     * Configures the push command.
25
     */
26 3
    protected function configure()
27
    {
28 3
        $this
29 3
            ->setName('push')
30 3
            ->setDescription('Sets external job result')
31 3
            ->addArgument('url', InputArgument::REQUIRED, 'Jenkins home URL')
32 3
            ->addArgument('job', InputArgument::REQUIRED, 'Job name as configured in Jenkins')
33 3
            ->addOption('display', null, InputOption::VALUE_OPTIONAL, '')
34 3
            ->addOption('description', null, InputOption::VALUE_OPTIONAL, '')
35 3
            ->addOption('duration', null, InputOption::VALUE_OPTIONAL, '')
36 3
            ->addOption('log', null, InputOption::VALUE_OPTIONAL, '');
37 3
    }
38
39
    /**
40
     * Executes the monitor command.
41
     *
42
     * @param InputInterface  $input  An InputInterface instance
43
     * @param OutputInterface $output An OutputInterface instance
44
     *
45
     * @return null|int null or 0 if everything went fine, or an error code
46
     */
47 3
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49 3
        $monitor = new JobMonitor(
50 3
            $input->getArgument('job'),
51 3
            $input->getOption('display'),
52 3
            $input->getOption('description')
53 3
        );
54 3
        $monitor->setLog($this->getOptionLog($input));
55
56
        try {
57 3
            $this->getClient()->send($monitor->getRequest(), ['base_uri' => $input->getArgument('url')]);
58 3
        } catch (\Exception $e) {
59
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
60
            return 1;
61
        }
62
63 3
        return 0;
64
    }
65
66
    /**
67
     * Returns the value for log option.
68
     *
69
     * If the log option is not provided, STDIN is being used instead.
70
     *
71
     * @param InputInterface $input
72
     * @throws \RuntimeException
73
     * @return mixed|string
74
     */
75 3 View Code Duplication
    public function getOptionLog(InputInterface $input)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77 3
        $log = $input->getOption('log');
78 3
        if (!$log && 0 === ftell(STDIN)) {
79
            $log = '';
80
            while (!feof(STDIN)) {
81
                $log .= fread(STDIN, 1024);
82
            }
83
        }
84
85 3
        return $log;
86
    }
87
88
    /**
89
     * @param GuzzleHttp\ClientInterface $client
90
     */
91 3
    public function setClient(ClientInterface $client)
92
    {
93 3
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<GuzzleHttp\ClientInterface> is incompatible with the declared type object<Softius\JenkinsJo...leHttp\ClientInterface> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
94 3
    }
95
96
    /**
97
     * @return Client
98
     */
99 3
    public function getClient()
100
    {
101 3
        return $this->client;
102
    }
103
}
104