checkdomain /
Comodo
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Checkdomain\Comodo\Tests; |
||
| 3 | |||
| 4 | use Checkdomain\Comodo\ImapExtension; |
||
| 5 | use Checkdomain\Comodo\ImapHelper; |
||
| 6 | use Zend\Mail\Storage\Message; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class ImapHelperTest |
||
| 10 | */ |
||
| 11 | class ImapHelperTest extends AbstractTest |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var ImapHelper |
||
| 15 | */ |
||
| 16 | private $imapHelper; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | private $messages = []; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $name |
||
| 25 | * @param array $data |
||
| 26 | * @param string $dataName |
||
| 27 | */ |
||
| 28 | public function __construct($name = null, array $data = [], $dataName = '') |
||
| 29 | { |
||
| 30 | parent::__construct($name, $data, $dataName); |
||
| 31 | |||
| 32 | $this->imapHelper = new ImapHelper(); |
||
| 33 | $this->messages = json_decode(file_get_contents(__DIR__.'/data/messages/messages.json'), true); |
||
|
0 ignored issues
–
show
|
|||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * @param int $messageId |
||
| 39 | * |
||
| 40 | * @return \PHPUnit_Framework_MockObject_MockObject|\Zend\Mail\Storage\Message |
||
| 41 | */ |
||
| 42 | public function createImapStorageMessage($messageId) |
||
| 43 | { |
||
| 44 | $messageData = $this->messages[$messageId]; |
||
| 45 | |||
| 46 | $message = $this |
||
| 47 | ->getMockBuilder(Message::class) |
||
| 48 | ->disableOriginalConstructor() |
||
| 49 | ->disableOriginalClone() |
||
| 50 | ->getMock(); |
||
| 51 | |||
| 52 | $message |
||
| 53 | ->expects($this->any()) |
||
| 54 | ->method('getHeader') |
||
| 55 | ->will($this->returnCallback(function ($index, $type) use ($messageData) { |
||
| 56 | if ($type != 'string') { |
||
| 57 | return null; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($index == 'subject') { |
||
| 61 | return utf8_encode($messageData[$index]); |
||
| 62 | } |
||
| 63 | |||
| 64 | return $messageData[$index]; |
||
| 65 | })); |
||
| 66 | |||
| 67 | $message |
||
| 68 | ->expects($this->any()) |
||
| 69 | ->method('isMultipart') |
||
| 70 | ->will($this->returnValue(false)); |
||
| 71 | |||
| 72 | $message |
||
| 73 | ->expects($this->any()) |
||
| 74 | ->method('getContent') |
||
| 75 | ->will($this->returnValue($this->messages[$messageId]['plainText'])); |
||
| 76 | |||
| 77 | $message |
||
| 78 | ->expects($this->any()) |
||
| 79 | ->method('getHeaderField') |
||
| 80 | ->will($this->returnValue('text/plain')) |
||
| 81 | ->with($this->equalTo('Content-Type')); |
||
| 82 | |||
| 83 | return $message; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * This test is only for validating correct decoding of the message (subject/plaintext/received) |
||
| 88 | */ |
||
| 89 | public function testMailParse() |
||
| 90 | { |
||
| 91 | $imapAdapter = $this->createImapAdapter(); |
||
| 92 | |||
| 93 | /** @var \PHPUnit_Framework_MockObject_MockObject|ImapExtension $imapExtension */ |
||
| 94 | $imapExtension = $imapAdapter->getInstance(); |
||
|
0 ignored issues
–
show
The method
getInstance does only exist in Checkdomain\Comodo\ImapAdapter, but not in PHPUnit_Framework_MockObject_MockObject.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 95 | |||
| 96 | $imapExtension |
||
|
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Checkdomain\Comodo\ImapExtension.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 97 | ->expects($this->any()) |
||
| 98 | ->method('search') |
||
| 99 | ->will($this->returnValue([0])); |
||
| 100 | |||
| 101 | $imapExtension |
||
| 102 | ->expects($this->any()) |
||
| 103 | ->method('getMessage') |
||
| 104 | ->will($this->returnValue($this->createImapRawMessage( |
||
| 105 | base64_decode(file_get_contents(__DIR__.'/data/messages/raw/multipart')) |
||
| 106 | ))); |
||
| 107 | |||
| 108 | $messages = $this->imapHelper->fetchMails($imapAdapter, null, true, true); |
||
|
0 ignored issues
–
show
It seems like
$imapAdapter defined by $this->createImapAdapter() on line 91 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\ImapHelper::fetchMails() 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...
|
|||
| 109 | $message = $messages[0]; |
||
| 110 | |||
| 111 | $this->assertEquals('ORDER #12345678 - CONFIRMATION', $message['subject']); |
||
| 112 | $this->assertEquals(1404914391, $message['received']); |
||
| 113 | $this->assertEquals('test'.chr(10).chr(10), $message['plainText']); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * This test is only for validating correct decoding of the attachments |
||
| 118 | */ |
||
| 119 | public function testMailAttachmentParse() |
||
| 120 | { |
||
| 121 | $imapAdapter = $this->createImapAdapter(); |
||
| 122 | |||
| 123 | /** @var \PHPUnit_Framework_MockObject_MockObject|ImapExtension $imapExtension */ |
||
| 124 | $imapExtension = $imapAdapter->getInstance(); |
||
|
0 ignored issues
–
show
The method
getInstance does only exist in Checkdomain\Comodo\ImapAdapter, but not in PHPUnit_Framework_MockObject_MockObject.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 125 | |||
| 126 | $imapExtension |
||
|
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Checkdomain\Comodo\ImapExtension.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 127 | ->expects($this->any()) |
||
| 128 | ->method('search') |
||
| 129 | ->will($this->returnValue([0])); |
||
| 130 | |||
| 131 | $imapExtension |
||
| 132 | ->expects($this->any()) |
||
| 133 | ->method('getMessage') |
||
| 134 | ->will($this->returnValue($this->createImapRawMessage( |
||
| 135 | base64_decode(file_get_contents(__DIR__.'/data/messages/raw/with-attachment')) |
||
| 136 | ))); |
||
| 137 | |||
| 138 | $messages = $this->imapHelper->fetchMails($imapAdapter, null, true, true); |
||
|
0 ignored issues
–
show
It seems like
$imapAdapter defined by $this->createImapAdapter() on line 121 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\ImapHelper::fetchMails() 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...
|
|||
| 139 | $attachment = $messages[0]['attachments'][0]; |
||
| 140 | |||
| 141 | $this->assertEquals('application/x-zip-compressed', $attachment['mime']); |
||
| 142 | $this->assertEquals('finaltest_tobias-nitsche_de.zip', $attachment['filename']); |
||
| 143 | $this->assertEquals(3962, strlen($attachment['content'])); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * test for assuming domain names and ordernumbersof email |
||
| 148 | */ |
||
| 149 | public function testMailAssume() |
||
| 150 | { |
||
| 151 | $asserts = array_map(function ($message) { |
||
| 152 | static $i = 0; |
||
| 153 | |||
| 154 | return [ |
||
| 155 | 'id' => $i++, |
||
| 156 | 'folder' => 'INBOX', |
||
| 157 | 'subject' => $message['subject'], |
||
| 158 | 'received' => strtotime($message['date']), |
||
| 159 | 'plainText' => $message['plainText'], |
||
| 160 | 'attachments' => null, |
||
| 161 | 'type' => $message['type'], |
||
| 162 | 'domainName' => $message['domainName'], |
||
| 163 | 'orderNumber' => $message['orderNumber'], |
||
| 164 | ]; |
||
| 165 | }, $this->messages); |
||
| 166 | |||
| 167 | $imapAdapter = $this->createImapAdapter(); |
||
| 168 | |||
| 169 | $imapAdapter |
||
|
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Checkdomain\Comodo\ImapAdapter.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 170 | ->expects($this->any()) |
||
| 171 | ->method('search') |
||
| 172 | ->will($this->returnValue(array_keys($this->messages))); |
||
| 173 | |||
| 174 | $imapAdapter |
||
| 175 | ->expects($this->any()) |
||
| 176 | ->method('getMessage') |
||
| 177 | ->will($this->returnCallback(function ($id) { |
||
| 178 | return $this->createImapStorageMessage($id); |
||
| 179 | })); |
||
| 180 | |||
| 181 | |||
| 182 | $messages = $this->imapHelper->fetchMails($imapAdapter, [], true, true); |
||
|
0 ignored issues
–
show
It seems like
$imapAdapter defined by $this->createImapAdapter() on line 167 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Checkdomain\Comodo\ImapHelper::fetchMails() 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...
array() is of type array, but the function expects a string.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 183 | |||
| 184 | $this->assertEquals($asserts, $messages); |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $raw |
||
| 189 | * |
||
| 190 | * @return Message |
||
| 191 | */ |
||
| 192 | protected function createImapRawMessage($raw) |
||
| 193 | { |
||
| 194 | return new Message(['raw' => $raw]); |
||
| 195 | } |
||
| 196 | } |
||
| 197 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..