Completed
Push — master ( f66325...242356 )
by Emily
02:14
created

ObjectType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2
ccs 4
cts 4
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B compare() 0 22 6
A equals() 0 4 1
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\ArrayList;
18
19
/**
20
 * Represetns a data type which must be an instance of an object
21
 *
22
 * @property-read string $classname
23
 */
24
class ObjectType extends AbstractType
25
{
26
    /**
27
     * The name of the class this must be an instance of
28
     *
29
     * @readable
30
     * @var string
31
     */
32
    protected $classname;
33
34
    /**
35
     * Generic types for this object
36
     *
37
     * @readable
38
     * @var ArrayList
39
     */
40
    protected $generics;
41
42
    /**
43
     * Creates this ObjectType with the given classname
44
     *
45
     * @param string $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...
46
     *     instance of
47
     */
48 27
    public function __construct(string $classname)
49
    {
50 27
        $this->classname = $classname;
51 27
        $this->generics = new ArrayList();
52 27
    }
53
54
    public function compare($type) : int
55
    {
56
        if
57
        (
58
            $type instanceof ObjectType &&
59
            $type->classname === $this->classname &&
60
            $type->generics->size() <= $this->generics->size()
61
        )
62
        {
63
            foreach ($type->generics as $i => $generic)
64
            {
65
                if (!$this->generics[$i]->compatible($generic))
66
                {
67
                    return -1;
68
                }
69
            }
70
71
            return $this->generics->size() - $type->generics->size();
72
        }
73
74
        return -1;
75
    }
76
77
    public function equals($object) : bool
78
    {
79
        return $this->compare($type) === 0;
0 ignored issues
show
Bug introduced by
The variable $type does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
80
    }
81
}
82