Skip to content

Commit

Permalink
Improve static analysis (#698)
Browse files Browse the repository at this point in the history
* Improve static analysis

* Improve composer.json

* Fix tests
  • Loading branch information
jordisala1991 committed Nov 6, 2021
1 parent 5d49c8e commit ca99973
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 52 deletions.
17 changes: 7 additions & 10 deletions composer.json
Expand Up @@ -44,27 +44,24 @@
"conflict": {
"sonata-project/block-bundle": "<4.2"
},
"provide": {
"sonata-project/admin-bundle-persistency-layer": "1.0.0"
},
"require-dev": {
"doctrine/annotations": "^1.10",
"doctrine/data-fixtures": "^1.4",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.52",
"phpstan/phpstan-phpunit": "^0.12.17",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.20",
"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.15.1",
"psalm/plugin-symfony": "^2.0",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^3.0",
"sonata-project/block-bundle": "^4.2",
"symfony/browser-kit": "^4.4 || ^5.3",
"symfony/css-selector": "^4.4 || ^5.3",
"symfony/panther": "^1.0",
"symfony/phpunit-bridge": "^5.1.8",
"symfony/phpunit-bridge": "^5.3",
"vimeo/psalm": "^4.1.1"
},
"config": {
Expand Down
10 changes: 7 additions & 3 deletions phpstan.neon.dist
Expand Up @@ -2,10 +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
10 changes: 1 addition & 9 deletions psalm.xml
@@ -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="2" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<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">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand All @@ -11,12 +11,4 @@
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
<issueHandlers>
<InvalidArgument>
<errorLevel type="suppress">
<!-- TODO: This will be fixed when regex would allow as an expression -->
<file name="src/Filter/StringFilter.php"/>
</errorLevel>
</InvalidArgument>
</issueHandlers>
</psalm>
3 changes: 3 additions & 0 deletions src/Builder/DatagridBuilder.php
Expand Up @@ -30,6 +30,9 @@

/**
* @phpstan-implements DatagridBuilderInterface<ProxyQueryInterface>
* @psalm-suppress DeprecatedInterface
*
* @see https://github.com/sonata-project/SonataAdminBundle/pull/7519
*/
final class DatagridBuilder implements DatagridBuilderInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Builder/FormContractor.php
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
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 ListBuilder implements ListBuilderInterface
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Builder/ShowBuilder.php
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
2 changes: 0 additions & 2 deletions src/FieldDescription/FieldDescriptionFactory.php
Expand Up @@ -46,8 +46,6 @@ public function create(string $class, string $name, array $options = []): FieldD
}

/**
* @psalm-suppress RedundantConditionGivenDocblockType see https://github.com/doctrine/mongodb-odm/issues/2325
*
* @phpstan-param class-string $baseClass
*
* @phpstan-return array{
Expand Down
5 changes: 5 additions & 0 deletions tests/App/AppKernel.php
Expand Up @@ -32,6 +32,11 @@
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @see https://github.com/psalm/psalm-plugin-symfony/pull/220
*/
final class AppKernel extends Kernel
{
use MicroKernelTrait;
Expand Down
3 changes: 2 additions & 1 deletion tests/Builder/ListBuilderTest.php
Expand Up @@ -51,8 +51,9 @@ final class ListBuilderTest extends AbstractModelManagerTestCase

protected function setUp(): void
{
$this->typeGuesser = $this->createStub(TypeGuesserInterface::class);
parent::setUp();

$this->typeGuesser = $this->createStub(TypeGuesserInterface::class);
$this->admin = $this->createMock(AdminInterface::class);

$this->listBuilder = new ListBuilder($this->typeGuesser, [
Expand Down
12 changes: 6 additions & 6 deletions tests/Fixtures/Document/AssociatedDocument.php
Expand Up @@ -21,18 +21,18 @@
class AssociatedDocument
{
/**
* @ODM\Field(type="int")
* @ODM\EmbedOne(targetDocument=EmbeddedDocument::class)
*
* @var int
* @var EmbeddedDocument
*/
private $plainField;
public $embeddedDocument;

/**
* @ODM\EmbedOne(targetDocument=EmbeddedDocument::class)
* @ODM\Field(type="int")
*
* @var EmbeddedDocument
* @var int
*/
private $embeddedDocument;
private $plainField;

public function __construct(int $plainField, EmbeddedDocument $embeddedDocument)
{
Expand Down
14 changes: 7 additions & 7 deletions tests/Fixtures/Document/ContainerDocument.php
Expand Up @@ -20,6 +20,13 @@
*/
class ContainerDocument
{
/**
* @ODM\EmbedOne(targetDocument=EmbeddedDocument::class)
*
* @var EmbeddedDocument
*/
public $embeddedDocument;

/**
* @ODM\Field(type="int")
*
Expand All @@ -34,13 +41,6 @@ class ContainerDocument
*/
private $associatedDocument;

/**
* @ODM\EmbedOne(targetDocument=EmbeddedDocument::class)
*
* @var EmbeddedDocument
*/
private $embeddedDocument;

public function __construct(AssociatedDocument $associatedDocument, EmbeddedDocument $embeddedDocument)
{
$this->associatedDocument = $associatedDocument;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Document/DocumentForAcl.php
Expand Up @@ -25,7 +25,7 @@ class DocumentForAcl
*
* @var string|null
*/
private $id;
public $id;

public function getId(): ?string
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Fixtures/Document/DocumentWithReferences.php
Expand Up @@ -25,35 +25,35 @@ class DocumentWithReferences
*
* @var string|null
*/
private $id;
public $id;

/**
* @ODM\Field(type="string")
*
* @var string
*/
private $name;
public $name;

/**
* @ODM\EmbedOne()
*
* @var EmbeddedDocument|null
*/
private $embeddedDocument;
public $embeddedDocument;

/**
* @ODM\EmbedMany()
*
* @var Collection<array-key, EmbeddedDocument>
*/
private $embeddedDocuments;
public $embeddedDocuments;

/**
* @ODM\ReferenceOne(targetDocument=TestDocument::class)
*
* @var TestDocument|null
*/
private $referenceOne;
public $referenceOne;

public function __construct(string $name, ?EmbeddedDocument $embeddedDocument = null)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Document/EmbeddedDocument.php
Expand Up @@ -31,7 +31,7 @@ class EmbeddedDocument
*
* @var bool
*/
private $plainField = true;
public $plainField = true;

public function __construct(int $position = 0)
{
Expand Down
19 changes: 12 additions & 7 deletions tests/Fixtures/Document/TestDocument.php
Expand Up @@ -31,22 +31,27 @@ class TestDocument
* @ODM\Field(type="int")
*
* @var int
*
* @phpstan-ignore-next-line
*
* This property is private on purpose, to test an error is thrown
* when trying to reverse transform it on ModelManager.
*/
private $schmeckles = 0;
private $plumbus = 0;

/**
* @ODM\Field(type="string")
* @ODM\Field(type="int")
*
* @var string
* @var int
*/
private $multiWordProperty = '';
private $schmeckles = 0;

/**
* @ODM\Field(type="int")
* @ODM\Field(type="string")
*
* @var int
* @var string
*/
private $plumbus = 0;
private $multiWordProperty = '';

public function getSchmeckles(): int
{
Expand Down

0 comments on commit ca99973

Please sign in to comment.