Fix or individually ignore the errors in the PHPstan baseline.

This commit is contained in:
Buster Neece 2023-12-01 01:18:57 -06:00
parent 6fbb9b0165
commit 5004f54b96
No known key found for this signature in database
10 changed files with 113 additions and 88 deletions

View File

@ -1,72 +1,2 @@
parameters:
ignoreErrors:
-
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: "#^Method App\\\\Normalizer\\\\DoctrineEntityNormalizer\\:\\:getAllowedAttributes\\(\\) should return array\\|false but returns array\\<string\\|Symfony\\\\Component\\\\Serializer\\\\Mapping\\\\AttributeMetadataInterface\\>\\|bool\\.$#"
count: 1
path: src/Normalizer/DoctrineEntityNormalizer.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: "#^Access to an undefined property XMLReader\\:\\:\\$depth\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$hasAttributes\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$isEmptyElement\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$localName\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$name\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$nodeType\\.$#"
count: 1
path: src/Xml/Reader.php
-
message: "#^Access to an undefined property XMLReader\\:\\:\\$value\\.$#"
count: 2
path: src/Xml/Reader.php

View File

@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace App\Entity\Migration\Traits;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
trait UpdateAllRecords
{
/** @var Connection */
protected $connection;
/**
* Executes an SQL UPDATE statement on a table.
*
* Table expression and columns are not escaped and are not safe for user-input.
*
* @param string $table Table name
* @param array<string, mixed> $data Column-value pairs
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
*
* @throws Exception
*/
public function updateAllRecords(
string $table,
array $data,
array $types = []
): int|string {
$columns = $values = $set = [];
foreach ($data as $columnName => $value) {
$columns[] = $columnName;
$values[] = $value;
$set[] = $columnName . ' = ?';
}
if (is_string(key($types))) {
$types = $this->extractTypeValues($columns, $types);
}
$sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $set);
return $this->connection->executeStatement($sql, $values, $types);
}
/**
* Extract ordered type list from an ordered column list and type map.
*
* @param array<int, string> $columnList
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types
*
* @return array<int, int|string|Type|null>|array<string, int|string|Type|null>
*/
private function extractTypeValues(array $columnList, array $types): array
{
$typeValues = [];
foreach ($columnList as $columnName) {
$typeValues[] = $types[$columnName] ?? ParameterType::STRING;
}
return $typeValues;
}
}

View File

