diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2963840..5e42f62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] runs-on: ${{ matrix.operating-system }} diff --git a/composer.json b/composer.json index 0066b21..e0832fc 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage" : "https://donatstudios.com/SimpleCalendar", "license" : "MIT", "require" : { - "php": ">=7.2", + "php": ">=7.4", "ext-calendar": "*" }, "require-dev": { @@ -14,7 +14,7 @@ "corpus/coding-standard": "^0.6.0", "donatj/drop": "^1.1", "friendsofphp/php-cs-fixer": "^3.3", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "*", "squizlabs/php_codesniffer": "^3.7" }, diff --git a/src/SimpleCalendar.php b/src/SimpleCalendar.php index 4a15f2d..30e5402 100644 --- a/src/SimpleCalendar.php +++ b/src/SimpleCalendar.php @@ -203,10 +203,7 @@ public function setStartOfWeek( $offset ) : void { throw new \InvalidArgumentException('invalid offset'); } - $date = date('N', $weekTime); - assert($date !== false); - - $this->offset = intval($date) % 7; + $this->offset = intval(date('N', $weekTime)) % 7; } } @@ -315,18 +312,26 @@ public function render() : string { } /** - * @param array $data + * @template T + * @param array $data + * @param-out array $data */ private function rotate( array &$data, int $steps ) : void { $count = count($data); + if( $count === 0 ) { + return; + } + if( $steps < 0 ) { $steps = $count + $steps; } $steps %= $count; - for( $i = 0; $i < $steps; $i++ ) { - $data[] = array_shift($data); + if( $steps === 0 ) { + return; } + + $data = array_merge(array_slice($data, $steps), array_slice($data, 0, $steps)); } /** diff --git a/test/SimpleCalendarTest.php b/test/SimpleCalendarTest.php index c87cd08..a2563e7 100644 --- a/test/SimpleCalendarTest.php +++ b/test/SimpleCalendarTest.php @@ -16,7 +16,7 @@ public function testBadDailyHtmlDates() : void { $cal = new SimpleCalendar('June 2010', 'June 5 2010'); $cal->addDailyHtml('foo', 'tomorrow', 'yesterday'); } catch( InvalidArgumentException $ex ) { - $this->assertTrue(true); + $this->addToAssertionCount(1); return; }