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

Introduce Psalm #15

Merged
merged 1 commit into from
Oct 10, 2019
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
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@
"doctrine/orm": "^2.5",
"doctrine/phpcr-odm": "^1.3",
"jackalope/jackalope-doctrine-dbal": "^1.2",
"lchrusciel/api-test-case": "^4.1",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"pagerfanta/pagerfanta": "^1.0|^2.0",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-webmozart-assert": "^0.11",
"phpunit/phpunit": "^7.0",
"sylius/currency-bundle": "^1.1",
"sylius-labs/coding-standard": "^3.0",
"sylius/currency-bundle": "^1.1",
"symfony/console": "^3.4|^4.1.1",
"symfony/twig-bundle": "^3.4|^4.1.1",
"twig/twig": "^2.0",
"lchrusciel/api-test-case": "^4.1"
"vimeo/psalm": "^3.5"
},
"conflict": {
"twig/twig": "^1.0"
Expand All @@ -77,7 +78,8 @@
"scripts": {
"analyse": [
"@php vendor/bin/ecs check src",
"@php vendor/bin/phpstan analyse --ansi -c phpstan.neon -l max src"
"@php vendor/bin/phpstan analyse --ansi -c phpstan.neon -l max src",
"@php vendor/bin/psalm"
],
"fix": [
"@php vendor/bin/ecs check src --fix"
Expand Down
85 changes: 85 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<directory name="src/Bundle/Doctrine/PHPCRODM" />
<directory name="src/Bundle/spec" />
<directory name="src/Bundle/test" />
<directory name="src/Bundle/Tests" />
<directory name="src/Component/spec" />
<directory name="src/Component/vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="Symfony\Bundle\FrameworkBundle\Controller\Controller" />
<referencedClass name="Symfony\Component\EventDispatcher\Event" />
<referencedClass name="Symfony\Component\HttpKernel\Event\FilterResponseEvent" />
<referencedClass name="Symfony\Component\HttpKernel\Event\GetResponseEvent" />
<referencedClass name="Symfony\Component\Translation\TranslatorInterface" />
</errorLevel>
</DeprecatedClass>

<DeprecatedMethod>
<errorLevel type="suppress">
<referencedMethod name="Symfony\Component\Config\Definition\Builder\TreeBuilder::root" />
<referencedMethod name="Symfony\Component\EventDispatcher\Event::isPropagationStopped" />
<referencedMethod name="Symfony\Component\EventDispatcher\Event::stopPropagation" />
<referencedMethod name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
</errorLevel>
</DeprecatedMethod>

<InvalidArgument>
<errorLevel type="suppress">
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
</errorLevel>
</InvalidArgument>

<PossiblyNullReference>
<errorLevel type="suppress">
<file name="src/Bundle/DependencyInjection/Configuration.php" />
</errorLevel>
</PossiblyNullReference>

<PossiblyUndefinedMethod>
<errorLevel type="suppress">
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeDefinition::arrayNode" />
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeDefinition::scalarNode" />
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeDefinition::variableNode" />
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::end" />
</errorLevel>
</PossiblyUndefinedMethod>

<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<referencedProperty name="Symfony\Component\DependencyInjection\ContainerAwareTrait::$container" />
<referencedProperty name="Symfony\Component\Validator\ConstraintValidator::$context" />
</errorLevel>
</PropertyNotSetInConstructor>

<TooManyArguments>
<errorLevel type="suppress">
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch"/>
<referencedFunction name="Symfony\Component\Config\Definition\Builder\TreeBuilder::__construct" />
</errorLevel>
</TooManyArguments>

<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass" />
<referencedClass name="Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass" />
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter" />
<referencedClass name="Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
4 changes: 4 additions & 0 deletions src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('sylius_grid');

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('sylius_grid');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/Doctrine/DBAL/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getExpressionBuilder(): ExpressionBuilderInterface
*/
public function getData(Parameters $parameters)
{
$countQueryBuilderModifier = function ($queryBuilder) {
$countQueryBuilderModifier = function (QueryBuilder $queryBuilder): void {
$queryBuilder
->select('COUNT(DISTINCT o.id) AS total_results')
->setMaxResults(1)
Expand Down
16 changes: 12 additions & 4 deletions src/Bundle/Doctrine/DBAL/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,39 @@ public function notEquals(string $field, $value)
*/
public function lessThan(string $field, $value)
{
$this->queryBuilder->andWhere($field . ' < :' . $field)->setParameter($field, $value);
$this->queryBuilder->setParameter($field, $value);

return $this->queryBuilder->expr()->lt($field, ':' . $field);
}

/**
* {@inheritdoc}
*/
public function lessThanOrEqual(string $field, $value)
{
$this->queryBuilder->andWhere($field . ' =< :' . $field)->setParameter($field, $value);
$this->queryBuilder->setParameter($field, $value);

return $this->queryBuilder->expr()->lte($field, ':' . $field);
}

/**
* {@inheritdoc}
*/
public function greaterThan(string $field, $value)
{
$this->queryBuilder->andWhere($field . ' > :' . $field)->setParameter($field, $value);
$this->queryBuilder->setParameter($field, $value);

return $this->queryBuilder->expr()->gt($field, ':' . $field);
}

/**
* {@inheritdoc}
*/
public function greaterThanOrEqual(string $field, $value)
{
$this->queryBuilder->andWhere($field . ' => :%s' . $field)->setParameter($field, $value);
$this->queryBuilder->setParameter($field, $value);

return $this->queryBuilder->expr()->gte($field, ':' . $field);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Bundle/FieldTypes/TwigFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

final class TwigFieldType implements FieldTypeInterface
{
/** @var DataExtractorInterface */
private $dataExtractor;

/** @var \Twig_Environment */
/** @var Environment */
private $twig;

public function __construct(DataExtractorInterface $dataExtractor, \Twig_Environment $twig)
public function __construct(DataExtractorInterface $dataExtractor, Environment $twig)
{
$this->dataExtractor = $dataExtractor;
$this->twig = $twig;
Expand Down
2 changes: 2 additions & 0 deletions src/Bundle/Form/DataTransformer/DateTimeFilterTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

final class DateTimeFilterTransformer implements DataTransformerInterface
{
/** @var array<string, array{hour: string, minute: string}> */
private static $defaultTime = [
'from' => ['hour' => '00', 'minute' => '00'],
'to' => ['hour' => '23', 'minute' => '59'],
Expand All @@ -28,6 +29,7 @@ final class DateTimeFilterTransformer implements DataTransformerInterface

public function __construct(string $type)
{
/** @psalm-suppress RedundantCondition */
Assert::oneOf($type, array_keys(static::$defaultTime));

$this->type = $type;
Expand Down
5 changes: 3 additions & 2 deletions src/Bundle/Renderer/TwigBulkActionGridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;
use Twig\Environment;

final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface
{
/** @var \Twig_Environment */
/** @var Environment */
private $twig;

/** @var array */
private $bulkActionTemplates;

public function __construct(\Twig_Environment $twig, array $bulkActionTemplates)
public function __construct(Environment $twig, array $bulkActionTemplates)
{
$this->twig = $twig;
$this->bulkActionTemplates = $bulkActionTemplates;
Expand Down
5 changes: 3 additions & 2 deletions src/Bundle/Renderer/TwigGridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

final class TwigGridRenderer implements GridRendererInterface
{
/** @var \Twig_Environment */
/** @var Environment */
private $twig;

/** @var ServiceRegistryInterface */
Expand All @@ -49,7 +50,7 @@ final class TwigGridRenderer implements GridRendererInterface
private $filterTemplates;

public function __construct(
\Twig_Environment $twig,
Environment $twig,
ServiceRegistryInterface $fieldsRegistry,
FormFactoryInterface $formFactory,
FormTypeRegistryInterface $formTypeRegistry,
Expand Down
4 changes: 2 additions & 2 deletions src/Bundle/SyliusGridBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class SyliusGridBundle extends Bundle
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand All @@ -40,7 +40,7 @@ public function build(ContainerBuilder $container)
/**
* @return string[]
*/
public static function getAvailableDrivers()
public static function getAvailableDrivers(): array
{
return [
self::DRIVER_DOCTRINE_ORM,
Expand Down
13 changes: 13 additions & 0 deletions src/Bundle/Templating/Helper/GridHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,37 @@ public function __construct(GridRendererInterface $gridRenderer)
$this->gridRenderer = $gridRenderer;
}

/**
* @return string
*/
public function renderGrid(GridView $gridView, ?string $template = null)
{
return $this->gridRenderer->render($gridView, $template);
}

/**
* @param mixed $data
*
* @return string
*/
public function renderField(GridView $gridView, Field $field, $data)
{
return $this->gridRenderer->renderField($gridView, $field, $data);
}

/**
* @param mixed|null $data
*
* @return string
*/
public function renderAction(GridView $gridView, Action $action, $data = null)
{
return $this->gridRenderer->renderAction($gridView, $action, $data);
}

/**
* @return string
*/
public function renderFilter(GridView $gridView, Filter $filter)
{
return $this->gridRenderer->renderFilter($gridView, $filter);
Expand Down
6 changes: 4 additions & 2 deletions src/Bundle/Twig/BulkActionGridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Sylius\Bundle\GridBundle\Twig;

use Sylius\Bundle\GridBundle\Templating\Helper\BulkActionGridHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class BulkActionGridExtension extends \Twig_Extension
final class BulkActionGridExtension extends AbstractExtension
{
/** @var BulkActionGridHelper */
private $bulkActionGridHelper;
Expand All @@ -31,7 +33,7 @@ public function __construct(BulkActionGridHelper $bulkActionGridHelper)
public function getFunctions(): array
{
return [
new \Twig_Function(
new TwigFunction(
'sylius_grid_render_bulk_action',
[$this->bulkActionGridHelper, 'renderBulkAction'],
['is_safe' => ['html']]
Expand Down
12 changes: 7 additions & 5 deletions src/Bundle/Twig/GridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Sylius\Bundle\GridBundle\Twig;

use Sylius\Bundle\GridBundle\Templating\Helper\GridHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class GridExtension extends \Twig_Extension
final class GridExtension extends AbstractExtension
{
/** @var GridHelper */
private $gridHelper;
Expand All @@ -31,10 +33,10 @@ public function __construct(GridHelper $gridHelper)
public function getFunctions(): array
{
return [
new \Twig_Function('sylius_grid_render', [$this->gridHelper, 'renderGrid'], ['is_safe' => ['html']]),
new \Twig_Function('sylius_grid_render_field', [$this->gridHelper, 'renderField'], ['is_safe' => ['html']]),
new \Twig_Function('sylius_grid_render_action', [$this->gridHelper, 'renderAction'], ['is_safe' => ['html']]),
new \Twig_Function('sylius_grid_render_filter', [$this->gridHelper, 'renderFilter'], ['is_safe' => ['html']]),
new TwigFunction('sylius_grid_render', [$this->gridHelper, 'renderGrid'], ['is_safe' => ['html']]),
new TwigFunction('sylius_grid_render_field', [$this->gridHelper, 'renderField'], ['is_safe' => ['html']]),
new TwigFunction('sylius_grid_render_action', [$this->gridHelper, 'renderAction'], ['is_safe' => ['html']]),
new TwigFunction('sylius_grid_render_filter', [$this->gridHelper, 'renderFilter'], ['is_safe' => ['html']]),
];
}
}
1 change: 1 addition & 0 deletions src/Component/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
!/vendor/.gitignore
/bin/

/composer.phar
Expand Down
3 changes: 3 additions & 0 deletions src/Component/Data/DataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@

interface DataProviderInterface
{
/**
* @return mixed
*/
public function getData(Grid $grid, Parameters $parameters);
}
Loading