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
Pull Request — master (#3)
by Kevin
05:09
created

AbstractTest::createImapAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapAdapter
19
     */
20
    protected function createImapAdapter()
21
    {
22
        $imapAdapter = new ImapAdapter();
23
        $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...
24
25
        return $imapAdapter;
26
    }
27
28
    /**
29
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapExtension
30
     */
31
    protected function createImapExtension()
32
    {
33
        $imapExtension = $this
34
            ->getMockBuilder(ImapExtension::class)
35
            ->disableOriginalConstructor()
36
            ->disableOriginalClone()
37
            ->getMock();
38
39
        $imapExtension
40
            ->expects($this->any())
41
            ->method('getFolders')
42
            ->will($this->returnValue([$this->createZendImapStorageFolder()]));
43
44
        $imapExtension
45
            ->expects($this->any())
46
            ->method('selectFolder')
47
            ->will($this->returnValue(true));
48
49
        return $imapExtension;
50
    }
51
52
    /**
53
     * @return \PHPUnit_Framework_MockObject_MockObject|\Zend\Mail\Storage\Folder
54
     */
55
    protected function createZendImapStorageFolder()
56
    {
57
        return $this
58
            ->getMockBuilder(Folder::class)
59
            ->setConstructorArgs(['INBOX'])
60
            ->disableOriginalConstructor()
61
            ->disableOriginalClone()
62
            ->getMock();
63
    }
64
65
    /**
66
     * little helper to create the util class
67
     *
68
     * @param Client $client
69
     *
70
     * @return Util
71
     */
72
    protected function createUtil(Client $client = null)
73
    {
74
        $imapHelper = $this->createImapHelper();
75
        $imapAdapter = $this->createImapAdapter();
76
        $communicationAdapter = new CommunicationAdapter(new Account('test_user', 'test_password'));
77
78
        if ($client != null) {
79
            $communicationAdapter->setClient($client);
80
        }
81
82
        return new Util($communicationAdapter, $imapAdapter, $imapHelper);
0 ignored issues
show
Bug introduced by
It seems like $imapAdapter defined by $this->createImapAdapter() on line 75 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 74 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...
83
    }
84
85
    /**
86
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapHelper
87
     */
88
    public function createImapHelper()
89
    {
90
        return $this
91
            ->getMockBuilder(ImapHelper::class)
92
            ->disableOriginalConstructor()
93
            ->disableOriginalClone()
94
            ->disableAutoload()
95
            ->getMock();
96
    }
97
98
    /**
99
     * Creates a class to simulate Requests, and return response String for testing purposes
100
     *
101
     * @param $responseString
102
     *
103
     * @return \PHPUnit_Framework_MockObject_MockObject|\GuzzleHttp\Client
104
     */
105
    protected function createGuzzleClient($responseString)
106
    {
107
        $client   = $this->createMock(Client::class);
108
        $response = $this->createMock(ResponseInterface::class);
109
        $body     = $this->createMock(StreamInterface::class);
110
111
        $body
112
            ->expects($this->any())
113
            ->method('getContents')
114
            ->will($this->returnValue($responseString));
115
116
        $response
117
            ->expects($this->any())
118
            ->method('getBody')
119
            ->will($this->returnValue($body));
120
121
        $client
122
            ->expects($this->any())
123
            ->method('request')
124
            ->will($this->returnValue($response));
125
126
        return $client;
127
    }
128
}
129