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

VOInteger::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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