From a3a63b69f105e1dc7f80534f16d9171244f58f11 Mon Sep 17 00:00:00 2001 From: Diego Brocanelli Date: Mon, 10 Jun 2019 17:47:12 -0300 Subject: [PATCH] Refactoring the code --- src/Calculate/WorkingDays.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Calculate/WorkingDays.php b/src/Calculate/WorkingDays.php index 54c0a83..55b6a8a 100644 --- a/src/Calculate/WorkingDays.php +++ b/src/Calculate/WorkingDays.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use DateTime; use Exception; +use phpDocumentor\Reflection\Types\Boolean; /** * @author Diego Brocanelli @@ -54,7 +55,7 @@ public function __construct($dateStart, $dateEnd, $holidays = []) */ public function calculate() { - if($this->diff->days == 0 && in_array( $this->dateStart->format('Y-m-d'), $this->holidays )){ + if( $this->checkStartDayIsHoliDay() ){ return $this; } @@ -67,7 +68,8 @@ public function calculate() $weekDay = $this->dateStart->format('w'); $dtAnalize = $this->dateStart->format('Y-m-d'); - if($weekDay == self::SUNDAY || $weekDay == self::SATURDAY || in_array( $dtAnalize, $this->holidays )){ + + if($weekDay == self::SUNDAY || $weekDay == self::SATURDAY || $this->checkHolidayList($dtAnalize) ){ continue; } @@ -103,7 +105,7 @@ public function getDayList() * * @return void */ - private function analyzeTheDay() + private function analyzeTheDay() : void { $weekDay = $this->dateStart->format('w'); if($weekDay != self::SUNDAY && $weekDay != self::SATURDAY){ @@ -111,4 +113,29 @@ private function analyzeTheDay() $this->number += 1; } } + + /** + * Responsible for holiday list check + * + * @param string $day + * @return boolean + */ + private function checkHolidayList($day) : bool + { + return in_array( $day, $this->holidays ); + } + + /** + * Responsible for check the start day is holiday + * + * @return boolean + */ + private function checkStartDayIsHoliDay() : bool + { + if($this->diff->days == 0 && $this->checkHolidayList($this->dateStart->format('Y-m-d') ) ){ + return true; + } + + return false; + } } \ No newline at end of file