Completed
Push — master ( a4e176...8c9478 )
by Adam
02:50
created

Metric::equals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BestServedCold\PhalueObjects\VOArray;
4
5
use BestServedCold\PhalueObjects\VOArray;
6
use BestServedCold\PhalueObjects\Exception\InvalidTypeException;
7
use BestServedCold\PhalueObjects\Contract\ValueObject;
8
9
/**
10
 * Trait Metric
11
 */
12
trait Metric
13
{
14
    /**
15
     * @return int
16
     */
17 4
    public function count()
18
    {
19 4
        return count($this->getValue());
0 ignored issues
show
Bug introduced by
It seems like getValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
20
    }
21
22
    /**
23
     * @return bool
24
     */
25 1
    public function isEmpty()
26
    {
27 1
        return empty($this->value);
0 ignored issues
show
Bug introduced by
The property value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
    }
29
30
    /**
31
     * @param  ValueObject $object
32
     * @return bool
33
     */
34 2
    public function equals(ValueObject $object)
0 ignored issues
show
Coding Style introduced by
function equals() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
35
    {
36 2
        if (! $object instanceof VOArray) {
37 1
            throw new InvalidTypeException($object, [ VOArray::class ]);
38
        }
39
40 1
        return parent::equals($object);
41
    }
42
}
43