PHPStan upgrade and new baseline.

Changelogs summary:

 - phpstan/phpstan updated from 0.12.96 to 1.0.1 major
   See changes: https://github.com/phpstan/phpstan/compare/0.12.96...1.0.1
   Release notes: https://github.com/phpstan/phpstan/releases/tag/1.0.1

 - phpstan/phpstan-doctrine updated from 0.12.44 to 1.0.1 major
   See changes: https://github.com/phpstan/phpstan-doctrine/compare/0.12.44...1.0.1
   Release notes: https://github.com/phpstan/phpstan-doctrine/releases/tag/1.0.1
This commit is contained in:
Buster "Silver Eagle" Neece 2021-11-02 23:12:02 -05:00
parent 32ca24e406
commit 79b1bc5c4a
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
21 changed files with 145 additions and 92 deletions

View File

@ -107,26 +107,26 @@
"require-dev": {
"codeception/codeception": "^4.0",
"codeception/module-asserts": "^1.1",
"codeception/module-cli": "^1.0",
"codeception/module-doctrine2": "^1.0",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-rest": "^1.0",
"ergebnis/composer-normalize": "^2.15",
"filp/whoops": "^2",
"jetbrains/phpstorm-attributes": "^1.0",
"mockery/mockery": "^1.0",
"php-parallel-lint/php-console-highlighter": "^0.5.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "0.12.96",
"phpstan/phpstan-doctrine": "^0.12",
"phpunit/php-timer": "^5.0",
"phpunit/phpunit": "^9.2",
"pyrech/composer-changelogs": "^1.7",
"roave/security-advisories": "dev-latest",
"slevomat/coding-standard": "^7",
"softcreatr/jsonpath": "^0.7.2",
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^5.1"
"codeception/module-cli": "^1.0",
"codeception/module-doctrine2": "^1.0",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-rest": "^1.0",
"ergebnis/composer-normalize": "^2.15",
"filp/whoops": "^2",
"jetbrains/phpstorm-attributes": "^1.0",
"mockery/mockery": "^1.0",
"php-parallel-lint/php-console-highlighter": "^0.5.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1",
"phpstan/phpstan-doctrine": "^1",
"phpunit/php-timer": "^5.0",
"phpunit/phpunit": "^9.2",
"pyrech/composer-changelogs": "^1.7",
"roave/security-advisories": "dev-latest",
"slevomat/coding-standard": "^7",
"softcreatr/jsonpath": "^0.7.2",
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^5.1"
},
"config": {
"discard-changes": true,

37
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "601cce81f6dc67d28ef0902a712fb852",
"content-hash": "5ff9d6ce6c6161765b7aaf4dce99fc31",
"packages": [
{
"name": "aws/aws-crt-php",
@ -11689,16 +11689,16 @@
},
{
"name": "phpstan/phpstan",
"version": "0.12.96",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "a98bdc51318f20fcae8c953d266f81a70254917f"
"reference": "0eb6ecdfbcebf2207668087dfb2e215581a75023"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/a98bdc51318f20fcae8c953d266f81a70254917f",
"reference": "a98bdc51318f20fcae8c953d266f81a70254917f",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/0eb6ecdfbcebf2207668087dfb2e215581a75023",
"reference": "0eb6ecdfbcebf2207668087dfb2e215581a75023",
"shasum": ""
},
"require": {
@ -11714,7 +11714,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
"dev-master": "1.0-dev"
}
},
"autoload": {
@ -11729,7 +11729,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/0.12.96"
"source": "https://github.com/phpstan/phpstan/tree/1.0.1"
},
"funding": [
{
@ -11749,25 +11749,25 @@
"type": "tidelift"
}
],
"time": "2021-08-21T11:55:13+00:00"
"time": "2021-11-02T10:25:31+00:00"
},
{
"name": "phpstan/phpstan-doctrine",
"version": "0.12.44",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-doctrine.git",
"reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd"
"reference": "ea3919219c4915f4a3896227aaa9e5d3d2034bd7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/5fe9a9b15707d9bc5178fa7cf0899e904d112ccd",
"reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd",
"url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/ea3919219c4915f4a3896227aaa9e5d3d2034bd7",
"reference": "ea3919219c4915f4a3896227aaa9e5d3d2034bd7",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^0.12.85"
"phpstan/phpstan": "^1.0"
},
"conflict": {
"doctrine/collections": "<1.0",
@ -11785,16 +11785,17 @@
"doctrine/orm": "^2.9.1",
"doctrine/persistence": "^1.1 || ^2.0",
"nesbot/carbon": "^2.49",
"nikic/php-parser": "^4.13.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.5",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"ramsey/uuid-doctrine": "^1.5.0"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
"dev-master": "1.0-dev"
},
"phpstan": {
"includes": [
@ -11815,9 +11816,9 @@
"description": "Doctrine extensions for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-doctrine/issues",
"source": "https://github.com/phpstan/phpstan-doctrine/tree/0.12.44"
"source": "https://github.com/phpstan/phpstan-doctrine/tree/1.0.1"
},
"time": "2021-09-01T06:46:16+00:00"
"time": "2021-11-02T13:28:55+00:00"
},
{
"name": "phpunit/php-code-coverage",

62
phpstan-baseline.neon Normal file
View File

@ -0,0 +1,62 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$record of method App\\\\Controller\\\\Api\\\\AbstractApiCrudController\\<TEntity of App\\\\Entity\\\\StationPlaylist\\|App\\\\Entity\\\\StationStreamer\\>\\:\\:fromArray\\(\\) expects \\(TEntity of App\\\\Entity\\\\StationPlaylist\\|App\\\\Entity\\\\StationStreamer\\)\\|null, \\(TEntity of App\\\\Entity\\\\StationPlaylist\\|App\\\\Entity\\\\StationStreamer\\)\\|null given\\.$#"
count: 1
path: src/Controller/Api/Stations/AbstractScheduledEntityController.php
-
message: "#^Parameter \\#3 \\$criteria of method Doctrine\\\\DBAL\\\\Connection\\:\\:update\\(\\) expects array\\<string, mixed\\>, array\\<int, int\\> given\\.$#"
count: 1
path: src/Entity/Migration/Version20180412055024.php
-
message: "#^Parameter \\#3 \\$criteria of method Doctrine\\\\DBAL\\\\Connection\\:\\:update\\(\\) expects array\\<string, mixed\\>, array\\<int, int\\> given\\.$#"
count: 1
path: src/Entity/Migration/Version20180429013130.php
-
message: "#^Parameter \\#3 \\$criteria of method Doctrine\\\\DBAL\\\\Connection\\:\\:update\\(\\) expects array\\<string, mixed\\>, array\\<int, int\\> given\\.$#"
count: 1
path: src/Entity/Migration/Version20180818223558.php
-
message: "#^Parameter \\#3 \\$criteria of method Doctrine\\\\DBAL\\\\Connection\\:\\:update\\(\\) expects array\\<string, mixed\\>, array\\<int, int\\> given\\.$#"
count: 1
path: src/Entity/Migration/Version20190513163051.php
-
message: "#^Parameter \\#2 \\$criteria of method Doctrine\\\\DBAL\\\\Connection\\:\\:delete\\(\\) expects array\\<string, mixed\\>, array\\<int, int\\> given\\.$#"
count: 1
path: src/Entity/Migration/Version20201204043539.php
-
message: "#^Static property App\\\\Environment\\:\\:\\$instance \\(static\\(App\\\\Environment\\)\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: src/Environment.php
-
message: "#^Cannot cast Symfony\\\\Component\\\\Validator\\\\ConstraintViolationListInterface to string\\.$#"
count: 1
path: src/Exception/ValidationException.php
-
message: "#^Static property App\\\\Session\\\\Csrf\\:\\:\\$instance \\(static\\(App\\\\Session\\\\Csrf\\)\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: src/Session/Csrf.php
-
message: "#^Static property App\\\\Session\\\\Flash\\:\\:\\$instance \\(static\\(App\\\\Session\\\\Flash\\)\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: src/Session/Flash.php
-
message: "#^Parameter \\#1 \\$className of method Doctrine\\\\ORM\\\\EntityManagerInterface\\:\\:getRepository\\(\\) expects class\\-string\\<object\\>, class\\-string\\|false given\\.$#"
count: 1
path: src/Validator/Constraints/UniqueEntityValidator.php
-
message: "#^Parameter \\#2 \\$callback of method League\\\\Plates\\\\Engine\\:\\:registerFunction\\(\\) expects League\\\\Plates\\\\callback, Closure given\\.$#"
count: 7
path: src/View.php

View File

@ -1,3 +1,7 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
parameters:
level: 8
@ -16,19 +20,5 @@ parameters:
- App\Session\NamespaceInterface
- App\View
ignoreErrors:
# Caused by Symfony Validator (perhaps wrongly) returning the interface.
- '#Cannot cast Symfony\\Component\\Validator\\ConstraintViolationListInterface to string.#'
# Some doctrine migrations fail because of these
- '#Parameter \#3 \$criteria of method Doctrine\\DBAL\\Connection::update\(\) expects array<string, mixed>, array<int, int> given.#'
- '#Parameter \#2 \$criteria of method Doctrine\\DBAL\\Connection::delete\(\) expects array<string, mixed>, array<int, int> given.#'
# Known upstream issue with Plates template engine
- '#Parameter \#2 \$callback of method League\\Plates\\Engine::registerFunction\(\) expects League\\Plates\\callback, Closure given.#'
parallel:
maximumNumberOfProcesses: 1
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon

View File

@ -167,10 +167,10 @@ class AppFactory
return;
}
$errno = $error["type"] ?? E_ERROR;
$errfile = $error["file"] ?? 'unknown';
$errline = $error["line"] ?? 0;
$errstr = $error["message"] ?? 'Shutdown';
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
if ($errno &= E_PARSE | E_ERROR | E_USER_ERROR | E_CORE_ERROR | E_COMPILE_ERROR) {
$logger->critical(

View File

@ -199,9 +199,7 @@ class StationsController extends AbstractAdminApiCrudController
$errors = $this->validator->validate($record);
if (count($errors) > 0) {
$e = new ValidationException((string)$errors);
$e->setDetailedErrors($errors);
throw $e;
throw ValidationException::fromValidationErrors($errors);
}
return ($create_mode)

View File

@ -63,9 +63,7 @@ abstract class AbstractScheduledEntityController extends AbstractStationApiCrudC
$errors = $this->validator->validate($record);
if (count($errors) > 0) {
$e = new ValidationException((string)$errors);
$e->setDetailedErrors($errors);
throw $e;
throw ValidationException::fromValidationErrors($errors);
}
$this->em->persist($record);

View File

@ -258,7 +258,7 @@ class ListAction
$row->is_dir = $file->isDir();
} else {
$row->path = $file;
$row->timestamp = $fs->lastModified($file) ?? 0;
$row->timestamp = $fs->lastModified($file);
$row->is_dir = false;
}

View File

@ -8,8 +8,8 @@ use App\Entity;
use App\Flysystem\StationFilesystems;
use App\Http\Response;
use App\Http\ServerRequest;
use League\Flysystem\UnableToCreateDirectory;
use Psr\Http\Message\ResponseInterface;
use SebastianBergmann\CodeCoverage\DirectoryCouldNotBeCreatedException;
class MakeDirectoryAction
{
@ -33,7 +33,7 @@ class MakeDirectoryAction
try {
$fsMedia->createDirectory($newDir);
} catch (DirectoryCouldNotBeCreatedException $e) {
} catch (UnableToCreateDirectory $e) {
return $response->withStatus(400)
->withJson(new Entity\Api\Error(400, $e->getMessage()));
}

View File

@ -164,9 +164,7 @@ class FilesController extends AbstractStationApiCrudController
// Validate the UploadFile API record.
$errors = $this->validator->validate($api_record);
if (count($errors) > 0) {
$e = new ValidationException((string)$errors);
$e->setDetailedErrors($errors);
throw $e;
throw ValidationException::fromValidationErrors($errors);
}
// Write file to temp path.
@ -225,9 +223,7 @@ class FilesController extends AbstractStationApiCrudController
$errors = $this->validator->validate($record);
if (count($errors) > 0) {
$e = new ValidationException((string)$errors);
$e->setDetailedErrors($errors);
throw $e;
throw ValidationException::fromValidationErrors($errors);
}
if ($record instanceof Entity\StationMedia) {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Frontend\PublicPages;
use App\Entity\PodcastEpisode;
use App\Entity\Repository\PodcastEpisodeRepository;
use App\Entity\Repository\PodcastRepository;
use App\Exception\PodcastNotFoundException;
@ -45,8 +46,11 @@ class PodcastEpisodesController
usort(
$publishedEpisodes,
static function ($prevEpisode, $nextEpisode) {
$prevPublishedAt = $prevEpisode->getPublishedAt ?? $prevEpisode->getCreatedAt();
$nextPublishedAt = $nextEpisode->getPublishedAt ?? $nextEpisode->getCreatedAt();
/** @var PodcastEpisode $prevEpisode */
/** @var PodcastEpisode $nextEpisode */
$prevPublishedAt = $prevEpisode->getPublishAt() ?? $prevEpisode->getCreatedAt();
$nextPublishedAt = $nextEpisode->getPublishAt() ?? $nextEpisode->getCreatedAt();
return ($nextPublishedAt <=> $prevPublishedAt);
}

View File

@ -49,7 +49,7 @@ class Customization
if (!empty($queryParams['theme']) && in_array($queryParams['theme'], self::THEMES, true)) {
$this->publicTheme = $this->theme = $queryParams['theme'];
} else {
$this->publicTheme = $this->settings->getPublicTheme() ?? $this->publicTheme;
$this->publicTheme = $this->settings->getPublicTheme();
if (null !== $this->user && !empty($this->user->getTheme())) {
$this->theme = (string)$this->user->getTheme();

View File

@ -220,7 +220,7 @@ class AuditLog implements EventSubscriber
Entity\AuditLog::OPER_INSERT,
get_class($owner),
$ownerIdentifier,
get_class($entity),
(string)get_class($entity),
$entityIdentifier,
[]
);
@ -231,7 +231,7 @@ class AuditLog implements EventSubscriber
Entity\AuditLog::OPER_DELETE,
get_class($owner),
$ownerIdentifier,
get_class($entity),
(string)get_class($entity),
$entityIdentifier,
[]
);

View File

@ -52,6 +52,6 @@ class Time
$this->utc_datetime = $now->format('Y-m-d g:i:s');
$this->utc_date = $now->format('F j, Y');
$this->utc_time = $now->format('g:ia');
$this->utc_json = $now->toJSON() ?? '';
$this->utc_json = $now->toJSON();
}
}

View File

@ -17,9 +17,9 @@ class Settings extends AbstractFixture
}
$settings = new Entity\Settings();
$settings->setBaseUrl((string)(getenv('INIT_BASE_URL') ?? 'docker.local'));
$settings->setInstanceName((string)(getenv('INIT_INSTANCE_NAME') ?? 'local test'));
$settings->setGeoliteLicenseKey((string)(getenv('INIT_GEOLITE_LICENSE_KEY') ?? ''));
$settings->setBaseUrl((string)(getenv('INIT_BASE_URL') ?: 'docker.local'));
$settings->setInstanceName((string)(getenv('INIT_INSTANCE_NAME') ?: 'local test'));
$settings->setGeoliteLicenseKey((string)(getenv('INIT_GEOLITE_LICENSE_KEY') ?: ''));
$settings->setSetupCompleteTime(time());
$settings->setPreferBrowserUrl(true);
@ -28,7 +28,7 @@ class Settings extends AbstractFixture
$settings->setExternalIp('127.0.0.1');
$settings->setEnableAdvancedFeatures(true);
$isDemoMode = (!empty(getenv('INIT_DEMO_API_KEY') ?? ''));
$isDemoMode = (!empty(getenv('INIT_DEMO_API_KEY') ?: ''));
if ($isDemoMode) {
$settings->setAnalytics(Entity\Analytics::LEVEL_NO_IP);
$settings->setCheckForUpdates(false);

View File

@ -72,9 +72,7 @@ class SettingsRepository extends Repository
$errors = $this->validator->validate($settingsObj);
if (count($errors) > 0) {
$e = new ValidationException((string)$errors);
$e->setDetailedErrors($errors);
throw $e;
throw ValidationException::fromValidationErrors($errors);
}
$this->em->persist($settings);

View File

@ -21,7 +21,13 @@ class QueueManager extends AbstractQueueManager
{
$pheanstalk = $this->pheanstalk->useTube($queueName);
while ($job = $pheanstalk->reserve()) {
while ($job = $pheanstalk->peekReady()) {
$pheanstalk->delete($job);
}
while ($job = $pheanstalk->peekBuried()) {
$pheanstalk->delete($job);
}
while ($job = $pheanstalk->peekDelayed()) {
$pheanstalk->delete($job);
}
}

View File

@ -62,7 +62,7 @@ class DoctrineEntityNormalizer extends AbstractNormalizer implements NormalizerA
return $this->handleCircularReference($object, $format, $context);
}
$context[self::CLASS_METADATA] = $this->em->getClassMetadata(get_class($object));
$context[self::CLASS_METADATA] = $this->em->getClassMetadata((string)get_class($object));
$props = $this->getAllowedAttributes($object, $context);
@ -247,7 +247,7 @@ class DoctrineEntityNormalizer extends AbstractNormalizer implements NormalizerA
if (count($prop_val) > 0) {
foreach ($prop_val as $val_obj) {
if ($form_mode) {
$id_field = $this->em->getClassMetadata(get_class($val_obj))->identifier;
$id_field = $this->em->getClassMetadata((string)get_class($val_obj))->identifier;
if ($id_field && count($id_field) === 1) {
$return_val[] = $this->getProperty($val_obj, $id_field[0]);

View File

@ -202,7 +202,7 @@ class AutoDJ
$startNext = $station->getBackendConfig()->getCrossfadeDuration();
$now = $now->addSeconds($duration ?? 1);
$now = $now->addSeconds($duration);
return ($duration >= $startNext)
? $now->subMilliseconds((int)($startNext * 1000))
: $now;

View File

@ -50,13 +50,13 @@ class File
}
$str = str_replace(' ', '_', $str);
return mb_strtolower($str) ?? '';
return mb_strtolower($str);
}
public static function generateTempPath(string $pattern = ''): string
{
$prefix = pathinfo($pattern, PATHINFO_FILENAME) ?? 'temp';
$extension = pathinfo($pattern, PATHINFO_EXTENSION) ?? 'log';
$prefix = pathinfo($pattern, PATHINFO_FILENAME) ?: 'temp';
$extension = pathinfo($pattern, PATHINFO_EXTENSION) ?: 'log';
$tempPath = tempnam(sys_get_temp_dir(), $prefix . '_') . '.' . $extension;
touch($tempPath);

View File

@ -72,7 +72,7 @@ class UniqueEntityValidator extends ConstraintValidator
return;
}
$class = $this->em->getClassMetadata(get_class($value));
$class = $this->em->getClassMetadata((string)get_class($value));
$criteria = [];
$hasNullValue = false;