Passed
Push — master ( 9fdafe...783d3e )
by Martin
02:30
created

Query   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAllRemainingTasks() 0 4 1
A getAllCompletedTasks() 0 4 1
A getTaskById() 0 10 2
1
<?php
2
3
namespace Todo\Application\Task;
4
5
use Todo\Domain\Exception\TaskNotFoundException;
6
use Todo\Domain\Repository\TaskRepositoryInterface;
7
use Todo\Domain\Task;
8
9
/**
10
 * Class Query
11
 *
12
 * @category None
13
 * @package  Todo\Application\Task
14
 * @author   Martin Pham <[email protected]>
15
 * @license  None http://
16
 * @link     None
17
 */
18
class Query
19
{
20
    /**
21
     * Task Repository
22
     *
23
     * @var TaskRepositoryInterface
24
     */
25
    protected $taskRepository;
26
27
    /**
28
     * Query constructor
29
     *
30
     * @param TaskRepositoryInterface $taskRepository Task Repository
31
     */
32
    public function __construct(TaskRepositoryInterface $taskRepository)
33
    {
34
        $this->taskRepository = $taskRepository;
35
    }
36
37
    /**
38
     * Get All Remaining Tasks
39
     *
40
     * @return array
41
     */
42
    public function getAllRemainingTasks() : array
43
    {
44
        return $this->taskRepository->findAllByStatus(Task::STATUS_REMAINING);
45
    }
46
47
    /**
48
     * Get All Completed Tasks
49
     *
50
     * @return array
51
     */
52
    public function getAllCompletedTasks() : array
53
    {
54
        return $this->taskRepository->findAllByStatus(Task::STATUS_COMPLETED);
55
    }
56
57
    /**
58
     * Get Task By Id
59
     *
60
     * @param string $taskId Task ID
61
     *
62
     * @return Task
63
     * @throws TaskNotFoundException
64
     */
65
    public function getTaskById($taskId) : Task
66
    {
67
        try {
68
            $task = $this->taskRepository->find($taskId);
69
        } catch (TaskNotFoundException $e) {
70
            throw $e;
71
        }
72
73
        return $task;
74
    }
75
}
76