diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache deleted file mode 100644 index 61f225d..0000000 --- a/.php-cs-fixer.cache +++ /dev/null @@ -1 +0,0 @@ -{"php":"8.0.11","version":"3.2.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Calendar.php":4069419489,"src\/Day.php":3566524330,"src\/Week.php":1355338800,"src\/AbstractCarbonWrapper.php":499610566,"tests\/Calendar\/WeekTest.php":1555848260,"tests\/Calendar\/CalendarTest.php":1852566807,"tests\/Calendar\/DayTest.php":4247321876}} \ No newline at end of file diff --git a/src/AbstractCarbonWrapper.php b/src/AbstractCarbonWrapper.php index 9cd99ef..465a911 100644 --- a/src/AbstractCarbonWrapper.php +++ b/src/AbstractCarbonWrapper.php @@ -2,15 +2,14 @@ namespace Calendar; +use Carbon\CarbonImmutable; + /** * @mixin \Carbon\CarbonImmutable */ abstract class AbstractCarbonWrapper { - /** - * @var \Carbon\CarbonImmutable - */ - protected $carbon; + protected CarbonImmutable $carbon; /** * Attempts to query Carbon for the property diff --git a/src/Calendar.php b/src/Calendar.php index 6b17d6b..038c2cc 100644 --- a/src/Calendar.php +++ b/src/Calendar.php @@ -4,7 +4,6 @@ use Carbon\CarbonInterface; use DateTimeZone; -use InvalidArgumentException; class Calendar { @@ -14,32 +13,17 @@ class Calendar */ public const WEEKS_IN_MONTH = 6; - /** - * @var int - */ - private $month; + private int $month; - /** - * @var int - */ - private $year; + private int $year; - /** - * @var \DateTimeZone - */ - private $timezone; + private DateTimeZone $timezone; - /** - * @var int - */ - private $weekStart = CarbonInterface::MONDAY; + private int $weekStart = CarbonInterface::MONDAY; - /** - * @var bool - */ - private $variableWeeks = false; + private bool $variableWeeks = false; - public function __construct(int $year, int $month, $timezone = 'UTC') + public function __construct(int $year, int $month, DateTimeZone|string $timezone = 'UTC') { $this->setYear($year); $this->setMonth($month); @@ -66,17 +50,8 @@ public function getYear(): int return $this->year; } - /** - * @param \DateTimeZone|string $timezone - * - * @throws \InvalidArgumentException - */ - public function setTimezone($timezone): void + public function setTimezone(DateTimeZone|string $timezone): void { - if (! ($timezone instanceof DateTimeZone || is_string($timezone))) { - throw new InvalidArgumentException('setTimezone requires a DateTimeZone instance or a timezone string'); - } - $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); } @@ -135,7 +110,6 @@ public function getWeeks(): array $firstDay = $this->getFirstDay(); $lastDay = $this->getLastDay(); $numberOfWeeks = $this->isVariableWeeks() ? $this->getWeekCount($firstDay) : self::WEEKS_IN_MONTH; - /** @var \Calendar\Day $day */ $day = clone $firstDay; $weeks = []; diff --git a/src/Day.php b/src/Day.php index 6d3b330..fa81b0b 100644 --- a/src/Day.php +++ b/src/Day.php @@ -7,22 +7,13 @@ class Day extends AbstractCarbonWrapper { - /** - * @var bool - */ - private $blankDay = false; + private bool $blankDay = false; - /** - * @param int $year - * @param int $month - * @param int $day - * @param \DateTimeZone|string $timezone - */ - public function __construct(int $year, int $month, int $day, $timezone = 'UTC') + public function __construct(int $year, int $month, int $day, DateTimeZone|string $timezone = 'UTC') { $hour = 5; - if (($timezone instanceof DateTimeZone && $timezone->getName() === 'UTC') || $timezone === 'UTC') { + if ($timezone === 'UTC' || ($timezone instanceof DateTimeZone && $timezone->getName() === 'UTC')) { $hour = 0; } @@ -35,9 +26,8 @@ public function setBlankDay(bool $value): void } /** - * A "blank" day refers to days that appear - * on the current months calendar but are physically part of the - * previous or next months + * A "blank" day refers to days that appear on the current month's calendar + * but are physically part of the previous or next months */ public function isBlankDay(): bool { diff --git a/src/Week.php b/src/Week.php index 7d0eb88..e86e32c 100644 --- a/src/Week.php +++ b/src/Week.php @@ -6,27 +6,15 @@ class Week { - /** - * @var \Calendar\Day - */ - private $dateStart; + private Day $dateStart; - /** - * @var int - */ - private $currentMonth; + private int $currentMonth; - /** - * @var int - */ - private $weekStart = CarbonInterface::MONDAY; + private int $weekStart = CarbonInterface::MONDAY; - /** - * @var array - */ - private $days = []; + private array $days = []; - public function __construct(Day $dateStart, int $currentMonth = null, int $weekStart = CarbonInterface::MONDAY) + public function __construct(Day $dateStart, ?int $currentMonth = null, int $weekStart = CarbonInterface::MONDAY) { $this->setWeekStart($weekStart); $this->setStartDate($dateStart); @@ -47,7 +35,7 @@ public function getStartDate(): Day return $this->dateStart; } - private function setCurrentMonth(int $currentMonth = null): void + private function setCurrentMonth(?int $currentMonth = null): void { $this->currentMonth = $currentMonth ?? $this->dateStart->month; } @@ -83,8 +71,6 @@ private function generateWeek(): void /** * Adds a day to the days property * Goes through a check first - * - * @param \Calendar\Day $day */ private function addDay(Day $day): void { @@ -94,7 +80,7 @@ private function addDay(Day $day): void } /** - * @return \Calendar\Day[] + * @return array<\Calendar\Day> */ public function getDays(): array { @@ -102,12 +88,7 @@ public function getDays(): array } /** - * Determines whether a day is part of the currently - * selected month or not - * - * @param \Calendar\Day $day - * - * @return bool + * Determines whether a day is part of the currently selected month or not */ public function currentMonthDay(Day $day): bool {