Test Failed
Push — master ( faf208...51c6fd )
by Martin
14:25
created

TaskNameIsUniqueSpecification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Todo\Domain\Specification;
4
5
use Todo\Domain\Exception\TaskNotFoundException;
6
use Todo\Domain\Repository\TaskRepositoryInterface;
7
8
/**
9
 * Class TaskNameIsUniqueSpecification
10
 *
11
 * @category None
12
 * @package  Domain\Specification
13
 * @author   Martin Pham <[email protected]>
14
 * @license  None http://
15
 * @link     None
16
 */
17
class TaskNameIsUniqueSpecification
18
{
19
    /**
20
     * TaskRepository
21
     *
22
     * @var TaskRepositoryInterface
23
     */
24
    protected $taskRepository;
25
26
    /**
27
     * TaskNameIsUniqueSpecification constructor
28
     *
29
     * @param TaskRepositoryInterface $taskRepository Task Repository
30
     */
31
    public function __construct(TaskRepositoryInterface $taskRepository)
32
    {
33
        $this->taskRepository = $taskRepository;
34
    }
35
36
    /**
37
     * Is Satisfied By
38
     *
39
     * @param string $name Name
40
     *
41
     * @return bool
42
     */
43
    public function isSatisfiedBy(string $name)
44
    {
45
        try {
46
            $this->taskRepository->findByName($name);
47
        } catch (TaskNotFoundException $e) {
48
            return true;
49
        }
50
51
        return false;
52
53
    }
54
55
56
57
}
58