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 ( 3e65ba...cab908 )
by Cees-Jan
08:21
created

User   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 10
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A refresh() 0 4 1
A repository() 0 8 1
A repositories() 0 22 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\Resource\Async;
4
5
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand;
6
use ApiClients\Foundation\Transport\CommandBus\Command\JsonDecodeCommand;
7
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand;
8
use ApiClients\Foundation\Transport\Response;
9
use ApiClients\Client\Github\CommandBus\Command\IteratePagesCommand;
10
use ApiClients\Client\Github\Resource\User as BaseUser;
11
use Psr\Http\Message\ResponseInterface;
12
use Rx\Observable;
13
use Rx\ObservableInterface;
14
use Rx\ObserverInterface;
15
use Rx\React\Promise;
16
use Rx\SchedulerInterface;
17
18
class User extends BaseUser
19
{
20
    public function refresh() : User
21
    {
22
        return $this->wait($this->callAsync('refresh'));
0 ignored issues
show
Bug introduced by
The method callAsync() does not seem to exist on object<ApiClients\Client...ub\Resource\Async\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method wait() does not seem to exist on object<ApiClients\Client...ub\Resource\Async\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
    }
24
25
    public function repository(string $repository)
26
    {
27
        return $this->getCommandBus()->handle(
28
            new SimpleRequestCommand('repos/' . $this->login() . '/' . $repository)
29
        )->then(function (ResponseInterface $response) {
30
            return $this->getCommandBus()->handle(new HydrateCommand('Repository', $response->getBody()->getJson()));
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Psr\Http\Message\StreamInterface as the method getJson() does only exist in the following implementations of said interface: ApiClients\Foundation\Transport\JsonStream.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
31
        });
32
    }
33
34
    public function repositories(): ObservableInterface
35
    {
36
        return Observable::create(function (
37
            ObserverInterface $observer,
38
            SchedulerInterface $scheduler
39
        ) {
40
            $this->getCommandBus()->handle(
41
                new IteratePagesCommand('users/' . $this->login() . '/repos', $scheduler)
0 ignored issues
show
Unused Code introduced by
The call to IteratePagesCommand::__construct() has too many arguments starting with $scheduler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
            )->done(function (Observable $observable) use ($observer, $scheduler) {
43
                $observable->subscribeCallback(
44
                    [$observer, 'onNext'],
45
                    [$observer, 'onError'],
46
                    [$observer, 'onCompleted'],
47
                    $scheduler
48
                );
49
            });
50
        })->flatMap(function ($repositories) {
51
            return Observable::fromArray($repositories);
52
        })->flatMap(function ($repository) {
53
            return Promise::toObservable($this->getCommandBus()->handle(new HydrateCommand('Repository', $repository)));
54
        });
55
    }
56
}
57