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 Level 2 #6161

Merged
merged 1 commit into from
Jul 1, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
env:
REQUIRE_DEV: true
with:
args: analyse
args: analyse -c .phpstan/phpstan.neon.dist
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved phpstan related things to .phpstan folder. Because It will be too much filles in the root (phpstan.neon.dist, phpstan-baseline.neon, 3 files that can't be resolved because of CoreBundle)

134 changes: 134 additions & 0 deletions .phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* 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 <[email protected]>
*
* @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
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading