ShiftCoworkersFinder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findCoworkersForShift() 0 19 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