mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Fix "Argument 1 of Meritoo\\Common\\Utilities\\Date::getdayofweek expects int, string|false provided" bug pointed by Psalm
This commit is contained in:
@@ -235,20 +235,20 @@ class Date
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getCurrentDayOfWeek()
|
||||
public static function getCurrentDayOfWeek(): int
|
||||
{
|
||||
$now = new DateTime();
|
||||
|
||||
$year = $now->format('Y');
|
||||
$month = $now->format('m');
|
||||
$day = $now->format('d');
|
||||
$year = (int)$now->format('Y');
|
||||
$month = (int)$now->format('m');
|
||||
$day = (int)$now->format('d');
|
||||
|
||||
return self::getDayOfWeek($year, $month, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns day of week (number 0 to 6, 0 - sunday, 6 - saturday).
|
||||
* Based on the Zeller's algorithm (http://pl.wikipedia.org/wiki/Kalendarz_wieczny).
|
||||
* Based on the Zeller's algorithm (https://en.wikipedia.org/wiki/Perpetual_calendar).
|
||||
*
|
||||
* @param int $year The year value
|
||||
* @param int $month The month value
|
||||
@@ -257,12 +257,8 @@ class Date
|
||||
* @throws UnknownDatePartTypeException
|
||||
* @return int
|
||||
*/
|
||||
public static function getDayOfWeek($year, $month, $day)
|
||||
public static function getDayOfWeek(int $year, int $month, int $day): int
|
||||
{
|
||||
$year = (int)$year;
|
||||
$month = (int)$month;
|
||||
$day = (int)$day;
|
||||
|
||||
// Oops, given year is incorrect
|
||||
if ($year <= 0) {
|
||||
throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year);
|
||||
@@ -299,13 +295,13 @@ class Date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCurrentDayOfWeekName()
|
||||
public static function getCurrentDayOfWeekName(): string
|
||||
{
|
||||
$now = new DateTime();
|
||||
|
||||
$year = $now->format('Y');
|
||||
$month = $now->format('m');
|
||||
$day = $now->format('d');
|
||||
$year = (int)$now->format('Y');
|
||||
$month = (int)$now->format('m');
|
||||
$day = (int)$now->format('d');
|
||||
|
||||
return self::getDayOfWeekName($year, $month, $day);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideIncorrectYearMonthDay
|
||||
*/
|
||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day): void
|
||||
public function testGetDayOfWeekIncorrectValues(int $year, int $month, int $day): void
|
||||
{
|
||||
$this->expectException(UnknownDatePartTypeException::class);
|
||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||
@@ -241,7 +241,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideYearMonthDay
|
||||
*/
|
||||
public function testGetDayOfWeek($year, $month, $day): void
|
||||
public function testGetDayOfWeek(int $year, int $month, int $day): void
|
||||
{
|
||||
self::assertRegExp('/^[0-6]{1}$/', (string)Date::getDayOfWeek($year, $month, $day));
|
||||
}
|
||||
@@ -766,20 +766,8 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectYearMonthDay()
|
||||
public function provideIncorrectYearMonthDay(): Generator
|
||||
{
|
||||
yield[
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
0,
|
||||
0,
|
||||
|
||||
Reference in New Issue
Block a user