Completed
Pull Request — master (#327)
by
unknown
02:16
created

DateTimeDeltaToken::isLast()   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
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Prophecy\Argument\Token;
4
5
6
class DateTimeDeltaToken implements TokenInterface
7
{
8
    /** @var \DateTime */
9
    private $value;
10
    /** @var integer */
11
    private $delta;
12
13
    public function __construct(\DateTime $value, $delta)
14
    {
15
        $this->value = $value;
16
        $this->delta = $delta;
17
    }
18
19
    /**
20
     * Calculates token match score for provided argument.
21
     *
22
     * @param $argument
23
     *
24
     * @return bool|int
25
     */
26
    public function scoreArgument($argument)
27
    {
28
        if (!$argument instanceof \DateTime) {
29
            return false;
30
        }
31
32
        return abs($argument->getTimestamp() - $this->value->getTimestamp()) < $this->delta;
33
    }
34
35
    /**
36
     * Returns true if this token prevents check of other tokens (is last one).
37
     *
38
     * @return bool|int
39
     */
40
    public function isLast()
41
    {
42
        return false;
43
    }
44
45
    /**
46
     * Returns string representation for token.
47
     *
48
     * @return string
49
     */
50
    public function __toString()
51
    {
52
        return sprintf('Date{%s}~%d', $this->value->format('Y-m-d H:i:s'), $this->delta);
53
    }
54
}