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.

Repository   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 173
Duplicated Lines 46.24 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 4
dl 80
loc 173
ccs 0
cts 121
cp 0
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A builds() 10 10 1
A build() 0 10 1
A commits() 10 10 1
A settings() 0 10 1
A isActive() 0 12 1
A enable() 10 10 1
A disable() 10 10 1
A branches() 10 10 1
A vars() 10 10 1
A caches() 10 10 1
A key() 0 10 1
A refresh() 10 10 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 declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\Resource\Sync;
4
5
use ApiClients\Client\Travis\Resource\Repository as BaseRepository;
6
use ApiClients\Client\Travis\Resource\RepositoryInterface;
7
use ApiClients\Client\Travis\Resource\RepositoryKeyInterface;
8
use ApiClients\Client\Travis\Resource\SettingsInterface;
9
use ApiClients\Foundation\Hydrator\CommandBus\Command\BuildAsyncFromSyncCommand;
10
use Rx\React\Promise;
11
use function React\Promise\resolve;
12
13
class Repository extends BaseRepository
14
{
15
    /**
16
     * @return array
17
     */
18 View Code Duplication
    public function builds(): array
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...
19
    {
20
        return $this->wait(
21
            $this->handleCommand(
22
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
23
            )->then(function (RepositoryInterface $repository) {
24
                return Promise::fromObservable($repository->builds()->toArray());
0 ignored issues
show
Bug introduced by
The method builds() does not exist on ApiClients\Client\Travis...rce\RepositoryInterface. Did you maybe mean lastBuildState()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
            })
26
        );
27
    }
28
29
    /**
30
     * @param  int   $id
31
     * @return Build
32
     */
33
    public function build(int $id): Build
34
    {
35
        return $this->wait(
36
            $this->handleCommand(
37
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
38
            )->then(function (RepositoryInterface $repository) use ($id) {
39
                return $repository->build($id);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method build() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
40
            })
41
        );
42
    }
43
44
    /**
45
     * @return array
46
     */
47 View Code Duplication
    public function commits(): array
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...
48
    {
49
        return $this->wait(
50
            $this->handleCommand(
51
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
52
            )->then(function (RepositoryInterface $repository) {
53
                return Promise::fromObservable($repository->commits()->toArray());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method commits() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
54
            })
55
        );
56
    }
57
58
    /**
59
     * @return SettingsInterface
60
     */
61
    public function settings(): SettingsInterface
62
    {
63
        return $this->wait(
64
            $this->handleCommand(
65
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
66
            )->then(function (RepositoryInterface $repository) {
67
                return $repository->settings();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method settings() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
68
            })
69
        );
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isActive(): bool
76
    {
77
        return $this->wait(
78
            $this->handleCommand(
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface React\Promise\PromiseInterface as the method otherwise() does only exist in the following implementations of said interface: React\Promise\FulfilledPromise, React\Promise\LazyPromise, React\Promise\Promise, React\Promise\RejectedPromise.

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...
79
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
80
            )->then(function (RepositoryInterface $repository) {
81
                return $repository->isActive();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method isActive() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
82
            })->otherwise(function (bool $state) {
83
                return resolve($state);
84
            })
85
        );
86
    }
87
88
    /**
89
     * @return Repository
90
     */
91 View Code Duplication
    public function enable(): Repository
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...
92
    {
93
        return $this->wait(
94
            $this->handleCommand(
95
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
96
            )->then(function (RepositoryInterface $repository) {
97
                return $repository->enable();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method enable() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
98
            })
99
        );
100
    }
101
102
    /**
103
     * @return Repository
104
     */
105 View Code Duplication
    public function disable(): Repository
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...
106
    {
107
        return $this->wait(
108
            $this->handleCommand(
109
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
110
            )->then(function (RepositoryInterface $repository) {
111
                return $repository->disable();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method disable() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
112
            })
113
        );
114
    }
115
116
    /**
117
     * @return array
118
     */
119 View Code Duplication
    public function branches(): array
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...
120
    {
121
        return $this->wait(
122
            $this->handleCommand(
123
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
124
            )->then(function (RepositoryInterface $repository) {
125
                return Promise::fromObservable($repository->branches()->toArray());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method branches() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
126
            })
127
        );
128
    }
129
130
    /**
131
     * @return array
132
     */
133 View Code Duplication
    public function vars(): array
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...
134
    {
135
        return $this->wait(
136
            $this->handleCommand(
137
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
138
            )->then(function (RepositoryInterface $repository) {
139
                return Promise::fromObservable($repository->vars()->toArray());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method vars() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
140
            })
141
        );
142
    }
143
144
    /**
145
     * @return array
146
     */
147 View Code Duplication
    public function caches(): array
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...
148
    {
149
        return $this->wait(
150
            $this->handleCommand(
151
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
152
            )->then(function (RepositoryInterface $repository) {
153
                return Promise::fromObservable($repository->caches()->toArray());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method caches() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
154
            })
155
        );
156
    }
157
158
    /**
159
     * @return RepositoryKeyInterface
160
     */
161
    public function key(): RepositoryKeyInterface
162
    {
163
        return $this->wait(
164
            $this->handleCommand(
165
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
166
            )->then(function (RepositoryInterface $repository) {
167
                return $repository->key();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method key() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
168
            })
169
        );
170
    }
171
172
    /**
173
     * @return Repository
174
     */
175 View Code Duplication
    public function refresh(): Repository
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...
176
    {
177
        return $this->wait(
178
            $this->handleCommand(
179
                new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
180
            )->then(function (RepositoryInterface $repository) {
181
                return $repository->refresh();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ApiClients\Client\Travis...rce\RepositoryInterface as the method refresh() does only exist in the following implementations of said interface: ApiClients\Client\Travis\Resource\Async\Repository, ApiClients\Client\Travis\Resource\Sync\Repository.

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...
182
            })
183
        );
184
    }
185
}
186