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.

DataServiceTestBase   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 2 Features 2
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 91
rs 10
c 3
b 2
f 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetterAndSetterName() 0 10 1
A testGetterAndSetterConnector() 0 9 1
A testGetterAndSetterConfig() 0 16 1
A testGetHost() 0 7 1
A testSetterAndGetterQueryLimitWithoutInitialisation() 0 10 1
A testTransformJsonResponseWithValidJson() 0 20 1
A testTransformJsonResponseWithInvalidJson() 0 9 1
1
<?php
2
/**
3
 * This file is part of the Gerrie package.
4
 *
5
 * (c) Andreas Grunwald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Gerrie\Tests\API\DataService;
12
13
class DataServiceTestBase extends \PHPUnit_Framework_TestCase
14
{
15
16
    public function testGetterAndSetterName()
17
    {
18
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
19
20
        $name = 'UnitTest Test name';
21
22
        $this->assertNotEmpty($instance->getName());
23
        $instance->setName($name);
24
        $this->assertEquals($name, $instance->getName());
25
    }
26
27
    public function testGetterAndSetterConnector()
28
    {
29
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
30
31
        $dummyConnector = new \stdClass();
32
33
        $instance->setConnector($dummyConnector);
34
        $this->assertEquals($dummyConnector, $instance->getConnector());
35
    }
36
37
    public function testGetterAndSetterConfig()
38
    {
39
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
40
41
        $dummyConfig = [
42
            'key' => 'value',
43
            'hash' => [
44
                'my' => 'map',
45
                'Gerrit' => 'Gerrie',
46
                'HTTP' => 'SSH'
47
            ]
48
        ];
49
50
        $instance->setConfig($dummyConfig);
51
        $this->assertEquals($dummyConfig, $instance->getConfig());
52
    }
53
54
    public function testGetHost()
55
    {
56
        $dummyHost = 'example.com';
57
        $instance = $this->getServiceMock(['host' => $dummyHost]);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
58
59
        $this->assertEquals($dummyHost, $instance->getHost());
60
    }
61
62
    public function testSetterAndGetterQueryLimitWithoutInitialisation()
63
    {
64
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
65
66
        $queryLimit = 1234;
67
        $instance->setQueryLimit($queryLimit);
68
69
        $this->assertInternalType('int', $instance->getQueryLimit());
70
        $this->assertEquals($queryLimit, $instance->getQueryLimit());
71
    }
72
73
    public function testTransformJsonResponseWithValidJson()
74
    {
75
        $json = '{"count":5,"stringVal":"fooBar","smallArray":[5,3,1]}';
76
77
        $jsonResult = [
78
            'count' => 5,
79
            'stringVal' => "fooBar",
80
            'smallArray' => [
81
                5,
82
                3,
83
                1
84
            ]
85
        ];
86
87
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
88
        $response = $instance->transformJsonResponse($json);
89
90
        $this->assertInternalType('array', $response);
91
        $this->assertEquals($jsonResult, $response);
92
    }
93
94
    public function testTransformJsonResponseWithInvalidJson()
95
    {
96
        $json = '{"count":5 "stringVal":"fooBar","smallArray":[5,3,1]}';
97
98
        $instance = $this->getServiceMock();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Gerrie\Tests\API\DataService\DataServiceTestBase as the method getServiceMock() does only exist in the following sub-classes of Gerrie\Tests\API\DataService\DataServiceTestBase: Gerrie\Tests\API\DataService\HTTPDataServiceTest, Gerrie\Tests\API\DataService\SSHDataServiceTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
99
        $response = $instance->transformJsonResponse($json);
100
101
        $this->assertNull($response);
102
    }
103
}