GetShiftsAssignedToEmployee   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 20 4
1
<?php
2
3
namespace Scheduler\Application\Service;
4
5
use Aura\Payload\Payload;
6
use Scheduler\Domain\Model\Shift\ShiftMapper;
7
use Scheduler\Domain\Model\User\User;
8
9
class GetShiftsAssignedToEmployee
10
{
11
    const INVALID_ID_MESSAGE = "must be a valid employee id";
12
13
    private $payload;
14
    private $shiftMapper;
15
16
    public function __construct(ShiftMapper $shiftMapper)
17
    {
18
        $this->payload = new Payload();
19
        $this->shiftMapper = $shiftMapper;
20
    }
21
22
    public function __invoke(User $currentUser, $employeeId)
23
    {
24
        if (! $currentUser->isAuthenticated()) {
25
            return $this->payload->setStatus(Payload::NOT_AUTHENTICATED);
26
        }
27
28
        if (! is_integer($employeeId)) {
29
            return $this->payload->setStatus(Payload::NOT_VALID)
30
                                 ->setMessages(["employee_id" => self::INVALID_ID_MESSAGE]);
31
        }
32
33
        if ($currentUser->getId() !== $employeeId) {
34
            return $this->payload->setStatus(Payload::NOT_AUTHORIZED);
35
        }
36
37
        $shifts = $this->shiftMapper->findShiftsByEmployeeId($currentUser->getId());
38
39
        return $this->payload->setStatus(Payload::SUCCESS)
40
                             ->setOutput($shifts);
41
    }
42
}
43