Skip to content

Commit

Permalink
add psalm to project
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslavstartsev committed Aug 17, 2020
1 parent f46719b commit 6cebc40
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/qa.yaml
Expand Up @@ -12,3 +12,11 @@ jobs:
REQUIRE_DEV: true
with:
args: analyse -c .phpstan/phpstan.neon.dist
psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Psalm
uses: docker://vimeo/psalm-github-actions
6 changes: 0 additions & 6 deletions .phpstan/phpstan-baseline.neon
Expand Up @@ -115,12 +115,6 @@ parameters:
count: 1
path: ../src/Command/GenerateObjectAclCommand.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. Code is marked as deprecated
message: "#^Method Sonata\\\\AdminBundle\\\\Datagrid\\\\Datagrid\\:\\:getFilter\\(\\) should return Sonata\\\\AdminBundle\\\\Filter\\\\FilterInterface but returns null\\.$#"
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE-3.x.md
Expand Up @@ -45,6 +45,10 @@ with `sonata-project/block-bundle` on your composer.json in order to avoid unwan

There is a minimal BC Break on `AdminListBlockService`, `AdminSearchBlockService` and `AdminStatsBlockService`. If you are extending those clases (keep in mind that they will become final on 4.0) you should add return type hints to `execute()` and `configureSettings()`.

## Deprecated passing `callable` that does not return `Symfony\Component\Routing\Route` as `$element` (2nd argument) to `Sonata\AdminBundle\Route\RouteCollection::addElement($code, $element)`

When calling a `Sonata\AdminBundle\Route\RouteCollection::addElement($code, $element)`, please pass `$element` of type `Route|callable():Route`. Passing `callable` that returns non instance of `Route` is deprecated.

