GetShift   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A __invoke() 0 21 4
1
<?php
2
3
namespace Scheduler\Application\Service;
4
5
use Aura\Payload\Payload;
6
use Scheduler\Domain\Model\Shift\Shift;
7
use Scheduler\Domain\Model\Shift\ShiftCoworkersFinder;
8
use Scheduler\Domain\Model\Shift\ShiftMapper;
9
10
class GetShift
11
{
12
    private $payload;
13
    private $shiftMapper;
14
    private $shiftCoworkersFinder;
15
16
    public function __construct(
17
        ShiftMapper $shiftMapper,
18
        ShiftCoworkersFinder $shiftCoworkersFinder
19
    ) {
20
        $this->payload = new Payload();
21
        $this->shiftMapper = $shiftMapper;
22
        $this->shiftCoworkersFinder = $shiftCoworkersFinder;
23
    }
24
25
    public function __invoke($currentUser, $shiftId, $withCoworkers)
26
    {
27
        if (! $currentUser->isAuthenticated()) {
28
            return $this->payload->setStatus(Payload::NOT_AUTHENTICATED);
29
        }
30
31
        $shift = $this->shiftMapper->find($shiftId);
32
33
        if ($shift === null) {
34
            return $this->payload->setStatus(Payload::NOT_FOUND);
35
        }
36
37
        if ($withCoworkers) {
38
            $shift = $shift->withCoworkers(
39
                $this->shiftCoworkersFinder->findCoworkersForShift($shift)
40
            );
41
        }
42
43
        return $this->payload->setStatus(Payload::SUCCESS)
44
                             ->setOutput($shift);
45
    }
46
}
47