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.

Job   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 10
dl 10
loc 47
rs 10
c 2
b 0
f 0
ccs 0
cts 5
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 21 1
A annotations() 10 10 1
A refresh() 0 6 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
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis\Resource\Async;
5
6
use ApiClients\Client\Pusher\CommandBus\Command\SharedAppClientCommand;
7
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand;
8
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand;
9
use React\Promise\PromiseInterface;
10
use Rx\Observable;
11
use Rx\ObservableInterface;
12
use Rx\Observer\CallbackObserver;
13
use Rx\ObserverInterface;
14
use Rx\React\Promise;
15
use Rx\SchedulerInterface;
16
use WyriHaximus\Travis\ApiSettings;
17
use WyriHaximus\Travis\Resource\Job as BaseJob;
18
use function React\Promise\resolve;
19
20
class Job extends BaseJob
21
{
22
    public function log(): ObservableInterface
23
    {
24
        return Observable::create(function (
25
            ObserverInterface $observer,
26
            SchedulerInterface $scheduler
0 ignored issues
show
Unused Code introduced by
The parameter $scheduler is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
        ) {
28
            $this->handleCommand(
29
                new SharedAppClientCommand(ApiSettings::PUSHER_KEY)
30
            )->then(function ($pusher) use ($observer) {
31
                $pusher->channel('job-' . $this->id)->filter(function ($message) {
32
                    return $message->event == 'job:log';
33
                })->map(function ($message) {
34
                    return json_decode($message->data, true);
35
                })->flatMap(function (array $json) {
36
                    return Promise::toObservable($this->handleCommand(new HydrateCommand('LogLine', $json)));
37
                })->subscribe(new CallbackObserver(function ($repository) use ($observer) {
38
                    $observer->onNext($repository);
39
                }));
40
            });
41
        });
42
    }
43
    /**
44
     * @return ObservableInterface
45
     */
46 View Code Duplication
    public function annotations(): ObservableInterface
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...
47
    {
48
        return Promise::toObservable(
49
            $this->handleCommand(new SimpleRequestCommand('jobs/' . $this->id() . '/annotations'))
50
        )->flatMap(function ($response) {
51
            return Observable::fromArray($response['annotations']);
52
        })->flatMap(function ($annotation) {
53
            return Promise::toObservable($this->handleCommand(new HydrateCommand('Annotation', $annotation)));
54
        });
55
    }
56
57
    /**
58
     * @return PromiseInterface
59
     */
60
    public function refresh(): PromiseInterface
61
    {
62
        return $this->handleCommand(new SimpleRequestCommand('jobs/' . $this->id))->then(function ($json) {
63
            return resolve($this->handleCommand(new HydrateCommand('Job', $json['job'])));
64
        });
65
    }
66
}
67