Skip to content

Commit

Permalink
Refactoring the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego-Brocanelli committed Jun 10, 2019
1 parent d8f0c49 commit a3a63b6
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/Calculate/WorkingDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use InvalidArgumentException;
use DateTime;
use Exception;
use phpDocumentor\Reflection\Types\Boolean;

/**
* @author Diego Brocanelli <contato@diegobrocanelli.com.br>
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -103,12 +105,37 @@ public function getDayList()
*
* @return void
*/
private function analyzeTheDay()
private function analyzeTheDay() : void
{
$weekDay = $this->dateStart->format('w');
if($weekDay != self::SUNDAY && $weekDay != self::SATURDAY){
$this->daysList[] = $this->dateStart->format('Y-m-d');
$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;
}
}

0 comments on commit a3a63b6

Please sign in to comment.