Skip to content

Commit

Permalink
Apply misc static analysis fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Nov 24, 2020
1 parent 832ee74 commit 307a2ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 59 deletions.
23 changes: 5 additions & 18 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,11 @@ parameters:
- %currentWorkingDirectory%/src/Component/vendor/*

ignoreErrors:
# Symfony 3.4 compatibility
- '/Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false/'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)/'
- '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters/'
- '/Class Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface not found/'
- '/Instantiated class Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheAdapter not found/'
- '/Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\./'
- '/Parameter \#1 \$event of method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) expects object, string given\./'

- '/Class Doctrine\\Bundle\\MongoDBBundle/'
- '/Class Doctrine\\Bundle\\PHPCRBundle/'

# Calls to Event::getResponse() after Event::hasResponse() has been made
- '/should return Symfony\\Component\\HttpFoundation\\Response but returns Symfony\\Component\\HttpFoundation\\Response\|null/'

- '/Class Doctrine\\Common\\Persistence\\ObjectManager not found\./'
- '/Class Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface not found/'
- '/Instantiated class Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheAdapter not found/'
- '/Method Sylius\\Bundle\\ResourceBundle\\Controller\\ResourcesCollectionProvider::get\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ResourceBundle\\Controller\\ResourcesCollectionProviderInterface::get\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ResourceBundle\\Controller\\ResourcesResolver::getResources\(\) has no return typehint specified./'
Expand All @@ -51,10 +41,7 @@ parameters:
- '/Method Sylius\\Component\\Resource\\Model\\ResourceInterface::getId\(\) has no return typehint specified./'
- '/Method Sylius\\Component\\Resource\\Model\\TimestampableInterface::setCreatedAt\(\) has no return typehint specified./'
- '/Method Sylius\\Component\\Resource\\Model\\TimestampableInterface::setUpdatedAt\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ResourceBundle\\ExpressionLanguage\\ExpressionLanguage::__construct\(\) has parameter \$cache with no typehint specified./'
- '/Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\./'
- '/Parameter \#1 \$array[0-9]? of function array_multisort expects array, array\|int given\./'
- '/Parameter \#2 \$class of static method Webmozart\\Assert\\Assert::isInstanceOf\(\) expects class-string<object>, string given./'
- '/Unable to resolve the template type ExpectedType in call to method static method Webmozart\\Assert\\Assert::isInstanceOf\(\)/'
- '/Method Sylius\\Bundle\\ResourceBundle\\Routing\\ResourceLoader::getResolver\(\) should return Symfony\\Component\\Config\\Loader\\LoaderResolverInterface but return statement is missing./'
- '/Parameter \#1 \$array[0-9]? of function array_multisort expects array, array\|int given\./'

- '/Class Doctrine\\Common\\Persistence\\ObjectManager not found\./'
35 changes: 0 additions & 35 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?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"
Expand All @@ -24,37 +23,13 @@
</projectFiles>

<issueHandlers>
<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\Common\Inflector\Inflector" />
<referencedClass name="Doctrine\Common\Persistence\ObjectRepository" />
<referencedClass name="Pagerfanta\Adapter\DoctrineORMAdapter" />
<referencedClass name="Symfony\Bundle\FrameworkBundle\Controller\Controller" />
<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="Doctrine\Common\Inflector\Inflector::pluralize" />
<referencedMethod name="FOS\RestBundle\View\View::setTemplate" />
<referencedMethod name="FOS\RestBundle\View\View::setTemplateVar" />
<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="Doctrine\Common\Inflector\Inflector::pluralize" />
<referencedMethod name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
</errorLevel>
</DeprecatedMethod>

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

<MethodSignatureMismatch>
<errorLevel type="suppress">
<file name="src/Bundle/Doctrine/ResourceMappingDriverChain.php" />
Expand Down Expand Up @@ -90,19 +65,9 @@
</errorLevel>
</PossiblyUndefinedMethod>

<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<referencedProperty name="Symfony\Bundle\FrameworkBundle\Controller\AbstractController::$container"/>
<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\HttpFoundation\HeaderBag::all" />
<referencedFunction name="Symfony\Component\HttpFoundation\HeaderBag::get" />
<referencedFunction name="Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch" />
</errorLevel>
</TooManyArguments>
Expand Down
11 changes: 5 additions & 6 deletions src/Bundle/Controller/FlashHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sylius\Bundle\ResourceBundle\Controller;

use Doctrine\Common\Inflector\Inflector;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Component\Resource\Metadata\MetadataInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
Expand Down Expand Up @@ -60,8 +60,7 @@ public function addFlashFromEvent(RequestConfiguration $requestConfiguration, Re
private function addFlashWithType(RequestConfiguration $requestConfiguration, string $actionName, string $type): void
{
$metadata = $requestConfiguration->getMetadata();
$metadataName = ucfirst($metadata->getHumanizedName());
$parameters = $this->getParametersWithName($metadataName, $actionName);
$parameters = $this->getParametersWithName($metadata, $actionName);

$message = (string) $requestConfiguration->getFlashMessage($actionName);
if (empty($message)) {
Expand Down Expand Up @@ -122,12 +121,12 @@ private function isTranslationDefined(string $message, string $locale, array $pa
return $message !== $this->translator->trans($message, $parameters, 'flashes');
}

private function getParametersWithName(string $metadataName, string $actionName): array
private function getParametersWithName(MetadataInterface $metadata, string $actionName): array
{
if (stripos($actionName, 'bulk') !== false) {
return ['%resources%' => ucfirst(Inflector::pluralize($metadataName))];
return ['%resources%' => ucfirst($metadata->getPluralName())];
}

return ['%resource%' => ucfirst($metadataName)];
return ['%resource%' => ucfirst($metadata->getHumanizedName())];
}
}

0 comments on commit 307a2ec

Please sign in to comment.