Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan 1.0 and Psalm level 2 #1569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'php_unit_test_annotation' => false,
'php_unit_test_case_static_method_calls' => true,
'phpdoc_order' => true,
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']],
'single_line_throw' => false,
'static_lambda' => true,
'strict_comparison' => true,
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.52",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.10",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^3.0",
Expand All @@ -71,7 +71,7 @@
"symfony/templating": "^4.4 || ^5.3",
"symfony/yaml": "^4.4 || ^5.3",
"vimeo/psalm": "^4.1.1",
"weirdan/doctrine-psalm-plugin": "^1.0"
"weirdan/doctrine-psalm-plugin": "^2.0"
},
"suggest": {
"sonata-project/entity-audit-bundle": "If you want to support for versioning of entities and their associations."
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ parameters:
message: '#Method Sonata\\DoctrineORMAdminBundle\\Model\\ModelManager::getMetadata\(\) should return Doctrine\\ORM\\Mapping\\ClassMetadata\<TObject of object\> but returns Doctrine\\ORM\\Mapping\\ClassMetadata\<object\>\.$#'
path: src/Model/ModelManager.php
- # https://github.com/phpstan/phpstan-strict-rules/issues/131
message: '#^Call to function in_array\(\) with arguments (0|1), array<int, 0\|1>&nonEmpty and true will always evaluate to true\.$#'
message: '#^Call to function in_array\(\) with arguments (0|1), non-empty-array<int, 0\|1> and true will always evaluate to true\.$#'
path: src/Filter/BooleanFilter.php
4 changes: 3 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ includes:
- phpstan-baseline.neon

parameters:
level: max
level: 8
paths:
- src
- tests
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: true
checkInternalClassCaseSensitivity: true
checkMissingIterableValueType: true
checkMissingVarTagTypehint: true
checkMissingTypehints: true
checkUninitializedProperties: true
7 changes: 6 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="3" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand All @@ -12,4 +12,9 @@
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<!-- Psalm equivalent of PHPStan config `treatPhpDocTypesAsCertain: false` -->
<DocblockTypeContradiction errorLevel="suppress"/>
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
</issueHandlers>
</psalm>
11 changes: 10 additions & 1 deletion src/Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

/**
* @phpstan-implements DatagridBuilderInterface<ProxyQueryInterface>
* @psalm-suppress DeprecatedInterface
*
* @see https://github.com/sonata-project/SonataAdminBundle/pull/7519
*/
final class DatagridBuilder implements DatagridBuilderInterface
{
Expand Down Expand Up @@ -93,7 +96,13 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
]);
}

