/
LogicValidation.php
46 lines (37 loc) · 1.31 KB
/
LogicValidation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Service\Validation;
use App\Service\Factory\TimeFactoryInterface;
use App\Value\Day;
use App\Value\Time;
class LogicValidation implements LogicValidationInterface
{
private int $workHoursPerDay;
private int $lunchHoursLength;
private TimeFactoryInterface $timeFactory;
public function __construct(int $workHoursPerDay, int $lunchHoursLength, TimeFactoryInterface $timeFactory)
{
$this->workHoursPerDay = $workHoursPerDay;
$this->lunchHoursLength = $lunchHoursLength;
$this->timeFactory = $timeFactory;
}
public function isDateIntervalCorrect(Day $startDate, Day $endDate): bool
{
if ($startDate->isGreaterThan($endDate)) {
return false;
}
return true;
}
public function isWorkStartTimeCorrect(Time $workStart, Time $lunchStart): bool
{
if ($workStart->isGreaterThan($lunchStart)) {
return false;
}
$endOfDay = $this->timeFactory->createDayEndTime();
$workHoursWithLunch = $this->workHoursPerDay + $this->lunchHoursLength;
$maxPossibleWorkStart = $this->timeFactory->createBySubHoursFromTime($endOfDay, $workHoursWithLunch);
if ($workStart->isGreaterThan($maxPossibleWorkStart)) {
return false;
}
return true;
}
}