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

NotificationIsLockedSpecification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isSatisfiedBy() 0 4 1
A whereExpression() 0 9 2
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