ComparisonTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
getValue() 0 1 ?
A isGreaterThan() 0 4 1
A isLessThan() 0 4 1
A isGreaterThanOrEqualTo() 0 4 1
A isLessThanOrEqualTo() 0 4 1
A spaceship() 0 10 3
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Mathematical\Operator;
4
5
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface;
6
7
/**
8
 * Class ComparisonTrait
9
 *
10
 * @package   BestServedCold\PhalueObjects\Mathematical\Operator
11
 * @author    Adam Lewis <[email protected]>
12
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
13
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
14
 * @link      http://bestservedcold.com
15
 * @since     0.0.1-alpha
16
 * @version   0.0.2-alpha
17
 */
18
trait ComparisonTrait
19
{
20
    /**
21
     * @return int
22
     */
23
    public abstract function getValue();
24
25
    /**
26
     * @param ValueObjectInterface $object
27
     * @return bool
28
     */
29 3
    public function isGreaterThan(ValueObjectInterface $object)
30
    {
31 3
        return $this->getValue() > $object->getValue();
32
    }
33
34
    /**
35
     * @param  ValueObjectInterface $object
36
     * @return bool
37
     */
38 3
    public function isLessThan(ValueObjectInterface $object)
39
    {
40 3
        return $this->getValue() < $object->getValue();
41
    }
42
43
    /**
44
     * @param  ValueObjectInterface $object
45
     * @return bool
46
     */
47 3
    public function isGreaterThanOrEqualTo(ValueObjectInterface $object)
48
    {
49 3
        return $this->getValue() >= $object->getValue();
50
    }
51
52
    /**
53
     * @param  ValueObjectInterface $object
54
     * @return bool
55
     */
56 3
    public function isLessThanOrEqualTo(ValueObjectInterface $object)
57
    {
58 3
        return $this->getValue() <= $object->getValue();
59
    }
60
61
    /**
62
     * @param  ValueObjectInterface $object
63
     * @return int
64
     */
65 1
    public function spaceship(ValueObjectInterface $object)
66
    {
67 1
        return ($this->getValue() < $object->getValue())
68 1
                ? -1
69 1
                : (
70 1
                ($this->getValue() > $object->getValue())
71 1
                    ? 1
72 1
                    : 0
73 1
                );
74
    }
75
}
76