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.

AbstractTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 97
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createImapHelper() 0 9 1
A createImapAdapter() 0 7 1
A createImapExtension() 0 15 1
A createUtil() 0 12 2
A createGuzzleClient() 0 23 1
1
<?php
2
namespace Checkdomain\Comodo\Tests;
3
4
use Checkdomain\Comodo\CommunicationAdapter;
5
use Checkdomain\Comodo\ImapExtension;
6
use Checkdomain\Comodo\ImapHelper;
7
use Checkdomain\Comodo\ImapAdapter;
8
use Checkdomain\Comodo\Model\Account;
9
use Checkdomain\Comodo\Util;
10
use GuzzleHttp\Client;
11
use Psr\Http\Message\ResponseInterface;
12
use Psr\Http\Message\StreamInterface;
13
use Zend\Mail\Storage\Folder;
14
15
/**
16
 * Class AbstractTest
17
 */
18
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapHelper
22
     */
23
    public function createImapHelper()
24
    {
25
        return $this
26
            ->getMockBuilder(ImapHelper::class)
27
            ->disableOriginalConstructor()
28
            ->disableOriginalClone()
29
            ->disableAutoload()
30
            ->getMock();
31
    }
32
33
    /**
34
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapAdapter
35
     */
36
    protected function createImapAdapter()
37
    {
38
        $imapAdapter = new ImapAdapter();
39
        $imapAdapter->setInstance($this->createImapExtension());
0 ignored issues
show
Bug introduced by
It seems like $this->createImapExtension() targeting Checkdomain\Comodo\Tests...::createImapExtension() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\ImapAdapter::setInstance() does only seem to accept object<Checkdomain\Comodo\ImapExtension>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
40
41
        return $imapAdapter;
42
    }
43
44
    /**
45
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapExtension
46
     */
47
    protected function createImapExtension()
48
    {
49
        $imapExtension = $this
50
            ->getMockBuilder(ImapExtension::class)
51
            ->disableOriginalConstructor()
52
            ->disableOriginalClone()
53
            ->getMock();
54
55
        $imapExtension
56
            ->expects($this->any())
57
            ->method('selectFolder')
58
            ->will($this->returnValue(true));
59
60
        return $imapExtension;
61
    }
62
63
    /**
64
     * little helper to create the util class
65
     *
66
     * @param Client $client
67
     *
68
     * @return Util
69
     */
70
    protected function createUtil(Client $client = null)
71
    {
72
        $imapHelper = $this->createImapHelper();
73
        $imapAdapter = $this->createImapAdapter();
74
        $communicationAdapter = new CommunicationAdapter(new Account('test_user', 'test_password'));
75
76
        if ($client != null) {
77
            $communicationAdapter->setClient($client);
78
        }
79
80
        return new Util($communicationAdapter, $imapAdapter, $imapHelper);
0 ignored issues
show
Bug introduced by
It seems like $imapAdapter defined by $this->createImapAdapter() on line 73 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\Util::__construct() does only seem to accept object<Checkdomain\Comodo\ImapAdapter>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $imapHelper defined by $this->createImapHelper() on line 72 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\Util::__construct() does only seem to accept object<Checkdomain\Comodo\ImapHelper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
81
    }
82
83
84
    /**
85
     * Creates a class to simulate Requests, and return response String for testing purposes
86
     *
87
     * @param $responseString
88
     *
89
     * @return \PHPUnit_Framework_MockObject_MockObject|\GuzzleHttp\Client
90
     */
91
    protected function createGuzzleClient($responseString)
92
    {
93
        $client   = $this->getMockBuilder(Client::class)->getMock();
94
        $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
95
        $body     = $this->getMockBuilder(StreamInterface::class)->getMock();
96
97
        $body
98
            ->expects($this->any())
99
            ->method('getContents')
100
            ->will($this->returnValue($responseString));
101
102
        $response
103
            ->expects($this->any())
104
            ->method('getBody')
105
            ->will($this->returnValue($body));
106
107
        $client
108
            ->expects($this->any())
109
            ->method('request')
110
            ->will($this->returnValue($response));
111
112
        return $client;
113
    }
114
}
115