GetEmployee::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Scheduler\Application\Service;
4
5
use Aura\Payload\Payload;
6
use Scheduler\Domain\Model\User\NullUser;
7
use Scheduler\Domain\Model\User\User;
8
use Scheduler\Domain\Model\User\UserMapper;
9
10
class GetEmployee
11
{
12
    private $payload;
13
    private $userMapper;
14
15
    public function __construct(UserMapper $userMapper)
16
    {
17
        $this->payload = new Payload();
18
        $this->userMapper = $userMapper;
19
    }
20
21
    public function __invoke(User $currentUser, $employeeId)
22
    {
23
        if (! $currentUser->isAuthenticated()) {
24
            return $this->payload->setStatus(Payload::NOT_AUTHENTICATED);
25
        }
26
27
        $employee = $this->userMapper->find($employeeId);
28
29
        if ($employee === null) {
30
            return $this->payload->setStatus(Payload::NOT_FOUND);
31
        }
32
33
        return $this->payload->setStatus(Payload::SUCCESS)
34
                             ->setOutput($employee);
35
    }
36
}
37