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

NotificationIsLockedSpecification::__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\Specification;
7
8
class NotificationIsLockedSpecification extends Specification
9
{
10
    /**
11
     * @var bool
12
     */
13
    private $expectsToBeLocked;
14
15
    /**
16
     * @param bool $expectsToBeLocked
17
     */
18 2
    public function __construct(bool $expectsToBeLocked = true)
19
    {
20 2
        $this->expectsToBeLocked = $expectsToBeLocked;
21 2
    }
22
23
    /**
24
     * @param Notification $notification
25
     * @return bool
26
     */
27
    public function isSatisfiedBy($notification): bool
28
    {
29
        return $this->expectsToBeLocked === $notification->isLocked();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function whereExpression(string $alias): string
36
    {
37 2
        return sprintf(
38 2
            $this->expectsToBeLocked
39 1
                ? '%s.lockedAt IS NOT NULL'
40 2
                : '%s.lockedAt IS NULL',
41 2
            $alias
42
        );
43
    }
44
}
45