// NEXT_MAJOR: Remove the ModelAutocompleteFilter::class check
/**
* NEXT_MAJOR: Remove the ModelAutocompleteFilter::class check.
*
* @psalm-suppress DeprecatedClass
*
* @see https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1545
*/
if (
ModelAutocompleteFilter::class === $fieldDescription->getType() && null === $fieldDescription->getOption('field_type')
|| ModelAutocompleteType::class === $fieldDescription->getOption('field_type')
Expand Down
5 changes: 5 additions & 0 deletions src/Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

use Sonata\AdminBundle\Builder\AbstractFormContractor;

/**
* @psalm-suppress DeprecatedInterface
*
* @see https://github.com/sonata-project/SonataAdminBundle/pull/7519
*/
final class FormContractor extends AbstractFormContractor
{
}
5 changes: 5 additions & 0 deletions src/Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
use Sonata\AdminBundle\FieldDescription\TypeGuesserInterface;

/**
* @psalm-suppress DeprecatedInterface
*
* @see https://github.com/sonata-project/SonataAdminBundle/pull/7519
*/
final class ListBuilder implements ListBuilderInterface
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
use Sonata\AdminBundle\FieldDescription\TypeGuesserInterface;

/**
* @psalm-suppress DeprecatedInterface
*
* @see https://github.com/sonata-project/SonataAdminBundle/pull/7519
*/
final class ShowBuilder implements ShowBuilderInterface
{
/**
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/doctrine_orm_filter_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
$services->set('sonata.admin.orm.filter.type.datetime_range', DateTimeRangeFilter::class)
->tag('sonata.admin.filter.type', ['alias' => 'doctrine_orm_datetime_range']);

/**
* NEXT_MAJOR: Remove this service definition.
*
* @psalm-suppress DeprecatedClass
*
* @see https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1545
*/
$services->set('sonata.admin.orm.filter.type.model_autocomplete', ModelAutocompleteFilter::class)
->tag('sonata.admin.filter.type', ['alias' => 'doctrine_orm_model_autocomplete']);

Expand Down
7 changes: 7 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @see https://github.com/psalm/psalm-plugin-symfony/pull/220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if it gets solved, the PR I linked it has the problem described as the last message too.

*/
final class AppKernel extends Kernel
{
use MicroKernelTrait;
Expand Down Expand Up @@ -78,6 +83,8 @@ public function getProjectDir(): string
/**
* TODO: Drop RouteCollectionBuilder when support for Symfony < 5.1 is dropped.
*
* @psalm-suppress DeprecatedClass
*
* @param RoutingConfigurator|RouteCollectionBuilder $routes
*/
protected function configureRoutes($routes): void
Expand Down
2 changes: 1 addition & 1 deletion tests/App/Entity/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Reader
*
* @var int|null
*/
private $id;
public $id;

public function __construct()
{
Expand Down
15 changes: 15 additions & 0 deletions tests/Filter/FilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,27 @@ final protected function createQueryBuilderStub(): TestQueryBuilder
$queryBuilder = $this->createStub(TestQueryBuilder::class);

$queryBuilder->method('setParameter')->willReturnCallback(
/**
* @param mixed $value
*/
static function (string $name, $value) use ($queryBuilder): void {
$queryBuilder->queryParameters[$name] = $value;
}
);

$queryBuilder->method('andWhere')->willReturnCallback(
/**
* @param mixed $query
*/
static function ($query) use ($queryBuilder): void {
$queryBuilder->query[] = sprintf('WHERE %s', $query);
}
);

$queryBuilder->method('andHaving')->willReturnCallback(
/**
* @param mixed $query
*/
static function ($query) use ($queryBuilder): void {
$queryBuilder->query[] = sprintf('HAVING %s', $query);
}
Expand Down Expand Up @@ -120,6 +129,9 @@ static function (): Andx {
);

$expr->method('in')->willReturnCallback(
/**
* @param mixed $parameter
*/
static function (string $alias, $parameter): string {
if (\is_array($parameter)) {
return sprintf('%s IN ("%s")', $alias, implode(', ', $parameter));
Expand All @@ -130,6 +142,9 @@ static function (string $alias, $parameter): string {
);

$expr->method('notIn')->willReturnCallback(
/**
* @param mixed $parameter
*/
static function (string $alias, $parameter): string {
if (\is_array($parameter)) {
return sprintf('%s NOT IN ("%s")', $alias, implode(', ', $parameter));
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixtures/Entity/AssociatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
final class AssociatedEntity
{
/**
* @var int
* @var Embeddable\EmbeddedEntity
*/
private $plainField;
public $embeddedEntity;

/**
* @var Embeddable\EmbeddedEntity
* @var int
*/
private $embeddedEntity;
private $plainField;

public function __construct(Embeddable\EmbeddedEntity $embeddedEntity, int $plainField)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Fixtures/Entity/ContainerEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ final class ContainerEntity
/**
* @var int|null
*/
private $plainField;
public $plainField;

/**
* @var AssociatedEntity
* @var Embeddable\EmbeddedEntity
*/
private $associatedEntity;
public $embeddedEntity;

/**
* @var Embeddable\EmbeddedEntity
* @var AssociatedEntity
*/
private $embeddedEntity;
private $associatedEntity;

public function __construct(AssociatedEntity $associatedEntity, Embeddable\EmbeddedEntity $embeddedEntity)
{
Expand Down
16 changes: 8 additions & 8 deletions tests/Fixtures/Entity/DoubleNameEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
/** @Entity */
final class DoubleNameEntity
{
/**
* @Id
* @Column(type="integer")
*
* @var int
*/
public $id;

/**
* @Column(type="string")
*
Expand All @@ -34,14 +42,6 @@ final class DoubleNameEntity
*/
public $name2;

/**
* @Id
* @Column(type="integer")
*
* @var int
*/
private $id;

public function __construct(int $id, string $name, ?string $name2)
{
$this->id = $id;
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/ModelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public function testAddIdentifiersToQuery(array $expectedParameters, array $iden
/** @var QueryBuilder&MockObject $queryBuilder */
$queryBuilder = $this->getMockBuilder(QueryBuilder::class)
->setConstructorArgs([$em])
->setMethodsExcept(['getParameters', 'setParameter'])
->onlyMethods(['getRootAliases', 'andWhere'])
->getMock();

$queryBuilder
Expand Down