GetShiftsAssignedToEmployee::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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