Skip to content

Commit

Permalink
SA: Bump Psalm to level 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Apr 5, 2021
1 parent 574e7ad commit a08bc3b
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(array $typesConfig)
/**
* Create a connection by name.
*
* @param mixed[] $params
* @param string[]|Type[] $mappingTypes
* @param mixed[] $params
* @param array<string, string> $mappingTypes
*
* @return Connection
*
Expand Down
2 changes: 1 addition & 1 deletion DataCollector/DoctrineDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function getGroupedQueries()

private function executionTimePercentage(int $executionTimeMS, int $totalExecutionTimeMS): float
{
if ($totalExecutionTimeMS === 0.0 || $totalExecutionTimeMS === 0) {
if (! $totalExecutionTimeMS) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Configuration implements ConfigurationInterface
*/
public function __construct(bool $debug)
{
$this->debug = (bool) $debug;
$this->debug = $debug;
}

public function getConfigTreeBuilder(): TreeBuilder
Expand Down
10 changes: 1 addition & 9 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,9 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
}

/**
* @param mixed[] $connection
* @param array<string, mixed> $connection
*
* @return mixed[]
*
* @psalm-return T
* @psalm-param T
* @template T of array<string, mixed>
*/
protected function getConnectionOptions(array $connection): array
{
Expand Down Expand Up @@ -656,10 +652,6 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
return;
}

if (! isset($listenerDef)) {
throw new InvalidArgumentException('Entity listeners configuration requires doctrine-orm 2.5.0 or newer');
}

$entities = $entityManager['entity_listeners']['entities'];

foreach ($entities as $entityListenerClass => $entity) {
Expand Down
11 changes: 10 additions & 1 deletion Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Doctrine\Bundle\DoctrineBundle\Mapping;

use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory as BaseClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;

use function assert;

class ClassMetadataFactory extends BaseClassMetadataFactory
{
/**
Expand All @@ -15,12 +18,18 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
{
parent::doLoadMetadata($class, $parent, $rootEntityFound, $nonSuperclassParents);

if (! $class instanceof ClassMetadataInfo) {
return;
}

$customGeneratorDefinition = $class->customGeneratorDefinition;

if (! isset($customGeneratorDefinition['instance']) || ! $class instanceof ClassMetadataInfo) {
if (! isset($customGeneratorDefinition['instance'])) {
return;
}

assert($customGeneratorDefinition['instance'] instanceof AbstractIdGenerator);

$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM);
$class->setIdGenerator($customGeneratorDefinition['instance']);
unset($customGeneratorDefinition['instance']);
Expand Down
4 changes: 2 additions & 2 deletions Mapping/MappingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata): void
$this->driver->loadMetadataForClass($className, $metadata);

if (
$metadata->generatorType !== ClassMetadataInfo::GENERATOR_TYPE_CUSTOM
! $metadata instanceof ClassMetadataInfo
|| $metadata->generatorType !== ClassMetadataInfo::GENERATOR_TYPE_CUSTOM
|| ! isset($metadata->customGeneratorDefinition['class'])
|| ! $this->idGeneratorLocator->has($metadata->customGeneratorDefinition['class'])
|| ! $metadata instanceof ClassMetadataInfo
) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Exception;
use Throwable;

Expand All @@ -27,7 +28,7 @@ public function testContainer(): void
$params = ['driverClass' => FakeDriver::class];
$config = null;
$eventManager = null;
$mappingTypes = [0];
$mappingTypes = ['' => ''];
$exception = class_exists(Driver\AbstractDriverException::class) ?
new DriverException('', $this->createMock(Driver\AbstractDriverException::class)) :
new DriverException('', $this->createMock(Driver\AbstractException::class));
Expand Down Expand Up @@ -140,12 +141,12 @@ public function getDatabasePlatform(): AbstractPlatform
* @param string|null $password
* @param mixed[] $driverOptions
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = []): void
public function connect(array $params, $username = null, $password = null, array $driverOptions = []): Connection
{
throw new Exception('not implemented');
}

public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null): void
public function getSchemaManager(Connection $conn, ?AbstractPlatform $platform = null): AbstractSchemaManager
{
throw new Exception('not implemented');
}
Expand Down
5 changes: 0 additions & 5 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\ORM\EntityManagerInterface;
use Generator;
use InvalidArgumentException;
Expand Down Expand Up @@ -1447,10 +1446,6 @@ public function __construct(string $tableToIgnore)

public function __invoke(string $assetName): bool
{
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}

return $assetName !== $this->tableToIgnore;
}
}
2 changes: 0 additions & 2 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,6 @@ public function testShardManager(): void
*/
private function getContainer(array $bundles = ['YamlBundle'], string $vendor = ''): ContainerBuilder
{
$bundles = (array) $bundles;

$map = [];
foreach ($bundles as $bundle) {
require_once __DIR__ . '/Fixtures/Bundles/' . ($vendor ? $vendor . '/' : '') . $bundle . '/' . $bundle . '.php';
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/Fixtures/DbalTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
public function getProjectDir(): string
{
if ($this->projectDir === null) {
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand());
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand());
}

return $this->projectDir;
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependencyInjection/Fixtures/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
public function getProjectDir(): string
{
if ($this->projectDir === null) {
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand());
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand());
}

return $this->projectDir;
Expand Down
1 change: 1 addition & 0 deletions Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function setUp(): void
$this->twig->addExtension(new CodeExtension('', '', ''));
$this->twig->addExtension(new RoutingExtension($urlGenerator));
$this->twig->addExtension(new HttpKernelExtension());
/** @psalm-suppress InternalClass */
$this->twig->addExtension(new WebProfilerExtension());
$this->twig->addExtension(new DoctrineExtension());

Expand Down
2 changes: 1 addition & 1 deletion psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
errorLevel="4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down

0 comments on commit a08bc3b

Please sign in to comment.