ShiftCoworkersFinder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Scheduler\Domain\Model\Shift;
4
5
use Scheduler\Domain\Model\Shift\Shift;
6
use Scheduler\Domain\Model\Shift\ShiftMapper;
7
8
class ShiftCoworkersFinder
9
{
10
    private $shiftMapper;
11
12
    public function __construct(ShiftMapper $shiftMapper)
13
    {
14
        $this->shiftMapper = $shiftMapper;
15
    }
16
17
    public function findCoworkersForShift(Shift $shift)
18
    {
19
        $shifts = $this->shiftMapper->findShiftsInTimePeriod(
20
            $shift->getStartTime(),
21
            $shift->getEndTime()
22
        );
23
24
        $employee = $shift->getEmployee();
25
26
        $shifts = array_filter($shifts, function ($shift) use ($employee) {
27
            return $shift->getEmployee()->getId() !== $employee->getId();
28
        });
29
30
        $coworkers = array_map(function ($shift) {
31
            return $shift->getEmployee();
32
        }, $shifts);
33
34
        return array_values($coworkers);
35
    }
36
}
37