Query   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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
 * Sends query into repository to get Task objects
13
 *
14
 * @category None
15
 * @package  Todo\Application\Task
16
 * @author   Martin Pham <[email protected]>
17
 * @license  None http://
18
 * @link     None
19
 */
20
class Query
21
{
22
    /**
23
     * Task Repository
24
     *
25
     * @var TaskRepositoryInterface
26
     */
27
    protected $taskRepository;
28
29
    /**
30
     * Query constructor
31
     *
32
     * @param TaskRepositoryInterface $taskRepository Task Repository
33
     */
34
    public function __construct(TaskRepositoryInterface $taskRepository)
35
    {
36
        // Inject Task repository
37
        $this->taskRepository = $taskRepository;
38
    }
39
40
    /**
41
     * Get tasks with remaining status
42
     *
43
     * @return array
44
     */
45
    public function getAllRemainingTasks() : array
46
    {
47
        return $this->taskRepository->findAllByStatus(Task::STATUS_REMAINING);
48
    }
49
50
    /**
51
     * Get tasks with completed status
52
     *
53
     * @return array
54
     */
55
    public function getAllCompletedTasks() : array
56
    {
57
        return $this->taskRepository->findAllByStatus(Task::STATUS_COMPLETED);
58
    }
59
60
    /**
61
     * Get task object by Id
62
     *
63
     * @param string $taskId Task ID
64
     *
65
     * @return Task
66
     * @throws TaskNotFoundException
67
     */
68
    public function getTaskById($taskId) : Task
69
    {
70
        try {
71
            $task = $this->taskRepository->find($taskId);
72
        } catch (TaskNotFoundException $e) {
73
            throw $e;
74
        }
75
76
        return $task;
77
    }
78
}
79