Passed
Push — master ( 6afdcd...dc022a )
by Hirofumi
05:03
created

NotificationIsFreshSpecification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use Tanigami\Specification\AnyOfSpecification;
7
use Tanigami\Specification\OneOfSpecification;
8
use Tanigami\Specification\Specification;
9
10
class NotificationIsFreshSpecification extends Specification
11
{
12
    /**
13
     * @var bool
14
     */
15
    private $expectsToBeFresh;
16
17
    /**
18
     * @param bool $expectsToBeFresh
19
     */
20 4
    public function __construct(bool $expectsToBeFresh = true)
21
    {
22 4
        $this->expectsToBeFresh = $expectsToBeFresh;
23 4
    }
24
25
    /**
26
     * @param Notification $notification
27
     * @return bool
28
     */
29 4
    public function isSatisfiedBy($notification): bool
30
    {
31 4
        return $this->expectsToBeFresh === $notification->isFresh();
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function whereExpression(string $alias): string
38
    {
39
        $specifications = [
40 2
            new NotificationIsLockedSpecification(!$this->expectsToBeFresh),
41 2
            new NotificationIsFailedSpecification(!$this->expectsToBeFresh),
42 2
            new NotificationIsSentSpecification(!$this->expectsToBeFresh),
43
        ];
44 2
        $composite = $this->expectsToBeFresh
45 1
            ? new AnyOfSpecification(...$specifications)
46 2
            : new OneOfSpecification(...$specifications);
47
48 2
        return $composite->whereExpression($alias);
49
    }
50
}
51