Fix phpstan issues.

This commit is contained in:
James Cole
2025-09-07 07:51:01 +02:00
parent 602df95f3c
commit c3a3bdf525
21 changed files with 52 additions and 219 deletions

View File

@@ -78,7 +78,7 @@ class ParseDateString
*/
public function parseDate(string $date): Carbon
{
app('log')->debug(sprintf('parseDate("%s")', $date));
Log::debug(sprintf('parseDate("%s")', $date));
$date = strtolower($date);
// parse keywords:
if (in_array($date, $this->keywords, true)) {
@@ -107,7 +107,7 @@ class ParseDateString
// maybe a date range
if (10 === strlen($date) && (str_contains($date, 'xx') || str_contains($date, 'xxxx'))) {
app('log')->debug(sprintf('[c] Detected a date range ("%s"), return a fake date.', $date));
Log::debug(sprintf('[c] Detected a date range ("%s"), return a fake date.', $date));
// very lazy way to parse the date without parsing it, because this specific function
// cant handle date ranges.
@@ -158,7 +158,7 @@ class ParseDateString
protected function parseRelativeDate(string $date): Carbon
{
app('log')->debug(sprintf('Now in parseRelativeDate("%s")', $date));
Log::debug(sprintf('Now in parseRelativeDate("%s")', $date));
$parts = explode(' ', $date);
$today = today(config('app.timezone'))->startOfDay();
$functions = [
@@ -179,14 +179,14 @@ class ParseDateString
];
foreach ($parts as $part) {
app('log')->debug(sprintf('Now parsing part "%s"', $part));
Log::debug(sprintf('Now parsing part "%s"', $part));
$part = trim($part);
// verify if correct
$pattern = '/[+-]\d+[wqmdy]/';
$result = preg_match($pattern, $part);
if (0 === $result || false === $result) {
app('log')->error(sprintf('Part "%s" does not match regular expression. Will be skipped.', $part));
if (0 === $result) {
Log::error(sprintf('Part "%s" does not match regular expression. Will be skipped.', $part));
continue;
}
@@ -194,14 +194,14 @@ class ParseDateString
$period = $part[strlen($part) - 1];
$number = (int) substr($part, 1, -1);
if (!array_key_exists($period, $functions[$direction])) {
app('log')->error(sprintf('No method for direction %d and period "%s".', $direction, $period));
Log::error(sprintf('No method for direction %d and period "%s".', $direction, $period));
continue;
}
$func = $functions[$direction][$period];
app('log')->debug(sprintf('Will now do %s(%d) on %s', $func, $number, $today->format('Y-m-d')));
Log::debug(sprintf('Will now do %s(%d) on %s', $func, $number, $today->format('Y-m-d')));
$today->{$func}($number); // @phpstan-ignore-line
app('log')->debug(sprintf('Resulting date is %s', $today->format('Y-m-d')));
Log::debug(sprintf('Resulting date is %s', $today->format('Y-m-d')));
}
return $today;
@@ -260,11 +260,11 @@ class ParseDateString
$pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a day range.', $date));
Log::debug(sprintf('"%s" is a day range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a day range.', $date));
Log::debug(sprintf('"%s" is not a day range.', $date));
return false;
}
@@ -287,11 +287,11 @@ class ParseDateString
$pattern = '/^xxxx-(0[1-9]|1[012])-xx$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month range.', $date));
Log::debug(sprintf('"%s" is a month range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a month range.', $date));
Log::debug(sprintf('"%s" is not a month range.', $date));
return false;
}
@@ -301,7 +301,7 @@ class ParseDateString
*/
protected function parseMonthRange(string $date): array
{
app('log')->debug(sprintf('parseMonthRange: Parsed "%s".', $date));
Log::debug(sprintf('parseMonthRange: Parsed "%s".', $date));
$parts = explode('-', $date);
return [
@@ -315,11 +315,11 @@ class ParseDateString
$pattern = '/^(19|20)\d\d-xx-xx$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a year range.', $date));
Log::debug(sprintf('"%s" is a year range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a year range.', $date));
Log::debug(sprintf('"%s" is not a year range.', $date));
return false;
}
@@ -329,7 +329,7 @@ class ParseDateString
*/
protected function parseYearRange(string $date): array
{
app('log')->debug(sprintf('parseYearRange: Parsed "%s"', $date));
Log::debug(sprintf('parseYearRange: Parsed "%s"', $date));
$parts = explode('-', $date);
return [
@@ -343,11 +343,11 @@ class ParseDateString
$pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/day range.', $date));
Log::debug(sprintf('"%s" is a month/day range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a month/day range.', $date));
Log::debug(sprintf('"%s" is not a month/day range.', $date));
return false;
}
@@ -357,7 +357,7 @@ class ParseDateString
*/
private function parseMonthDayRange(string $date): array
{
app('log')->debug(sprintf('parseMonthDayRange: Parsed "%s".', $date));
Log::debug(sprintf('parseMonthDayRange: Parsed "%s".', $date));
$parts = explode('-', $date);
return [
@@ -372,11 +372,11 @@ class ParseDateString
$pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a day/year range.', $date));
Log::debug(sprintf('"%s" is a day/year range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a day/year range.', $date));
Log::debug(sprintf('"%s" is not a day/year range.', $date));
return false;
}
@@ -386,7 +386,7 @@ class ParseDateString
*/
private function parseDayYearRange(string $date): array
{
app('log')->debug(sprintf('parseDayYearRange: Parsed "%s".', $date));
Log::debug(sprintf('parseDayYearRange: Parsed "%s".', $date));
$parts = explode('-', $date);
return [
@@ -401,11 +401,11 @@ class ParseDateString
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/';
$result = preg_match($pattern, $date);
if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/year range.', $date));
Log::debug(sprintf('"%s" is a month/year range.', $date));
return true;
}
app('log')->debug(sprintf('"%s" is not a month/year range.', $date));
Log::debug(sprintf('"%s" is not a month/year range.', $date));
return false;
}
@@ -415,7 +415,7 @@ class ParseDateString
*/
protected function parseMonthYearRange(string $date): array
{
app('log')->debug(sprintf('parseMonthYearRange: Parsed "%s".', $date));
Log::debug(sprintf('parseMonthYearRange: Parsed "%s".', $date));
$parts = explode('-', $date);
return [