Skip to content

Commit

Permalink
bump PHPStan level to 2
Browse files Browse the repository at this point in the history
add extra files to export-ignore
  • Loading branch information
vv12131415 committed Jun 21, 2020
1 parent 70e1e48 commit 85525d9
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
*.md export-ignore
tests export-ignore
docs export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
195 changes: 195 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,168 @@
parameters:
ignoreErrors:
-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:setFilterPersister\\(\\)\\.$#"
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\\:\\: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: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getBaseRoutePattern\\(\\)\\.$#"
count: 1
path: src/Admin/AbstractAdmin.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getBaseRouteName\\(\\)\\.$#"
count: 2
path: src/Admin/AbstractAdmin.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getSideMenu\\(\\)\\.$#"
count: 1
path: src/Admin/AbstractAdmin.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:addParentAssociationMapping\\(\\)\\.$#"
count: 1
path: src/Admin/AbstractAdmin.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getRouteGenerator\\(\\)\\.$#"
count: 1
path: src/Admin/BreadcrumbsBuilder.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getClassnameLabel\\(\\)\\.$#"
count: 2
path: src/Admin/BreadcrumbsBuilder.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getCurrentChildAdmin\\(\\)\\.$#"
count: 1
path: src/Admin/BreadcrumbsBuilder.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:getParentAssociationMapping\\(\\)\\.$#"
count: 2
path: src/Controller/CRUDController.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: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:reorderFormGroup\\(\\)\\.$#"
count: 1
path: src/Form/FormMapper.php

-
# will be fixed in v4. Currently BC break
message: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\FieldDescriptionInterface\\:\\:setHelp\\(\\)\\.$#"
count: 2
path: src/Form/FormMapper.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: "#^Call to an undefined method Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface\\:\\:defineFormBuilder\\(\\)\\.$#"
count: 1
path: src/Form/Type/AdminType.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
Expand All @@ -9,3 +172,35 @@ parameters:
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
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 0
level: 2

paths:
- src
Expand Down
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
2 changes: 2 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,7 @@ protected function attachInlineValidator()

// add the custom inline validation option
$metadata = $this->validator->getMetadataFor($this->getClass());
\assert($metadata instanceof GenericMetadata);

$metadata->addConstraint(new InlineConstraint([
'service' => $this,
Expand Down
57 changes: 57 additions & 0 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public function getIdParameter();
*/
public function hasRoute($name);

/**
* @return void
*/
public function setSecurityHandler(SecurityHandlerInterface $securityHandler);

/**
Expand Down Expand Up @@ -726,6 +729,60 @@ public function getListMode();
*/
// NEXT_MAJOR: uncomment this method in 4.0
// public function isDefaultFilter(string $name): bool;

// NEXT_MAJOR: uncomment this method in 4.0
// public function setFilterPersister(?\Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface\FilterPersisterInterface $filterPersister = null): void;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Returns the baseRoutePattern used to generate the routing information.
// */
// public function getBaseRoutePattern(): string;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Returns the baseRouteName used to generate the routing information.
// */
// public function getBaseRouteName(): string;

// NEXT_MAJOR: uncomment this method in 4.0
// public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): \Knp\Menu\ItemInterface;

// NEXT_MAJOR: uncomment this method in 4.0
// public function addParentAssociationMapping(string $code, string $value): void;

// NEXT_MAJOR: uncomment this method in 4.0
// public function getRouteGenerator(): \Sonata\AdminBundle\Route\RouteGeneratorInterface;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Returns the classname label.
// */
// public function getClassnameLabel(): string;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Returns the current child admin instance.
// */
// public function getCurrentChildAdmin(): ?AdminInterface;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Returns the name of the parent related field, so the field can be use to set the default
// * value (ie the parent object) or to filter the object.
// *
// */
// public function getParentAssociationMapping(): ?string;

// NEXT_MAJOR: uncomment this method in 4.0
// public function reorderFormGroup(string $group, array $keys): void;

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * This method is being called by the main admin class and the child class,
// * the getFormBuilder is only call by the main admin class.
// */
// public function defineFormBuilder(FormBuilderInterface $formBuilder): void;
}

class_exists(\Sonata\Form\Validator\ErrorElement::class);
6 changes: 6 additions & 0 deletions src/Admin/FieldDescriptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,10 @@ public function getSortParentAssociationMapping();
* @return mixed
*/
public function getFieldValue($object, $fieldName);

// NEXT_MAJOR: uncomment this method in 4.0
// /**
// * Defines the help message.
// */
// public function setHelp(string $help): void;
}
2 changes: 2 additions & 0 deletions src/Command/ExplainAdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;

/**
Expand Down Expand Up @@ -118,6 +119,7 @@ public function execute(InputInterface $input, OutputInterface $output)
}

$metadata = $this->validator->getMetadataFor($admin->getClass());
\assert($metadata instanceof ClassMetadata);

$output->writeln('');
$output->writeln('<comment>Validation Framework</comment> - http://symfony.com/doc/3.0/book/validation.html');
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CRUDController implements ContainerAwareInterface
ControllerTrait::render as originalRender;
}

/**
* @var ContainerInterface
*/
protected $container;

/**
* The related Admin class.
*
Expand Down Expand Up @@ -1011,7 +1016,7 @@ public function aclAction($deprecatedId = null) // NEXT_MAJOR: Remove the unused
$updateMethod = 'updateAclRoles';
}

if (isset($form)) {
if (isset($form, $updateMethod)) {
$form->handleRequest($request);

if ($form->isValid()) {
Expand Down
5 changes: 5 additions & 0 deletions src/Datagrid/DatagridMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class DatagridMapper extends BaseMapper
*/
protected $datagrid;

/**
* @var DatagridBuilderInterface
*/
protected $builder;

public function __construct(
DatagridBuilderInterface $datagridBuilder,
DatagridInterface $datagrid,
Expand Down
5 changes: 5 additions & 0 deletions src/Datagrid/ListMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class ListMapper extends BaseMapper
*/
protected $list;

/**
* @var ListBuilderInterface
*/
protected $builder;

public function __construct(
ListBuilderInterface $listBuilder,
FieldDescriptionCollection $list,
Expand Down
Loading

0 comments on commit 85525d9

Please sign in to comment.