Value   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A value() 0 4 1
A compareTo() 0 16 3
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