From 2c080136cf727628d997fa4865e8ec0d38bc1d5e Mon Sep 17 00:00:00 2001 From: Jan Galek Date: Fri, 13 Apr 2018 08:58:15 +0200 Subject: [PATCH] coding standard coding standard coding standard coding standard Used: validators Fixing bug Fixing bug Fixing bug --- .../Utils/Calendar/Business/IShipper.php | 4 +- src/Galek/Utils/Calendar/Business/Shipper.php | 4 +- src/Galek/Utils/Calendar/Business/Work.php | 6 +- src/Galek/Utils/Calendar/Calendar.php | 1060 ++++++++--------- .../Calendar/Configuration/Configurator.php | 2 +- .../Calendar/Configuration/Localization.php | 2 +- .../Utils/Calendar/Configuration/Shippers.php | 2 +- src/Galek/Utils/Calendar/DI/Extension.php | 2 +- src/Galek/Utils/Calendar/DI/TExtension.php | 39 +- src/Galek/Utils/Calendar/Day.php | 2 +- src/Galek/Utils/Calendar/EasterHoliday.php | 14 +- src/Galek/Utils/Calendar/Enum/Country.php | 2 +- .../Calendar/Enum/CountryLocalization.php | 2 +- .../Utils/Calendar/Enum/Localization.php | 2 +- .../Exceptions/InvalidHourException.php | 2 +- .../Exceptions/InvalidMinuteException.php | 2 +- src/Galek/Utils/Calendar/Holidays.php | 2 +- src/Galek/Utils/Calendar/Localization.php | 4 +- src/Galek/Utils/Calendar/Time.php | 2 +- .../Calendar/Validators/CountryValidator.php | 4 +- .../Calendar/Validators/HourValidator.php | 2 +- .../Utils/Calendar/Validators/IValidator.php | 2 +- .../Validators/LocalizationValidator.php | 4 +- .../Calendar/Validators/MinuteValidator.php | 4 +- tests/CalendarTests/Exceptions.phpt | 8 +- 25 files changed, 565 insertions(+), 614 deletions(-) diff --git a/src/Galek/Utils/Calendar/Business/IShipper.php b/src/Galek/Utils/Calendar/Business/IShipper.php index e7efe39..b50dd03 100644 --- a/src/Galek/Utils/Calendar/Business/IShipper.php +++ b/src/Galek/Utils/Calendar/Business/IShipper.php @@ -4,7 +4,7 @@ * User: Galek * Date: 4.4.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Business; @@ -14,7 +14,7 @@ interface IShipper { - public function getName(): string ; + public function getName(): string; public function getCurrentDate(): Calendar; diff --git a/src/Galek/Utils/Calendar/Business/Shipper.php b/src/Galek/Utils/Calendar/Business/Shipper.php index 6dc59d6..b280421 100644 --- a/src/Galek/Utils/Calendar/Business/Shipper.php +++ b/src/Galek/Utils/Calendar/Business/Shipper.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Business; @@ -124,7 +124,7 @@ public function getDeliveryTextDate(string $format = 'Y.m.d'): string $at = $local->getAt($dayNumber); $day = $local->getInflexion($dayNumber, 4); - return $at . ' ' . $day . ' ' .$date->format($format); + return $at . ' ' . $day . ' ' . $date->format($format); } diff --git a/src/Galek/Utils/Calendar/Business/Work.php b/src/Galek/Utils/Calendar/Business/Work.php index 54a628e..82ce977 100644 --- a/src/Galek/Utils/Calendar/Business/Work.php +++ b/src/Galek/Utils/Calendar/Business/Work.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Business; @@ -29,8 +29,8 @@ public function __construct(Localization $localization, array $settings) { $startHour = $settings['start']['hour']; $startMinute = $settings['start']['minute']; - $endHour = $settings['start']['hour']; - $endMinute = $settings['start']['minute']; + $endHour = $settings['end']['hour']; + $endMinute = $settings['end']['minute']; HourValidator::validate($startHour); MinuteValidator::validate($startMinute); HourValidator::validate($endHour); diff --git a/src/Galek/Utils/Calendar/Calendar.php b/src/Galek/Utils/Calendar/Calendar.php index bf27481..bdf195c 100644 --- a/src/Galek/Utils/Calendar/Calendar.php +++ b/src/Galek/Utils/Calendar/Calendar.php @@ -1,10 +1,12 @@ '16', 'minute' => '30' - ]; + private $shipping_time = [ + 'hour' => '16', 'minute' => '30' + ]; - private $shippingWeekend = false; + private $shippingWeekend = false; - const WORKTIME_START = 1, - WORKTIME_END = 2; + const WORKTIME_START = 1, + WORKTIME_END = 2; /** * @var Localization @@ -49,17 +51,17 @@ class Calendar extends DateTime /** - * @param string $time [optional] - * @param $object [optional] + * @param string $time [optional] + * @param $object [optional] * @param $configuration Localization - */ - public function __construct($time = 'now', $object = null, Localization $configuration = null) - { - parent::__construct($time, $object); + */ + public function __construct($time = 'now', $object = null, Localization $configuration = null) + { + parent::__construct($time, $object); - if (null === $this->date) { - $this->date = new \DateTime(); - } + if (null === $this->date) { + $this->date = new \DateTime(); + } $this->configuration = $configuration ?? new Localization(); } @@ -95,201 +97,201 @@ public function getLocalization() * @param int */ public function setShippingDays($shippingtime): void - { - $this->shippingtime = (int) $shippingtime; + { + $this->shippingtime = (int) $shippingtime; } - public function setYear($year): void - { - $this->setDate($year, $this->getMonth(), $this->getDay()); - } + public function setYear($year): void + { + $this->setDate($year, $this->getMonth(), $this->getDay()); + } public function setMonth($month): void - { - $this->setDate($this->getYear(), $month, $this->getDay()); - } + { + $this->setDate($this->getYear(), $month, $this->getDay()); + } - public function setDay($day): void - { - $this->setDate($this->getYear(), $this->getMonth(), $day); - } + public function setDay($day): void + { + $this->setDate($this->getYear(), $this->getMonth(), $day); + } /** * Get number of days to delivery * @return int */ public function getShippingDays(): int - { - return $this->shippingtime; - } - - /** - * Get Day - * @return int - */ - public function getDay(): int - { - return (int) $this->format('d'); - } - - /** - * Get Month - * @return int - */ - public function getMon(): int - { - return (int) $this->format('m'); - } - - /** - * Get Month - * @return int - */ - public function getMonth(): int - { - return $this->getMon(); - } - - /** - * Get Year - * @return int - */ - public function getYear(): int - { - return (int) $this->format('Y'); - } - - /** - * Get Hour - * @return int - */ - public function getHour(): int - { - return (int) $this->format('G'); - } - - /** - * Get Minute - * @return int - */ - public function getMinute(): int - { - return (int) $this->format('i'); - } - - /** - * Get time Second - * @return int - */ - public function getSecond(): int - { - return (int) $this->format('s'); - } - - /** - * Check Weekend - * @return bool - */ - public function isWeekend(): bool - { + { + return $this->shippingtime; + } + + /** + * Get Day + * @return int + */ + public function getDay(): int + { + return (int) $this->format('d'); + } + + /** + * Get Month + * @return int + */ + public function getMon(): int + { + return (int) $this->format('m'); + } + + /** + * Get Month + * @return int + */ + public function getMonth(): int + { + return $this->getMon(); + } + + /** + * Get Year + * @return int + */ + public function getYear(): int + { + return (int) $this->format('Y'); + } + + /** + * Get Hour + * @return int + */ + public function getHour(): int + { + return (int) $this->format('G'); + } + + /** + * Get Minute + * @return int + */ + public function getMinute(): int + { + return (int) $this->format('i'); + } + + /** + * Get time Second + * @return int + */ + public function getSecond(): int + { + return (int) $this->format('s'); + } + + /** + * Check Weekend + * @return bool + */ + public function isWeekend(): bool + { return Day::isWeekend($this); - } - - /** - * Check Weekday - * @return bool - */ - public function isWeekday(): bool - { + } + + /** + * Check Weekday + * @return bool + */ + public function isWeekday(): bool + { return Day::isWeek($this); - } - - /** - * Check Monday - * @return bool - */ - public function isMonday(): bool - { + } + + /** + * Check Monday + * @return bool + */ + public function isMonday(): bool + { return Day::isMonday($this); - } - - /** - * Check Tuesday - * @return bool - */ - public function isTuesday(): bool - { + } + + /** + * Check Tuesday + * @return bool + */ + public function isTuesday(): bool + { return Day::isTuesday($this); - } - - /** - * Check Wednesday - * @return bool - */ - public function isWednesday(): bool - { + } + + /** + * Check Wednesday + * @return bool + */ + public function isWednesday(): bool + { return Day::isWednesday($this); - } - - /** - * Check Thursday - * @return bool - */ - public function isThursday(): bool - { + } + + /** + * Check Thursday + * @return bool + */ + public function isThursday(): bool + { return Day::isThursday($this); - } - - /** - * Check Friday - * @return bool - */ - public function isFriday(): bool - { + } + + /** + * Check Friday + * @return bool + */ + public function isFriday(): bool + { return Day::isFriday($this); - } - - /** - * Check Saturday - * @return bool - */ - public function isSaturday(): bool - { - return Day::isSaturday($this); - } - - /** - * Check Sunday - * @return bool - */ - public function isSunday(): bool - { + } + + /** + * Check Saturday + * @return bool + */ + public function isSaturday(): bool + { + return Day::isSaturday($this); + } + + /** + * Check Sunday + * @return bool + */ + public function isSunday(): bool + { return Day::isSunday($this); - } + } - public function isWorkTime(): bool - { - if ($this->isWorkDay()) { - $startTime = $this->getWorkTime(1); - $endTime = $this->getWorkTime(2); - return $this->timeBetween((int) $startTime[0], (int) $startTime[1], (int) $endTime[0], (int) $endTime[1]); - } + public function isWorkTime(): bool + { + if ($this->isWorkDay()) { + $startTime = $this->getWorkTime(1); + $endTime = $this->getWorkTime(2); + return $this->timeBetween((int) $startTime[0], (int) $startTime[1], (int) $endTime[0], (int) $endTime[1]); + } - return false; - } + return false; + } - /** - * Check Holiday - * @return bool - */ - public function isHoliday(): bool - { - return $this->getHolidays()->isHoliday($this); - } + /** + * Check Holiday + * @return bool + */ + public function isHoliday(): bool + { + return $this->getHolidays()->isHoliday($this); + } /** @@ -297,114 +299,114 @@ public function isHoliday(): bool * @param \DateTime|null $date * @return bool */ - public function isWorkDay(\DateTime $date = null): bool - { - return Day::isWork($this->configuration->getHolidays(), $date ?: $this); - } - - - public function getDaysInMonth(int $year, int $month) - { - return cal_days_in_month(CAL_GREGORIAN, $month, $year); - } - - - public function getWorkDayNumberInMonth(int $month, int $year) - { - return $this->getWorkDayNumberInMonthTo($month, $year, $this->getDaysInMonth($year, $month)); - } - - - public function getWorkDayNumberInMonthTo(int $month, int $year, int $day): int - { - $dayCount = $this->getDaysInMonth($year, $month); - if ($day > $dayCount) { - $day = $dayCount; - } - - $date = new Calendar(); - $date->setDate($year, $month, 1); - - $number = 0; - - for ($i = 1; $i <= $day; $i++) { - $date->setDay($i); - if ($date->isWorkDay()) { - $number++; - } - } - - return $number; - } - - /** - * Check Time bellow - * @param int $hour - * @param int $minute format: 1,2,3,..9,10,... - * @return boolean - */ - public function timeBellow(int $hour, int $minute = 0): bool - { - return Time::bellow($this, $hour, $minute); - } - - /** - * Check Time over - * @param int $hour - * @param int $minute - * @return bool - */ - public function timeOver(int $hour, int $minute = 0): bool - { - return Time::over($this, $hour, $minute); - } - - /** - * @param int $firstHour - * @param int $firstMinute - * @param int $lastHour - * @param int $lastMinute - * @return bool - */ - public function timeBetween(int $firstHour, int $firstMinute, int $lastHour, int $lastMinute): bool - { - return Time::between($this, $firstHour, $firstMinute, $lastHour, $lastMinute); - } - - - public function dayNumber(): int - { - return (int) $this->format('w'); - } - - /** + public function isWorkDay(\DateTime $date = null): bool + { + return Day::isWork($this->configuration->getHolidays(), $date ?: $this); + } + + + public function getDaysInMonth(int $year, int $month) + { + return cal_days_in_month(CAL_GREGORIAN, $month, $year); + } + + + public function getWorkDayNumberInMonth(int $month, int $year) + { + return $this->getWorkDayNumberInMonthTo($month, $year, $this->getDaysInMonth($year, $month)); + } + + + public function getWorkDayNumberInMonthTo(int $month, int $year, int $day): int + { + $dayCount = $this->getDaysInMonth($year, $month); + if ($day > $dayCount) { + $day = $dayCount; + } + + $date = new Calendar(); + $date->setDate($year, $month, 1); + + $number = 0; + + for ($i = 1; $i <= $day; $i++) { + $date->setDay($i); + if ($date->isWorkDay()) { + $number++; + } + } + + return $number; + } + + /** + * Check Time bellow + * @param int $hour + * @param int $minute format: 1,2,3,..9,10,... + * @return boolean + */ + public function timeBellow(int $hour, int $minute = 0): bool + { + return Time::bellow($this, $hour, $minute); + } + + /** + * Check Time over + * @param int $hour + * @param int $minute + * @return bool + */ + public function timeOver(int $hour, int $minute = 0): bool + { + return Time::over($this, $hour, $minute); + } + + /** + * @param int $firstHour + * @param int $firstMinute + * @param int $lastHour + * @param int $lastMinute + * @return bool + */ + public function timeBetween(int $firstHour, int $firstMinute, int $lastHour, int $lastMinute): bool + { + return Time::between($this, $firstHour, $firstMinute, $lastHour, $lastMinute); + } + + + public function dayNumber(): int + { + return (int) $this->format('w'); + } + + /** * Get format date d.m.Y * @return string */ - public function getDateFormat(): string - { - return $this->format('d.m.Y'); - } + public function getDateFormat(): string + { + return $this->format('d.m.Y'); + } - /** - * Get format date d.m.Y H:i:s - * @return string - */ - public function getDateTimeFormat(): string - { - return $this->format('d.m.Y H:i:s'); - } + /** + * Get format date d.m.Y H:i:s + * @return string + */ + public function getDateTimeFormat(): string + { + return $this->format('d.m.Y H:i:s'); + } /** * Get different between today and $date by world * @return string */ - public function werbDif(): string - { - $curDate = new Calendar(); - $date = clone $this; - $date->setTime(0,0,0,0); - $curDate->setTime(0,0,0,0); + public function werbDif(): string + { + $curDate = new Calendar(); + $date = clone $this; + $date->setTime(0, 0, 0, 0); + $curDate->setTime(0, 0, 0, 0); $diff = $date->diff($curDate)->days; @@ -424,274 +426,258 @@ public function werbDif(): string if ($diff === 1) { return $local['yesterday']; } else { - return $local[ 'before' ] . ' ' . $diff . ' ' . $local[ 'twoDays' ]; + return $local['before'] . ' ' . $diff . ' ' . $local['twoDays']; } } return $local['after'] . ' ' . $diff . ' ' . $local['fiveDays']; - } + } /** * Get Easter Monday - * @param bool|int $year + * @param int|null $year * @return Calendar */ - public function getEasterMonday($year = false): Calendar - { - $year = ($year === false ? $this->getYear() : $year); - return EasterHoliday::getMonday($year); - } + public function getEasterMonday($year = null): Calendar + { + $year = $year ?? $this->getYear(); + return EasterHoliday::getMonday($year); + } /** * Get Easter - * @param bool|int $year + * @param int|null $year * @return Calendar */ - public function getEaster($year = false): Calendar - { - $year = ($year === false ? $this->getYear() : $year); + public function getEaster($year = null): Calendar + { + $year = $year ?? $this->getYear(); return EasterHoliday::getEaster($year); - } + } /** * Is Big Friday (friday before Easter, Czech republic = Holiday) ? - * @param bool|int $year + * @param int|null $year * @return Calendar */ - public function getGoodFriday($year = false): Calendar + public function getGoodFriday($year = null): Calendar { - $year = ($year === false ? $this->getYear() : $year); + $year = $year ?? $this->getYear(); return EasterHoliday::getGoodFriday($year); } - /** - * @param \DateTime $date - * @param integer $pad - * @return string - */ - public function sklonovaniDays($date, $pad = 1): string - { - return $this->configuration->getLocalization()->getInflexion($date->format('w'), $pad); - } - - /** - * Get workday - * @param bool|Calendar|\DateTime|DateTime $next - * @param bool|Calendar $date - * @return Calendar - */ - public function getWorkDay($next = false, $date = false): Calendar - { - if (!$date) { - $date = $this; - } - - if ($next instanceof \DateTime) { - $date = $next; - $next = false; - } + /** + * @param \DateTime $date + * @param integer $pad + * @return string + */ + public function sklonovaniDays($date, $pad = 1): string + { + return $this->configuration->getLocalization()->getInflexion($date->format('w'), $pad); + } + + /** + * Get workday + * @param bool|Calendar|\DateTime|DateTime $next + * @param null|Calendar $date + * @return Calendar + */ + public function getWorkDay($next = false, $date = null): Calendar + { + if (!$date) { + $date = $this; + } + + if ($next instanceof self) { + $date = $next; + $next = false; + } if ($next) { - $date->modify('+1 days'); + $date->modify('+1 days'); + } + + if (Day::isWeekend($date)) { + if (Day::isSunday($date)) { + $date->modify('+1 days'); + } else { + $date->modify('+2 days'); + } + } elseif ($this->getHolidays()->isHoliday($date)) { + $date->modify('+1 days'); + } + + if (!$this->isWorkDay($date)) { + $this->getWorkDay(); + } + + return $date; + } + + + /** + * @param bool $workTime + * @param Calendar|null $date + * @return Calendar + * @throws \Exception + */ + public function getWorkDayLimit($workTime = true, $date = null): Calendar + { + if ($date === null) { + $date = $this; + } + + if ($workTime === true) { + $limit = $this->getWorkTime(); + [$eH, $eM] = $limit[1]; + + if ($this->timeBellow($eH, $eM) === false) { + $date->modify('+1 days'); + } + } + + $date->getWorkDay(); + return $date; + } + + /** + * + * @param mixed $worktime Work time in array () or hour of work time (int) + * @param int|boolean $startMinute [description] + * @param int|boolean $endHour [description] + * @param int|boolean $endMinute [description] + * @return Calendar + * @throws \Exception + */ + public function setWorkTime($worktime, $startMinute = false, $endHour = false, $endMinute = false): Calendar + { + if (\is_array($worktime)) { + + if (\is_array($worktime[0])) { + [$startHour, $startMinute] = $worktime[0]; + + if (isset($worktime[1])) { + [$endHour, $endMinute] = $worktime[1]; + } + + if (isset($worktime[0][2])) { + $endHour = $worktime[0][2]; + } + + if (isset($worktime[0][3])) { + $endMinute = $worktime[0][3]; + } + } else { + [$startHour, $startMinute, $endHour, $endMinute] = $worktime; + } + + } elseif (is_numeric($worktime)) { + $startHour = $worktime; + $startMinute = (int) $startMinute; + $endHour = (int) $endHour; + $endMinute = (int) $endMinute; + } else { + throw new \Exception("Value '$worktime' is not allowed, use array (full list) or int (hour)"); + } + + HourValidator::validate($startHour); + HourValidator::validate($endHour); + MinuteValidator::validate($startMinute); + MinuteValidator::validate($endMinute); + + $this->working_time = [[(int) $startHour, (int) $startMinute], [(int) $endHour, (int) $endMinute]]; + + return $this; + } + + /** + * @param int|null $type + * @return array|mixed + * @throws \Exception + */ + public function getWorkTime(int $type = null) + { + if ($type === null) { + return $this->working_time; + } + + $type = (int) $type; + + if ($type === self::WORKTIME_START) { + return $this->working_time[0]; + } elseif ($type === self::WORKTIME_END) { + return $this->working_time[1]; + } + + throw new \Exception("Value '$type' is not allowed, you can use (false, 1, 2)"); + } + + /** + * Enable Shipper at weekend + * @return Calendar + */ + public function enableShippingWeekend(): Calendar + { + $this->shippingWeekend = true; + return $this; + } + + /** + * Disable Shipper at weekend + * @return Calendar + */ + public function disableShippingWeekend(): Calendar + { + $this->shippingWeekend = false; + return $this; + } + + /** + * Set Shipper time + * @param int $endHour + * @param int $endMinute + * @return Calendar + */ + public function setShippingTime($endHour, $endMinute): Calendar + { + $this->shipping_time['hour'] = $endHour; + $this->shipping_time['minute'] = $endMinute; + return $this; + } + + /** + * Get Shipper Date + * @return Calendar + */ + public function getShippingDate(): Calendar + { + $shippingTime = $this->shipping_time; + $hour = $shippingTime['hour']; + $minute = $shippingTime['minute']; + + $date = clone $this; + + if ($date->isWorkDay()) { + if ($date->timeOver($hour, $minute)) { + $date->modify('+1 days'); + } + + if (!$this->shippingWeekend) { + $date = $date->getWorkDay(); + } } - if ($date->isWeekend()) { - if ($date->isSunday()) { - $date->modify('+1 days'); - } else { - $date->modify('+2 days'); - } - } elseif ($date->isHoliday()) { - $date->modify('+1 days'); + if (!$date->isWorkDay()) { + if (!$this->shippingWeekend) { + $date = $date->getWorkDay(); + } + } + $date->modify('+' . $this->shippingtime . ' days'); + if (!$this->shippingWeekend) { + $date = $date->getWorkDay(); } - if (!$this->isWorkDay($date)) { - $this->getWorkDay(); - } - - return $date; - } - - /** - * @param bool $workTime - * @param bool $date - * @return Calendar - */ - public function GetWorkDayLimit($workTime = true, $date = false): Calendar - { - if (!$date) { - $date = $this; - } - - if ($workTime === true) { - $limit = $this->getWorkTime(); - $eH = $limit[1][0]; - $eM = $limit[1][1]; - - if ($this->timeBellow($eH, $eM) === false) { - $date->modify('+1 days'); - } - } - - $date->getWorkDay(); - return $date; - } - - /** - * - * @param mixed $worktime Work time in array () or hour of work time (int) - * @param int|boolean $startMinute [description] - * @param int|boolean $endHour [description] - * @param int|boolean $endMinute [description] - * @return Calendar - * @throws \Exception - */ - public function setWorkTime($worktime, $startMinute = false, $endHour = false, $endMinute = false): Calendar - { - if (\is_array($worktime)) { - - if (\is_array($worktime[0])) { - - $startHour = (int) $worktime[0][0]; - $startMinute = (int) $worktime[0][1]; - - if (isset($worktime[1])) { - $endHour = $worktime[1][0]; - $endMinute = $worktime[1][1]; - } - - if (isset($worktime[0][2])) { - $endHour = $worktime[0][2]; - } - - if (isset($worktime[0][3])) { - $endMinute = $worktime[0][3]; - } - } else { - $startHour = $worktime[0]; - $startMinute = (int) $worktime[1]; - $endHour = (int) $worktime[2]; - $endMinute = (int) $worktime[3]; - } - - } elseif (is_numeric($worktime)) { - $startHour = $worktime; - $startMinute = (int) $startMinute; - $endHour = (int) $endHour; - $endMinute = (int) $endMinute; - } else { - throw new \Exception( "Value '$worktime' is not allowed, use array (full list) or int (hour)" ); - } - - if ($startHour < 0 || $startHour > 23) { - throw new \Exception( "Try set bad value of start work time hour ('$startHour'), use 0-23." ); - } - - if ($endHour < 0 || $endHour > 23) { - throw new \Exception( "Try set bad value of end work time hour ('$endHour'), use 0-23." ); - } - - if ($startMinute < 0 || $startMinute > 59) { - throw new \Exception( "Try set bad value of start work time minute ('$startMinute'), use 0-59." ); - } - - if ($endMinute < 0 || $endMinute > 59) { - throw new \Exception( "Try set bad value of end work time minute ('$endMinute'), use 0-59." ); - } - $this->working_time = [ [(int) $startHour, (int) $startMinute], [(int) $endHour, (int) $endMinute] ]; - - return $this; - } - - /** - * @param bool $type - * @return array|mixed - * @throws \Exception - */ - public function getWorkTime($type = false) - { - if ($type === false) { - return $this->working_time; - } - - $type = (int) $type; - - if ($type === self::WORKTIME_START) { - return $this->working_time[0]; - } elseif ($type === self::WORKTIME_END) { - return $this->working_time[1]; - } - - throw new \Exception( "Value '$type' is not allowed, you can use (false, 1, 2)" ); - } - - /** - * Enable Shipper at weekend - * @return Calendar - */ - public function enableShippingWeekend(): Calendar - { - $this->shippingWeekend = true; - return $this; - } - - /** - * Disable Shipper at weekend - * @return Calendar - */ - public function disableShippingWeekend(): Calendar - { - $this->shippingWeekend = false; - return $this; - } - - /** - * Set Shipper time - * @param int $endHour - * @param int $endMinute - * @return Calendar - */ - public function setShippingTime($endHour, $endMinute): Calendar - { - $this->shipping_time['hour'] = $endHour; - $this->shipping_time['minute'] = $endMinute; - return $this; - } - - /** - * Get Shipper Date - * @return Calendar - */ - public function getShippingDate(): Calendar - { - $shippingTime = $this->shipping_time; - $hour = $shippingTime['hour']; - $minute = $shippingTime['minute']; - - $date = clone $this; - - //if ($date->isFriday()) { - if ($date->isWorkDay()) { - if ($date->timeOver($hour, $minute)) { - $date->modify('+1 days'); - } - - if (!$this->shippingWeekend) { - $date = $date->getWorkDay(); - } - } - - if (!$date->isWorkDay()) { - if (!$this->shippingWeekend) { - $date = $date->getWorkDay(); - } - } - $date->modify('+' . $this->shippingtime . ' days'); - if (!$this->shippingWeekend) { - $date = $date->getWorkDay(); - } - - return $date; - } + return $date; + } } diff --git a/src/Galek/Utils/Calendar/Configuration/Configurator.php b/src/Galek/Utils/Calendar/Configuration/Configurator.php index fd4bbc5..498135f 100644 --- a/src/Galek/Utils/Calendar/Configuration/Configurator.php +++ b/src/Galek/Utils/Calendar/Configuration/Configurator.php @@ -4,7 +4,7 @@ * User: Galek * Date: 19.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Configuration; diff --git a/src/Galek/Utils/Calendar/Configuration/Localization.php b/src/Galek/Utils/Calendar/Configuration/Localization.php index 68cd604..42034b2 100644 --- a/src/Galek/Utils/Calendar/Configuration/Localization.php +++ b/src/Galek/Utils/Calendar/Configuration/Localization.php @@ -4,7 +4,7 @@ * User: Galek * Date: 19.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Configuration; diff --git a/src/Galek/Utils/Calendar/Configuration/Shippers.php b/src/Galek/Utils/Calendar/Configuration/Shippers.php index 6a7e0cc..2cd61df 100644 --- a/src/Galek/Utils/Calendar/Configuration/Shippers.php +++ b/src/Galek/Utils/Calendar/Configuration/Shippers.php @@ -4,7 +4,7 @@ * User: Galek * Date: 19.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Configuration; diff --git a/src/Galek/Utils/Calendar/DI/Extension.php b/src/Galek/Utils/Calendar/DI/Extension.php index 0c982b1..cf9505a 100644 --- a/src/Galek/Utils/Calendar/DI/Extension.php +++ b/src/Galek/Utils/Calendar/DI/Extension.php @@ -4,7 +4,7 @@ * User: Galek * Date: 19.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\DI; diff --git a/src/Galek/Utils/Calendar/DI/TExtension.php b/src/Galek/Utils/Calendar/DI/TExtension.php index 24a29eb..88d331f 100644 --- a/src/Galek/Utils/Calendar/DI/TExtension.php +++ b/src/Galek/Utils/Calendar/DI/TExtension.php @@ -4,7 +4,7 @@ * User: Galek * Date: 6.4.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\DI; @@ -48,7 +48,6 @@ protected function checkConfig(array & $config): void { $this->checkCountry($config); $this->checkShippers($config); - $this->checkWork($config); } @@ -56,7 +55,7 @@ protected function checkCountry(array & $config): void { foreach ($config as $group => $setting) { if (!array_key_exists('country', $setting)) { - $config[$group][ 'country' ] = 'CzechRepublic'; + $config[$group]['country'] = 'CzechRepublic'; } } } @@ -85,38 +84,4 @@ protected function checkShippers(array & $config): void } } } - - - protected function checkWork(array & $config): void - { - foreach ($config as $group => $setting) { - if (!array_key_exists('work', $setting)) { - $config[$group]['work'] = $this->defaultWork; - } else { - if (!array_key_exists('start', $setting['work'])) { - $config[$group]['work']['start'] = $this->defaultWork['start']; - } else { - if (!array_key_exists('hour', $setting['work']['start'])) { - $config[$group]['work']['start']['hour'] = $this->defaultWork['start']['hour']; - } - if (!array_key_exists('minute', $setting['work']['start'])) { - $config[$group]['work']['start']['minute'] = $this->defaultWork['start']['minute']; - } - } - if (!array_key_exists('end', $setting['work'])) { - $config[$group]['work']['end'] = $this->defaultWork['end']; - } else { - if (!array_key_exists('hour', $setting['work']['end'])) { - $config[$group]['work']['end']['hour'] = $this->defaultWork['end']['hour']; - } - if (!array_key_exists('minute', $setting['work']['start'])) { - $config[$group]['work']['end']['minute'] = $this->defaultWork['end']['minute']; - } - } - if (!array_key_exists('weekend', $setting['work'])) { - $config[$group]['work']['weekend'] = $this->defaultWork['weekend']; - } - } - } - } } diff --git a/src/Galek/Utils/Calendar/Day.php b/src/Galek/Utils/Calendar/Day.php index b4acf96..bb379b5 100644 --- a/src/Galek/Utils/Calendar/Day.php +++ b/src/Galek/Utils/Calendar/Day.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar; diff --git a/src/Galek/Utils/Calendar/EasterHoliday.php b/src/Galek/Utils/Calendar/EasterHoliday.php index 9af0a80..2446a18 100644 --- a/src/Galek/Utils/Calendar/EasterHoliday.php +++ b/src/Galek/Utils/Calendar/EasterHoliday.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar; @@ -24,13 +24,13 @@ public static function getMonday(int $year): Calendar public static function getEaster($year): Calendar { - $a = ($year % 19); // cyklus stejnych dnu - $b = ($year % 4); // cyklus prestupnych roku - $c = ($year % 7); // dorovnani dne v tydnu + $a = ($year % 19); // cyklus stejnych dnu + $b = ($year % 4); // cyklus prestupnych roku + $c = ($year % 7); // dorovnani dne v tydnu $m = 1; $n = 1; - if ($year >= '1800' && $year <='1899') { + if ($year >= '1800' && $year <= '1899') { $m = 23; $n = 4; } else if ($year >= '1900' && $year <= '2099') { @@ -38,8 +38,8 @@ public static function getEaster($year): Calendar $n = 5; } - $d = ( ( (19 * $a) + $m) % 30); - $e = ( ($n + (2 * $b) + (4 * $c) + (6 * $d) ) % 7); + $d = (((19 * $a) + $m) % 30); + $e = (($n + (2 * $b) + (4 * $c) + (6 * $d)) % 7); $s1 = (22 + $d + $e); $s2 = ($d + $e - 9); diff --git a/src/Galek/Utils/Calendar/Enum/Country.php b/src/Galek/Utils/Calendar/Enum/Country.php index 7ce7d12..9927bb6 100644 --- a/src/Galek/Utils/Calendar/Enum/Country.php +++ b/src/Galek/Utils/Calendar/Enum/Country.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Enum; diff --git a/src/Galek/Utils/Calendar/Enum/CountryLocalization.php b/src/Galek/Utils/Calendar/Enum/CountryLocalization.php index f33d058..3e153ae 100644 --- a/src/Galek/Utils/Calendar/Enum/CountryLocalization.php +++ b/src/Galek/Utils/Calendar/Enum/CountryLocalization.php @@ -4,7 +4,7 @@ * User: Galek * Date: 19.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Enum; diff --git a/src/Galek/Utils/Calendar/Enum/Localization.php b/src/Galek/Utils/Calendar/Enum/Localization.php index 0cf89c2..b261be2 100644 --- a/src/Galek/Utils/Calendar/Enum/Localization.php +++ b/src/Galek/Utils/Calendar/Enum/Localization.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Enum; diff --git a/src/Galek/Utils/Calendar/Exceptions/InvalidHourException.php b/src/Galek/Utils/Calendar/Exceptions/InvalidHourException.php index cfbf9bf..5e8dd6d 100644 --- a/src/Galek/Utils/Calendar/Exceptions/InvalidHourException.php +++ b/src/Galek/Utils/Calendar/Exceptions/InvalidHourException.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Exceptions; diff --git a/src/Galek/Utils/Calendar/Exceptions/InvalidMinuteException.php b/src/Galek/Utils/Calendar/Exceptions/InvalidMinuteException.php index 25535f5..b85970d 100644 --- a/src/Galek/Utils/Calendar/Exceptions/InvalidMinuteException.php +++ b/src/Galek/Utils/Calendar/Exceptions/InvalidMinuteException.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Exceptions; diff --git a/src/Galek/Utils/Calendar/Holidays.php b/src/Galek/Utils/Calendar/Holidays.php index da56a36..2268249 100644 --- a/src/Galek/Utils/Calendar/Holidays.php +++ b/src/Galek/Utils/Calendar/Holidays.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar; diff --git a/src/Galek/Utils/Calendar/Localization.php b/src/Galek/Utils/Calendar/Localization.php index 26c496e..fc091f0 100644 --- a/src/Galek/Utils/Calendar/Localization.php +++ b/src/Galek/Utils/Calendar/Localization.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar; @@ -92,7 +92,7 @@ private function loadConfig() if (!$this->config) { $file = __DIR__ . '/Localization/' . $this->local . '.neon'; - $this->config = Neon::decode(file_get_contents($file), Neon::BLOCK); + $this->config = Neon::decode(file_get_contents($file), Neon::BLOCK); } return $this->config; diff --git a/src/Galek/Utils/Calendar/Time.php b/src/Galek/Utils/Calendar/Time.php index c12ec37..d082983 100644 --- a/src/Galek/Utils/Calendar/Time.php +++ b/src/Galek/Utils/Calendar/Time.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar; diff --git a/src/Galek/Utils/Calendar/Validators/CountryValidator.php b/src/Galek/Utils/Calendar/Validators/CountryValidator.php index e10b392..567d77e 100644 --- a/src/Galek/Utils/Calendar/Validators/CountryValidator.php +++ b/src/Galek/Utils/Calendar/Validators/CountryValidator.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Validators; @@ -17,7 +17,7 @@ class CountryValidator implements IValidator public static function validate($value): bool { - if ( \in_array($value, Country::$list, false) ) { + if (\in_array($value, Country::$list, false)) { return true; } diff --git a/src/Galek/Utils/Calendar/Validators/HourValidator.php b/src/Galek/Utils/Calendar/Validators/HourValidator.php index 0ee6159..8af787c 100644 --- a/src/Galek/Utils/Calendar/Validators/HourValidator.php +++ b/src/Galek/Utils/Calendar/Validators/HourValidator.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Validators; diff --git a/src/Galek/Utils/Calendar/Validators/IValidator.php b/src/Galek/Utils/Calendar/Validators/IValidator.php index b37d5d6..60218f9 100644 --- a/src/Galek/Utils/Calendar/Validators/IValidator.php +++ b/src/Galek/Utils/Calendar/Validators/IValidator.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Validators; diff --git a/src/Galek/Utils/Calendar/Validators/LocalizationValidator.php b/src/Galek/Utils/Calendar/Validators/LocalizationValidator.php index b9c1c99..da9679c 100644 --- a/src/Galek/Utils/Calendar/Validators/LocalizationValidator.php +++ b/src/Galek/Utils/Calendar/Validators/LocalizationValidator.php @@ -4,7 +4,7 @@ * User: Galek * Date: 9.3.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Validators; @@ -18,7 +18,7 @@ class LocalizationValidator implements IValidator public static function validate($value): bool { - if ( \in_array($value, Localization::$list, false) ) { + if (\in_array($value, Localization::$list, false)) { return true; } diff --git a/src/Galek/Utils/Calendar/Validators/MinuteValidator.php b/src/Galek/Utils/Calendar/Validators/MinuteValidator.php index aec44f2..76e58e0 100644 --- a/src/Galek/Utils/Calendar/Validators/MinuteValidator.php +++ b/src/Galek/Utils/Calendar/Validators/MinuteValidator.php @@ -4,7 +4,7 @@ * User: Jan Galek * Date: 10.03.2018 */ -declare(strict_types=1); +declare(strict_types = 1); namespace Galek\Utils\Calendar\Validators; @@ -15,7 +15,7 @@ class MinuteValidator implements IValidator public static function validate($value): bool { - if ( $value >= 0 && $value <= 59 ) { + if ($value >= 0 && $value <= 59) { return true; } diff --git a/tests/CalendarTests/Exceptions.phpt b/tests/CalendarTests/Exceptions.phpt index a559dd4..a3d5e72 100644 --- a/tests/CalendarTests/Exceptions.phpt +++ b/tests/CalendarTests/Exceptions.phpt @@ -15,19 +15,19 @@ class ExceptionsTest extends \Tester\TestCase $date = new Calendar(); Assert::exception(function () use($date) { $date->setWorkTime(25); - }, Exception::class, 'Try set bad value of start work time hour (\'25\'), use 0-23.'); + }, Exception::class, 'Value "25" is invalid for hour'); Assert::exception(function () use($date) { $date->setWorkTime(23, 60); - }, Exception::class, 'Try set bad value of start work time minute (\'60\'), use 0-59.'); + }, Exception::class, 'Value "60" is invalid for minute'); Assert::exception(function () use($date) { $date->setWorkTime(23, 59, 24, 0); - }, Exception::class, 'Try set bad value of end work time hour (\'24\'), use 0-23.'); + }, Exception::class, 'Value "24" is invalid for hour'); Assert::exception(function () use($date) { $date->setWorkTime(23, 59, 23, 60); - }, Exception::class, 'Try set bad value of end work time minute (\'60\'), use 0-59.'); + }, Exception::class, 'Value "60" is invalid for minute'); Assert::exception(function () use($date) { $date->getWorkTime(3);