1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 09:06:10 +02:00

Add phpstan strict rules and deprecation rules, fix all related issues

This commit is contained in:
Jordi Boggiano
2022-04-24 11:08:10 +02:00
parent ad732b37a7
commit 6627c092d8
62 changed files with 335 additions and 186 deletions

View File

@@ -59,12 +59,12 @@ class GitProcessor implements ProcessorInterface
*/
private static function getGitInfo(): array
{
if (self::$cache) {
if (self::$cache !== null) {
return self::$cache;
}
$branches = `git branch -v --no-abbrev`;
if ($branches && preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) {
$branches = shell_exec('git branch -v --no-abbrev');
if (is_string($branches) && 1 === preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) {
return self::$cache = [
'branch' => $matches[1],
'commit' => $matches[2],

View File

@@ -83,7 +83,7 @@ class IntrospectionProcessor implements ProcessorInterface
continue 2;
}
}
} elseif (in_array($trace[$i]['function'], self::SKIP_FUNCTIONS)) {
} elseif (in_array($trace[$i]['function'], self::SKIP_FUNCTIONS, true)) {
$i++;
continue;
@@ -118,6 +118,6 @@ class IntrospectionProcessor implements ProcessorInterface
return false;
}
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], self::SKIP_FUNCTIONS);
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], self::SKIP_FUNCTIONS, true);
}
}

View File

@@ -58,11 +58,11 @@ class MercurialProcessor implements ProcessorInterface
*/
private static function getMercurialInfo(): array
{
if (self::$cache) {
if (self::$cache !== null) {
return self::$cache;
}
$result = explode(' ', trim(`hg id -nb`));
$result = explode(' ', trim((string) shell_exec('hg id -nb')));
if (count($result) >= 3) {
return self::$cache = [

View File

@@ -60,12 +60,12 @@ class PsrLogMessageProcessor implements ProcessorInterface
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
$replacements[$placeholder] = $val;
} elseif ($val instanceof \DateTimeInterface) {
if (!$this->dateFormat && $val instanceof \Monolog\DateTimeImmutable) {
if (null === $this->dateFormat && $val instanceof \Monolog\DateTimeImmutable) {
// handle monolog dates using __toString if no specific dateFormat was asked for
// so that it follows the useMicroseconds flag
$replacements[$placeholder] = (string) $val;
} else {
$replacements[$placeholder] = $val->format($this->dateFormat ?: static::SIMPLE_DATE);
$replacements[$placeholder] = $val->format($this->dateFormat ?? static::SIMPLE_DATE);
}
} elseif (is_object($val)) {
$replacements[$placeholder] = '[object '.Utils::getClass($val).']';

View File

@@ -65,7 +65,7 @@ class WebProcessor implements ProcessorInterface
}
if (isset($extraFields[0])) {
foreach (array_keys($this->extraFields) as $fieldName) {
if (!in_array($fieldName, $extraFields)) {
if (!in_array($fieldName, $extraFields, true)) {
unset($this->extraFields[$fieldName]);
}
}