Completed
Push — master ( 478e09...9c084b )
by Konstantin
05:55 queued 03:57
created

ApproximateValueToken::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Prophecy.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *     Marcello Duarte <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Prophecy\Argument\Token;
13
14
/**
15
 * Approximate value token
16
 *
17
 * @author Daniel Leech <[email protected]>
18
 */
19
class ApproximateValueToken implements TokenInterface
20
{
21
    private $value;
22
    private $precision;
23
24
    public function __construct($value, $precision = 0)
25
    {
26
        $this->value = $value;
27
        $this->precision = $precision;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function scoreArgument($argument)
34
    {
35
        return round($argument, $this->precision) === round($this->value, $this->precision) ? 10 : false;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function isLast()
42
    {
43
        return false;
44
    }
45
46
    /**
47
     * Returns string representation for token.
48
     *
49
     * @return string
50
     */
51
    public function __toString()
52
    {
53
        return sprintf('≅%s', round($this->value, $this->precision));
54
    }
55
}
56