Completed
Push — master ( 50437b...6d2b5a )
by Adam
02:31
created

VOInteger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 39
c 1
b 0
f 0
wmc 5
lcom 1
cbo 3
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getValue() 0 4 1
A count() 0 4 1
A diff() 0 4 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects;
4
5
use BestServedCold\PhalueObjects\Contract\Diffable;
6
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface;
7
use BestServedCold\PhalueObjects\Exception\InvalidTypeException;
8
9
/**
10
 * Class VOInteger
11
 *
12
 * @package   BestServedCold\PhalueObjects\Mathematical
13
 * @author    Adam Lewis <[email protected]>
14
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
15
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
16
 * @link      http://bestservedcold.com
17
 * @since     0.0.1-alpha
18
 * @version   0.0.2-alpha
19
 */
20
class VOInteger extends ValueObject implements \Countable, Diffable
21
{
22
    /**
23
     * @param $value
24
     */
25
    public function __construct($value)
26
    {
27
        if (!is_int($value)) {
28
            throw new InvalidTypeException($value, [ 'integer' ]);
29
        }
30
31
        parent::__construct($value);
32
    }
33
34
    /**
35
     * @return integer
36
     */
37
    public function getValue()
38
    {
39
        return (integer) parent::getValue();
40
    }
41
42
    /**
43
     * @return integer
44
     */
45
    public function count()
46
    {
47
        return $this->getValue();
48
    }
49
50
    /**
51
     * @param  ValueObjectInterface $object
52
     * @return static
53
     */
54
    public function diff(ValueObjectInterface $object)
55
    {
56
        return new static($this->getValue() - $object->getValue());
57
    }
58
}
59