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
added some tests (due to changes that where made because of PHPStan)
  • Loading branch information
vv12131415 committed Jun 22, 2020
1 parent 70e1e48 commit 88cc4a4
Show file tree
Hide file tree
Showing 27 changed files with 538 additions and 32 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
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 \RuntimeException(
sprintf(
'Can\'t add inline validator for %s because it\'s metadata is instance of %s, instead of %s',
$this->getClass(),
\get_class($metadata),
GenericMetadata::class
)
);
}

$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;
}
11 changes: 11 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,16 @@ public function execute(InputInterface $input, OutputInterface $output)
}

$metadata = $this->validator->getMetadataFor($admin->getClass());
if (!$metadata instanceof ClassMetadata) {
throw new \RuntimeException(
sprintf(
'Can\'t read metadata properties of %s because it\'s metadata is instance of %s, instead of %s',
$admin->getClass(),
\get_class($metadata),
ClassMetadata::class
)
);
}

$output->writeln('');
$output->writeln('<comment>Validation Framework</comment> - http://symfony.com/doc/3.0/book/validation.html');
Expand Down
14 changes: 7 additions & 7 deletions src/Command/QuestionableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final protected function askAndValidate(
) {
$questionHelper = $this->getQuestionHelper();

$question = new Question($questionHelper->getQuestion($questionText, $default), $default);
$question = new Question($questionText, $default);

$question->setValidator($validator);

Expand All @@ -50,6 +50,8 @@ final protected function askAndValidate(
* @param string $default
* @param string $separator
*
* NEXT_MAJOR: Remove `$separator` argument
*
* @return string
*/
final protected function askConfirmation(
Expand All @@ -60,12 +62,10 @@ final protected function askConfirmation(
$separator
) {
$questionHelper = $this->getQuestionHelper();

$question = new ConfirmationQuestion($questionHelper->getQuestion(
$questionText,
$default,
$separator
), ('no' === $default ? false : true));
$question = new ConfirmationQuestion(
(new Question($questionText, $default))->getQuestion(),
('no' === $default ? false : true)
);

return $questionHelper->ask($input, $output, $question);
}
Expand Down
Loading

0 comments on commit 88cc4a4

Please sign in to comment.