@ -4,14 +4,14 @@ declare(strict_types=1);
namespace App\Entity\Migration;
use App\Entity\Migration\Traits\UpdateAllRecords;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180412055024 extends AbstractMigration
{
use UpdateAllRecords;
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE station_playlists ADD source VARCHAR(50) NOT NULL, ADD include_in_requests TINYINT(1) NOT NULL');
@ -19,13 +19,13 @@ final class Version20180412055024 extends AbstractMigration
public function postup(Schema $schema): void
{
$this->connection->update('station_playlists', [
'include_in_requests' => 1,
], ['type' => 'default']);
$this->updateAllRecords('station_playlists', [
'include_in_requests' => '1',
]);
$this->connection->update('station_playlists', [
$this->updateAllRecords('station_playlists', [
'source' => 'default',
], [1 => 1]);
]);
}
public function down(Schema $schema): void

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Entity\Migration;
use App\Entity\Migration\Traits\UpdateAllRecords;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
@ -12,6 +13,8 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20180429013130 extends AbstractMigration
{
use UpdateAllRecords;
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE station_playlists ADD playback_order VARCHAR(50) NOT NULL, ADD remote_url VARCHAR(255) DEFAULT NULL');
@ -19,10 +22,10 @@ final class Version20180429013130 extends AbstractMigration
public function postup(Schema $schema): void
{
$this->connection->update('station_playlists', [
$this->updateAllRecords('station_playlists', [
'source' => 'songs',
'playback_order' => 'random',
], [1 => 1]);
]);
}
public function down(Schema $schema): void

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Entity\Migration;
use App\Entity\Migration\Traits\UpdateAllRecords;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
@ -12,6 +13,8 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20180818223558 extends AbstractMigration
{
use UpdateAllRecords;
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE station ADD api_history_items SMALLINT NOT NULL');
@ -19,9 +22,9 @@ final class Version20180818223558 extends AbstractMigration
public function postup(Schema $schema): void
{
$this->connection->update('station', [
$this->updateAllRecords('station', [
'api_history_items' => 5,
], [1 => 1]);
]);
}
public function down(Schema $schema): void

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Entity\Migration;
use App\Entity\Migration\Traits\UpdateAllRecords;
use DateTime;
use DateTimeZone;
use Doctrine\DBAL\Schema\Schema;
@ -14,6 +15,8 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20190513163051 extends AbstractMigration
{
use UpdateAllRecords;
public function up(Schema $schema): void
{
// Move "play once per day" playlists to be standard scheduled ones with the same start/end time.
@ -36,9 +39,9 @@ final class Version20190513163051 extends AbstractMigration
}
// Set all stations' timezones to this value.
$this->connection->update('station', [
$this->updateAllRecords('station', [
'timezone' => $globalTz,
], [1 => 1]);
]);
// Calculate the offset of any currently scheduled playlists.
if ('UTC' !== $globalTz) {

View File

@ -74,7 +74,11 @@ final class Version20201204043539 extends AbstractMigration
}
);
$this->connection->delete('settings', [1 => 1]);
$this->connection->executeStatement(
<<<'SQL'
DELETE FROM settings
SQL
);
foreach ($newSettings as $settingKey => $settingValue) {
$this->connection->insert('settings', [

View File

@ -14,6 +14,7 @@ use InvalidArgumentException;
use ReflectionClass;
use ReflectionException;
use ReflectionProperty;
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
@ -130,13 +131,13 @@ final class DoctrineEntityNormalizer extends AbstractObjectNormalizer
* @param object|class-string<object> $classOrObject
* @param array $context
* @param bool $attributesAsString
* @return array|false
* @return string[]|AttributeMetadataInterface[]|bool
*/
protected function getAllowedAttributes(
$classOrObject,
array $context,
bool $attributesAsString = false
): array|false {
): array|bool {
$groups = $this->getGroups($context);
if (empty($groups)) {
return false;

View File

@ -19,6 +19,7 @@ use DateTimeInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Iterator;
use IteratorAggregate;
use RuntimeException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@ -124,7 +125,11 @@ final class UniqueEntityValidator extends ConstraintValidator
);
}
} else {
$repository = $this->em->getRepository(get_class($value));
$repoClass = get_class($value);
if (!$repoClass) {
throw new RuntimeException('Invalid class specified.');
}
$repository = $this->em->getRepository($repoClass);
}
$result = $repository->{$constraint->repositoryMethod}($criteria);

View File

@ -64,14 +64,18 @@ final class Reader
$text = '';
while ($reader->read()) {
// @phpstan-ignore-next-line
if ($reader->nodeType === XMLReader::ELEMENT) {
// @phpstan-ignore-next-line
if ($reader->depth === 0) {
return self::processNextElement($reader);
}
$attributes = self::getAttributes($reader);
// @phpstan-ignore-next-line
$name = $reader->name;
// @phpstan-ignore-next-line
if ($reader->isEmptyElement) {
$child = [];
} else {
@ -102,6 +106,7 @@ final class Reader
} elseif ($reader->nodeType === XMLReader::END_ELEMENT) {
break;
} elseif (in_array($reader->nodeType, self::$textNodes)) {
// @phpstan-ignore-next-line
$text .= $reader->value;
}
}
@ -118,8 +123,10 @@ final class Reader
{
$attributes = [];
// @phpstan-ignore-next-line
if ($reader->hasAttributes) {
while ($reader->moveToNextAttribute()) {
// @phpstan-ignore-next-line
$attributes['@' . $reader->localName] = $reader->value;
}