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 ( 31e25d...aa246b )
by
unknown
01:41
created

AbstractTest::createZendImapStorageFolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
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('selectFolder')
42
            ->will($this->returnValue(true));
43
44
        return $imapExtension;
45
    }
46
47
    /**
48
     * little helper to create the util class
49
     *
50
     * @param Client $client
51
     *
52
     * @return Util
53
     */
54
    protected function createUtil(Client $client = null)
55
    {
56
        $imapHelper = $this->createImapHelper();
57
        $imapAdapter = $this->createImapAdapter();
58
        $communicationAdapter = new CommunicationAdapter(new Account('test_user', 'test_password'));
59
60
        if ($client != null) {
61
            $communicationAdapter->setClient($client);
62
        }
63
64
        return new Util($communicationAdapter, $imapAdapter, $imapHelper);
0 ignored issues
show
Bug introduced by
It seems like $imapAdapter defined by $this->createImapAdapter() on line 57 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 56 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...
65
    }
66
67
    /**
68
     * @return \PHPUnit_Framework_MockObject_MockObject|\Checkdomain\Comodo\ImapHelper
69
     */
70
    public function createImapHelper()
71
    {
72
        return $this
73
            ->getMockBuilder(ImapHelper::class)
74
            ->disableOriginalConstructor()
75
            ->disableOriginalClone()
76
            ->disableAutoload()
77
            ->getMock();
78
    }
79
80
    /**
81
     * Creates a class to simulate Requests, and return response String for testing purposes
82
     *
83
     * @param $responseString
84
     *
85
     * @return \PHPUnit_Framework_MockObject_MockObject|\GuzzleHttp\Client
86
     */
87
    protected function createGuzzleClient($responseString)
88
    {
89
        $client   = $this->getMockBuilder(Client::class)->getMock();
90
        $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
91
        $body     = $this->getMockBuilder(StreamInterface::class)->getMock();
92
93
        $body
94
            ->expects($this->any())
95
            ->method('getContents')
96
            ->will($this->returnValue($responseString));
97
98
        $response
99
            ->expects($this->any())
100
            ->method('getBody')
101
            ->will($this->returnValue($body));
102
103
        $client
104
            ->expects($this->any())
105
            ->method('request')
106
            ->will($this->returnValue($response));
107
108
        return $client;
109
    }
110
}
111