Skip to content

Commit

Permalink
bump PHPStan level to 2
Browse files Browse the repository at this point in the history
added some tests (due to changes that where made because of PHPStan)
  • Loading branch information
vladyslavstartsev authored and greg0ire committed Jul 1, 2020
1 parent 3e834f8 commit 38b3377
Show file tree
Hide file tree
Showing 32 changed files with 666 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/qa.yaml
Expand Up @@ -11,4 +11,4 @@ jobs:
env:
REQUIRE_DEV: true
with:
args: analyse
args: analyse -c .phpstan/phpstan.neon.dist
134 changes: 134 additions & 0 deletions .phpstan/phpstan-baseline.neon
@@ -0,0 +1,134 @@
parameters:
ignoreErrors:
-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Datagrid\\\\PagerInterface\\:\\:isLastPage\\(\\)\\.$#"
count: 1
path: ../src/Action/RetrieveAutocompleteItemsAction.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Datagrid\\\\PagerInterface\\:\\:getPage\\(\\)\\.$#"
count: 1
path: ../src/Action/SearchAction.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Datagrid\\\\PagerInterface\\:\\:getNbResults\\(\\)\\.$#"
count: 1
path: ../src/Action/SearchAction.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Datagrid\\\\Datagrid\\:\\:addFilter\\(\\) should return Sonata\\\\AdminBundle\\\\Filter\\\\FilterInterface but return statement is missing\\.$#"
count: 1
path: ../src/Datagrid/Datagrid.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\FieldDescriptionInterface\\:\\:getLabel\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Datagrid/ListMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Constructor of class Sonata\\\\AdminBundle\\\\Form\\\\DataTransformer\\\\ModelsToArrayTransformer has an unused parameter \\$choiceList\\.$#"
count: 1
path: ../src/Form/DataTransformer/ModelsToArrayTransformer.php

-
# will be fixed in v4. Currently BC break
message: "#^Constructor of class Sonata\\\\AdminBundle\\\\Form\\\\DataTransformer\\\\ModelsToArrayTransformer has an unused parameter \\$class\\.$#"
count: 1
path: ../src/Form/DataTransformer/ModelsToArrayTransformer.php

-
# will be fixed in v4. Currently BC break
message: "#^Constructor of class Sonata\\\\AdminBundle\\\\Form\\\\DataTransformer\\\\ModelsToArrayTransformer has an unused parameter \\$modelManager\\.$#"
count: 1
path: ../src/Form/DataTransformer/ModelsToArrayTransformer.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getFormGroups\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Form/FormMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getFormTabs\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Form/FormMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\FieldDescriptionInterface\\:\\:getLabel\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Show/ShowMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getShowGroups\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Show/ShowMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getShowTabs\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: ../src/Show/ShowMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Translator\\\\Extractor\\\\JMSTranslatorBundle\\\\AdminExtractor\\:\\:buildSecurityInformation\\(\\) should return array\\<string, mixed\\> but return statement is missing\\.$#"
count: 1
path: ../src/Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php

-
# will be fixed in v4. Currently BC break
message: "#^Method Sonata\\\\AdminBundle\\\\Translator\\\\Extractor\\\\JMSTranslatorBundle\\\\AdminExtractor\\:\\:getBaseRole\\(\\) should return string but return statement is missing\\.$#"
count: 1
path: ../src/Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php

# next 6 errors are due to not installed Doctrine ORM\ODM
-
message: "#^Class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection not found\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

-
message: "#^Class Doctrine\\\\ORM\\\\PersistentCollection not found\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

-
message: "#^Call to method getTypeClass\\(\\) on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

-
message: "#^Call to method getTypeClass\\(\\) on an unknown class Doctrine\\\\ORM\\\\PersistentCollection\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

-
message: "#^Call to method add\\(\\) on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

-
message: "#^Call to method add\\(\\) on an unknown class Doctrine\\\\ORM\\\\PersistentCollection\\.$#"
count: 1
path: ../src/Admin/AdminHelper.php

# Symfony related errors
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:arrayNode\\(\\)\\.$#"
count: 1
path: ../src/DependencyInjection/Configuration.php

-
# Symfony BC break policy
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: ../src/Menu/MenuBuilder.php
16 changes: 16 additions & 0 deletions .phpstan/phpstan.neon.dist
@@ -0,0 +1,16 @@
includes:
- phpstan-baseline.neon

parameters:
level: 2