UPGRADE FROM 3.72 to 3.73
=========================

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Expand Up @@ -70,15 +70,18 @@
"require-dev": {
"jms/translation-bundle": "^1.4",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpdocumentor/reflection-docblock": "^5.2",
"phpstan/phpstan": "^0.12.29",
"psalm/plugin-symfony": "^1.4",
"psr/event-dispatcher": "^1.0",
"sonata-project/intl-bundle": "^2.4",
"symfony/browser-kit": "^4.4",
"symfony/css-selector": "^4.4",
"symfony/filesystem": "^4.4",
"symfony/maker-bundle": "^1.17",
"symfony/phpunit-bridge": "^5.1.1",
"symfony/yaml": "^4.4"
"symfony/yaml": "^4.4",
"vimeo/psalm": "^3.13.1"
},
"suggest": {
"jms/translation-bundle": "Extract message keys from Admins",
Expand Down
216 changes: 216 additions & 0 deletions psalm-baseline.xml
@@ -0,0 +1,216 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.13.1@afd8874a9e4562eac42a02de90e42e430c3a1db1">
<file src="src/Admin/AbstractAdmin.php">
<!--will be removed in v4. Currently BC break-->
<InvalidReturnStatement occurrences="1">
<code>$this-&gt;parentAssociationMapping</code>
</InvalidReturnStatement>
<!--will be fixed in v4. Currently BC break. Remove string from union type of $this->parentAssociationMapping-->
<InvalidArrayOffset occurrences="1">
<code>$this-&gt;parentAssociationMapping[$code]</code>
</InvalidArrayOffset>
<!--will be removed in v4. Currently BC break-->
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;subClasses</code>
</InvalidPropertyAssignmentValue>
</file>
<file src="src/Datagrid/Pager.php">
<InvalidReturnStatement occurrences="2">
<code>next($this-&gt;results)</code>
<code>reset($this-&gt;results)</code>
</InvalidReturnStatement>
</file>
<file src="src/Datagrid/SimplePager.php">
<InvalidReturnStatement occurrences="2">
<code>$this-&gt;results</code>
<code>$this-&gt;results</code>
</InvalidReturnStatement>
</file>
<file src="src/Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php">
<InvalidReturnType occurrences="2">
<code>buildSecurityInformation</code>
<code>getBaseRole</code>
</InvalidReturnType>
</file>
<!--The next error is due to not installed Doctrine ORM\ODM-->
<file src="src/Admin/AdminHelper.php">
<UndefinedClass occurrences="1">
<code>DoctrinePersistentCollection</code>
</UndefinedClass>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Command/CreateClassCacheCommand.php">
<UndefinedClass occurrences="1">
<code>ClassCollectionLoader</code>
</UndefinedClass>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Form/Type/ModelTypeList.php">
<InvalidExtendClass occurrences="1">
<code>ModelListType</code>
</InvalidExtendClass>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Object/MetadataInterface.php">
<UndefinedClass occurrences="1">
<code>CoreMetadataInterface</code>
</UndefinedClass>
<UnrecognizedStatement occurrences="1"/>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Form/Extension/ChoiceTypeExtension.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Extension/Field/Type/FormTypeFieldExtension.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Extension/Field/Type/MopaCompatibilityTypeFieldExtension.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/AclMatrixType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/AdminType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ChoiceFieldMaskType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/ChoiceType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/DateRangeType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/DateTimeRangeType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/DateTimeType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/DateType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/DefaultType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/Filter/NumberType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ModelAutocompleteType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ModelHiddenType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ModelListType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ModelReferenceType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<file src="src/Form/Type/ModelType.php">
<UndefinedClass occurrences="1">
<code>OptionsResolverInterface</code>
</UndefinedClass>
</file>
<!-- ignore template files-->
<file src="src/Resources/skeleton/Admin.tpl.php">
<UndefinedGlobalVariable occurrences="6">
<code>$namespace</code>
<code>$class_name</code>
<code>$fields</code>
<code>$fields</code>
<code>$fields</code>
<code>$fields</code>
</UndefinedGlobalVariable>
</file>
<file src="src/Resources/skeleton/AdminController.tpl.php">
<UndefinedGlobalVariable occurrences="2">
<code>$namespace</code>
<code>$class_name</code>
</UndefinedGlobalVariable>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Twig/Extension/StringExtension.php">
<UndefinedClass occurrences="2">
<code>TextExtension</code>
<code>TextExtension</code>
</UndefinedClass>
</file>
<file src="src/Admin/FieldDescriptionCollection.php">
<InvalidPropertyAssignmentValue occurrences="1">
<code>array_merge(array_flip($keys), $this-&gt;elements)</code>
</InvalidPropertyAssignmentValue>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Twig/Extension/TemplateRegistryExtension.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Route/AdminPoolLoader.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Model/AuditManager.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Filter/FilterFactory.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Controller/PolyfillControllerTrait.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
<!--will be removed in v4. Currently BC break-->
<file src="src/Admin/Pool.php">
<ContainerDependency occurrences="1">
<code>ContainerInterface $container</code>
</ContainerDependency>
</file>
</files>
10 changes: 10 additions & 0 deletions psalm.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="6" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<file name="src/Resources/skeleton"/>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>
16 changes: 9 additions & 7 deletions src/Admin/AbstractAdmin.php
Expand Up @@ -263,7 +263,7 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A
/**
* NEXT_MAJOR: should be default array and private.
*
* @var string|array
* @var array<string, mixed>|string|null
*/
protected $parentAssociationMapping;

Expand Down Expand Up @@ -952,6 +952,13 @@ public function getParentAssociationMapping()
*/
final public function addParentAssociationMapping($code, $value)
{
if (\is_string($this->parentAssociationMapping)) {
@trigger_error(sprintf(
'Calling "%s" when $this->parentAssociationMapping is string is deprecated since sonata-admin/admin-bundle 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$this->parentAssociationMapping[$code] = $value;
}

Expand Down Expand Up @@ -2682,12 +2689,7 @@ public function getSecurityInformation()
*/
public function getPermissionsShow($context)
{
switch ($context) {
case self::CONTEXT_DASHBOARD:
case self::CONTEXT_MENU:
default:
return ['LIST'];
}
return ['LIST'];
}

public function showIn($context)
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/AdminInterface.php
Expand Up @@ -253,8 +253,8 @@ public function setSecurityHandler(SecurityHandlerInterface $securityHandler);
public function getSecurityHandler();

/**
* @param string $name
* @param object|null $object
* @param string|array $name
* @param object|null $object
*
* @return bool
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Datagrid/Datagrid.php
Expand Up @@ -199,6 +199,8 @@ static function ($value) {
public function addFilter(FilterInterface $filter)
{
$this->filters[$filter->getName()] = $filter;

return $filter;
}

public function hasFilter($name)
Expand Down
2 changes: 2 additions & 0 deletions src/Datagrid/Pager.php
Expand Up @@ -492,6 +492,7 @@ public function next()

--$this->resultsCounter;

// NEXT_MAJOR: remove this line. Iterator::next(): void
return next($this->results);
}

Expand All @@ -503,6 +504,7 @@ public function rewind()

$this->resultsCounter = \count($this->results);

// NEXT_MAJOR: remove this line. Iterator::rewind(): void
return reset($this->results);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Maker/AdminMaker.php
Expand Up @@ -38,7 +38,7 @@ final class AdminMaker extends AbstractMaker
*/
private $projectDirectory;
/**
* @var string[]
* @var array<string, ModelManagerInterface|null>
*/
private $availableModelManagers;
/**
Expand Down Expand Up @@ -70,6 +70,10 @@ final class AdminMaker extends AbstractMaker
*/
private $modelManager;

/**
* @param string $projectDirectory
* @param array<string, ModelManagerInterface> $modelManagers
*/
public function __construct($projectDirectory, array $modelManagers = [])
{
$this->projectDirectory = $projectDirectory;
Expand Down

0 comments on commit 6cebc40

Please sign in to comment.