Completed
Push — master ( 5fca22...233410 )
by Emily
01:43
created

ObjectType::equals()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 1
crap 3
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Model\Reflection\Type;
16
17
use Spaark\CompositeUtils\Model\Collection\ListCollection\FlexibleList;
18
use Spaark\CompositeUtils\Model\ClassName;
19
20
/**
21
 * Represents a data type which must be an instance of an object
22
 *
23
 * @property-read string $classname
24
 */
25
class ObjectType extends AbstractType
26
{
27
    /**
28
     * The name of the class this must be an instance of
29
     *
30
     * @readable
31
     * @var ClassName
32
     */
33
    protected $classname;
34
35
    /**
36
     * Creates this ObjectType with the given classname
37
     *
38
     * @param mixed $class The name of the class this must be an
0 ignored issues
show
Bug introduced by
There is no parameter named $class. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
39
     *     instance of
40
     */
41 29
    public function __construct($classname)
42
    {
43 29
        $this->classname = $classname instanceof ClassName
44
            ? $classname
45 29
            : new ClassName($classname);
46 29
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 1
    public function equals($type) : bool
52
    {
53
        if
54
        (
55 1
            $type instanceof ObjectType &&
56 1
            $type->classname->equals($this->classname)
0 ignored issues
show
Documentation introduced by
$this->classname is of type object<Spaark\CompositeUtils\Model\ClassName>, but the function expects a object<self>.

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...
57
        )
58
        {
59 1
            return true;
60
        }
61
62 1
        return false;
63
    }
64
65
    /**
66
     * Returns a string representation of the object
67
     *
68
     * @return string
69
     */
70 21
    public function __toString() : string
71
    {
72 21
        $return = (string)$this->classname;
73
74 21
        return $return;
75
    }
76
}
77