paths:
- ../src
excludes_analyse:
# temporarily ignore template files
- ../src/Resources/**.tpl.php
scanFiles:
# NEXT_MAJOR: Remove those files
- stubs/MetadataInterface.file
- stubs/Exporter.file
- stubs/TextExtension.file
48 changes: 48 additions & 0 deletions .phpstan/stubs/Exporter.file
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\Exporter;

use Sonata\Exporter\Handler;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Sonata\Exporter\Writer\CsvWriter;
use Sonata\Exporter\Writer\JsonWriter;
use Sonata\Exporter\Writer\XlsWriter;
use Sonata\Exporter\Writer\XmlWriter;
use Symfony\Component\HttpFoundation\StreamedResponse;

@trigger_error(
'The '.__NAMESPACE__.'\Exporter class is deprecated since version 3.1 and will be removed in 4.0.'.
' Use Sonata\Exporter\Exporter instead',
E_USER_DEPRECATED
);

/**
* NEXT_MAJOR: Remove this stub when Exporter file doesn't need the CoreBundle dependency
*
* @deprecated since sonata-project/core-bundle 3.19, to be removed in 4.0.
*/
class Exporter
{
/**
* @param string $format
* @param string $filename
*
* @throws \RuntimeException
*
* @return StreamedResponse
*/
public function getResponse($format, $filename, SourceIteratorInterface $source)
{
}
}
57 changes: 57 additions & 0 deletions .phpstan/stubs/MetadataInterface.file
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\Model;

/**
* NEXT_MAJOR: Remove this stub when MetadataInterface file doesn't need the CoreBundle dependency
*
* @author Hugo Briand <briand@ekino.com>
*
* @deprecated since sonata-project/core-bundle 3.13.0, to be removed in 4.0. Use Sonata\BlockBundle\Meta\MetadataInterface instead.
*/
interface MetadataInterface
{
/**
* @return string
*/
public function getTitle();

/**
* @return string
*/
public function getDescription();

/**
* @return mixed
*/
public function getImage();

/**
* @return string
*/
public function getDomain();

/**
* @return array
*/
public function getOptions();

/**
* @param string $name The option key
* @param mixed $default The default value if option not found
*
* @return mixed
*/
public function getOption($name, $default = null);
}
40 changes: 40 additions & 0 deletions .phpstan/stubs/TextExtension.file
@@ -0,0 +1,40 @@
<?php

/**
* NEXT_MAJOR: Remove this stub when StringExtension and DeprecatedTextExtension files doesn't need the Twig\Extensions dependency
* This file is part of Twig.
*
* (c) 2009-2019 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extensions
{
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* @author Henrik Bjornskov <hb@peytz.dk>
*/
class TextExtension extends AbstractExtension
{
public function getFilters()
{
}
}
}

namespace
{
use Twig\Environment;

function twig_truncate_filter(Environment $env, $value, $length = 30, $preserve = false, $separator = '...')
{
}

function twig_wordwrap_filter(Environment $env, $value, $length = 80, $separator = "\n", $preserve = false)
{
}
}
11 changes: 0 additions & 11 deletions phpstan-baseline.neon

This file was deleted.

10 changes: 0 additions & 10 deletions phpstan.neon.dist

This file was deleted.

1 change: 1 addition & 0 deletions src/Action/SetObjectFieldValueAction.php
Expand Up @@ -159,6 +159,7 @@ public function __invoke(Request $request): JsonResponse
// render the widget
// todo : fix this, the twig environment variable is not set inside the extension ...
$extension = $this->twig->getExtension(SonataAdminExtension::class);
\assert($extension instanceof SonataAdminExtension);

$content = $extension->renderListElement($this->twig, $rootObject, $fieldDescription);

Expand Down
11 changes: 11 additions & 0 deletions src/Admin/AbstractAdmin.php
Expand Up @@ -51,6 +51,7 @@
use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Mapping\GenericMetadata;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
Expand Down Expand Up @@ -3410,6 +3411,16 @@ protected function attachInlineValidator()

// add the custom inline validation option
$metadata = $this->validator->getMetadataFor($this->getClass());
if (!$metadata instanceof GenericMetadata) {
throw new \UnexpectedValueException(
sprintf(
'Cannot add inline validator for %s because its metadata is an instance of %s instead of %s',
$this->getClass(),
\get_class($metadata),
GenericMetadata::class
)
);
}

$metadata->addConstraint(new InlineConstraint([
'service' => $this,
Expand Down

0 comments on commit 38b3377

Please sign in to comment.