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
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function getCurrentDayOfWeek()
|
public static function getCurrentDayOfWeek(): int
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
|
|
||||||
$year = $now->format('Y');
|
$year = (int)$now->format('Y');
|
||||||
$month = $now->format('m');
|
$month = (int)$now->format('m');
|
||||||
$day = $now->format('d');
|
$day = (int)$now->format('d');
|
||||||
|
|
||||||
return self::getDayOfWeek($year, $month, $day);
|
return self::getDayOfWeek($year, $month, $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns day of week (number 0 to 6, 0 - sunday, 6 - saturday).
|
* 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 $year The year value
|
||||||
* @param int $month The month value
|
* @param int $month The month value
|
||||||
@@ -257,12 +257,8 @@ class Date
|
|||||||
* @throws UnknownDatePartTypeException
|
* @throws UnknownDatePartTypeException
|
||||||
* @return int
|
* @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
|
// Oops, given year is incorrect
|
||||||
if ($year <= 0) {
|
if ($year <= 0) {
|
||||||
throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year);
|
throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year);
|
||||||
@@ -299,13 +295,13 @@ class Date
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getCurrentDayOfWeekName()
|
public static function getCurrentDayOfWeekName(): string
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
|
|
||||||
$year = $now->format('Y');
|
$year = (int)$now->format('Y');
|
||||||
$month = $now->format('m');
|
$month = (int)$now->format('m');
|
||||||
$day = $now->format('d');
|
$day = (int)$now->format('d');
|
||||||
|
|
||||||
return self::getDayOfWeekName($year, $month, $day);
|
return self::getDayOfWeekName($year, $month, $day);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ class DateTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideIncorrectYearMonthDay
|
* @dataProvider provideIncorrectYearMonthDay
|
||||||
*/
|
*/
|
||||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day): void
|
public function testGetDayOfWeekIncorrectValues(int $year, int $month, int $day): void
|
||||||
{
|
{
|
||||||
$this->expectException(UnknownDatePartTypeException::class);
|
$this->expectException(UnknownDatePartTypeException::class);
|
||||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||||
@@ -241,7 +241,7 @@ class DateTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideYearMonthDay
|
* @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));
|
self::assertRegExp('/^[0-6]{1}$/', (string)Date::getDayOfWeek($year, $month, $day));
|
||||||
}
|
}
|
||||||
@@ -766,20 +766,8 @@ class DateTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @return Generator
|
* @return Generator
|
||||||
*/
|
*/
|
||||||
public function provideIncorrectYearMonthDay()
|
public function provideIncorrectYearMonthDay(): Generator
|
||||||
{
|
{
|
||||||
yield[
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
|
|
||||||
yield[
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
];
|
|
||||||
|
|
||||||
yield[
|
yield[
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|||||||
Reference in New Issue
Block a user