MixedTypeTest::testAcceptsNull()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations\Metadata\Type;
6
7
use Doctrine\Annotations\Metadata\Type\MixedType;
8
use Doctrine\Annotations\Metadata\Type\Type;
9
use stdClass;
10
use function fclose;
11
use function fopen;
12
13
final class MixedTypeTest extends TypeTest
14
{
15
    protected function createType() : Type
16
    {
17
        return new MixedType();
18
    }
19
20
    public function testDescribe() : void
21
    {
22
        self::assertSame('mixed', $this->getType()->describe());
23
    }
24
25
    /**
26
     * @return mixed[]
27
     */
28
    public function validValidateValuesProvider() : iterable
29
    {
30
        yield [null];
0 ignored issues
show
Bug Best Practice introduced by
The expression yield array(null) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
31
        yield [true];
32
        yield [123];
33
        yield [1.234];
34
        yield ['hello'];
35
        yield [[123]];
36
        yield [new stdClass()];
37
    }
38
39
    /**
40
     * @return resource[][]
41
     */
42
    public function invalidValidateValuesProvider() : iterable
43
    {
44
        try {
45
            yield [$f = fopen(__FILE__, 'r')];
0 ignored issues
show
Bug Best Practice introduced by
The expression yield array($f = fopen(__FILE__, 'r')) returns the type Generator which is incompatible with the documented return type array<mixed,array<mixed,resource>>.
Loading history...
46
        } finally {
47
            @fclose($f);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for fclose(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

47
            /** @scrutinizer ignore-unhandled */ @fclose($f);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
It seems like $f can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
            @fclose(/** @scrutinizer ignore-type */ $f);
Loading history...
48
        }
49
    }
50
51
    public function testAcceptsNull() : void
52
    {
53
        self::assertTrue($this->getType()->acceptsNull());
54
    }
55
}
56