Completed
Push — master ( 192638...f858f1 )
by Ivannis Suárez
05:02
created

Value::value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Comparable\Tests\Fixtures;
11
12
use Cubiche\Core\Comparable\ComparableInterface;
13
14
/**
15
 * Comparable Value class.
16
 *
17
 * @author Ivannis Suárez Jerez <[email protected]>
18
 */
19
class Value implements ComparableInterface
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $value;
25
26
    /**
27
     * @param mixed $value
28
     */
29
    public function __construct($value)
30
    {
31
        $this->value = $value;
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37
    public function value()
38
    {
39
        return $this->value;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function compareTo($other)
46
    {
47
        if ($other instanceof self) {
48
            return $this->value() - $other->value();
49
        }
50
51
        if (\is_numeric($other)) {
52
            return $this->compareTo(new self($other));
53
        }
54
55
        throw new \InvalidArgumentException(sprintf(
56
            'Argument "%s" is invalid. Allowed types for argument are "%s" or numeric values.',
57
            $other,
58
            self::class
59
        ));
60
    }
61
}
62