Skip to content

Commit

Permalink
rector, PHPStan etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Oct 5, 2023
1 parent a1dd9d6 commit 05ff660
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 106 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.10.37",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/extension-installer": "^1.3.1"
"phpstan/phpstan-strict-rules": "^1.5.1",
"rector/rector": "^0.18.5",
"roave/security-advisories": "dev-latest"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -62,9 +65,13 @@
],
"php-cs-fixer-check": [
"vendor-bin/phpcs/vendor/bin/php-cs-fixer fix --diff --dry-run"
],
"rector": [
"./vendor/bin/rector process src"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"ocramius/package-versions": true,
"bamarni/composer-bin-plugin": true,
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ parameters:
count: 1
path: src/Form/Transformer/FileTransformer.php

-
message: "#^Return type \\(string\\|null\\) of method Valantic\\\\PimcoreFormsBundle\\\\Model\\\\AbstractMessage\\:\\:key\\(\\) should be covariant with return type \\(string\\) of method Iterator\\<string,mixed\\>\\:\\:key\\(\\)$#"
count: 1
path: src/Model/AbstractMessage.php

-
message: "#^Method Valantic\\\\PimcoreFormsBundle\\\\Service\\\\FormService\\:\\:errors\\(\\) should return array but returns array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null\\.$#"
count: 1
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ parameters:

bootstrapFiles:
- vendor/pimcore/pimcore/stubs/dynamic-constants.php

treatPhpDocTypesAsCertain: false

strictRules:
booleansInConditions: false
disallowedConstructs: false
noVariableVariables: false
14 changes: 13 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);

$rectorConfig->skip([
SimplifyEmptyCheckOnEmptyArrayRector::class,
DisallowedEmptyRuleFixerRector::class,
NullToStrictStringFuncCallArgRector::class,
StringClassNameToClassConstantRector::class => [
'src/DependencyInjection/Compiler/ExtensionCompilerPass.php',
'src/DependencyInjection/Compiler/TransformerCompilerPass.php',
],
IssetOnPropertyObjectToPropertyExistsRector::class,
CountArrayToEmptyArrayComparisonRector::class
]);

$rectorConfig->sets([
Expand Down
11 changes: 0 additions & 11 deletions src/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class FormController extends AbstractController
/**
* @Route("/ui/{name}")
*
* @param string $name
* @param FormService $formService
*
* @return Response
*/
public function uiAction(string $name, FormService $formService): Response
Expand All @@ -36,9 +33,6 @@ public function uiAction(string $name, FormService $formService): Response
/**
* @Route("/html/{name}")
*
* @param string $name
* @param FormService $formService
*
* @return Response
*/
public function htmlAction(string $name, FormService $formService): Response
Expand All @@ -51,11 +45,6 @@ public function htmlAction(string $name, FormService $formService): Response
/**
* @Route("/api/{name}")
*
* @param string $name
* @param FormService $formService
* @param Request $request
* @param TranslatorInterface $translator
*
* @throws SerializerException
*
* @return ApiResponse
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/ExtensionCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class ExtensionCompilerPass implements CompilerPassInterface
{
public const EXTENSION_TAG = 'liform.extension';
final public const EXTENSION_TAG = 'liform.extension';

/**
* {@inheritDoc}
Expand All @@ -35,7 +35,7 @@ public function process(ContainerBuilder $container): void

$liform = $container->getDefinition('Limenius\Liform\Liform');

foreach ($container->findTaggedServiceIds(self::EXTENSION_TAG) as $id => $attributes) {
foreach (array_keys($container->findTaggedServiceIds(self::EXTENSION_TAG)) as $id) {
$extension = $container->getDefinition($id);

$extensionClass = $extension->getClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class TransformerCompilerPass implements CompilerPassInterface
{
public const TRANSFORMER_TAG = 'liform.transformer';
final public const TRANSFORMER_TAG = 'liform.transformer';

/**
* {@inheritDoc}
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
class Configuration implements ConfigurationInterface
{
public const SYMFONY_CONSTRAINTS_NAMESPACE = 'Symfony\\Component\\Validator\\Constraints\\';
public const SYMFONY_FORMTYPES_NAMESPACE = 'Symfony\\Component\\Form\\Extension\\Core\\Type\\';
final public const SYMFONY_CONSTRAINTS_NAMESPACE = 'Symfony\\Component\\Validator\\Constraints\\';
final public const SYMFONY_FORMTYPES_NAMESPACE = 'Symfony\\Component\\Form\\Extension\\Core\\Type\\';

/**
* {@inheritDoc}
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function buildFieldsNode(): ArrayNodeDefinition
->cannotBeEmpty()
->info('The type of this FormType')
->validate()
->ifTrue(fn(string $type): bool => !(class_exists($type) || class_exists(self::SYMFONY_FORMTYPES_NAMESPACE . $type)))
->ifTrue(fn(string $type): bool => !class_exists($type) && !class_exists(self::SYMFONY_FORMTYPES_NAMESPACE . $type))
->thenInvalid('Invalid type class found. The type should either be a FQN or a subclass of ' . self::SYMFONY_FORMTYPES_NAMESPACE)
->end()
->example('TextType')
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/ValanticPimcoreFormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
*/
class ValanticPimcoreFormsExtension extends Extension
{
public const TAG_OUTPUT = 'valantic.pimcore_forms.output';
public const TAG_REDIRECT_HANDLER = 'valantic.pimcore_forms.redirect_handler';
public const TAG_INPUT_HANDLER = 'valantic.pimcore_forms.input_handler';
final public const TAG_OUTPUT = 'valantic.pimcore_forms.output';
final public const TAG_REDIRECT_HANDLER = 'valantic.pimcore_forms.redirect_handler';
final public const TAG_INPUT_HANDLER = 'valantic.pimcore_forms.input_handler';

/**
* {@inheritDoc}
Expand Down
8 changes: 3 additions & 5 deletions src/Document/Areabrick/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

class Form extends AbstractTemplateAreabrick implements EditableDialogBoxInterface
{
protected ConfigurationRepository $configurationRepository;

public function __construct(ConfigurationRepository $configurationRepository)
{
$this->configurationRepository = $configurationRepository;
public function __construct(
protected ConfigurationRepository $configurationRepository
) {
}

public function getTemplateLocation(): string
Expand Down
8 changes: 3 additions & 5 deletions src/Document/Twig/Extension/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

class Form extends AbstractExtension
{
protected FormService $formService;

public function __construct(FormService $formService)
{
$this->formService = $formService;
public function __construct(
protected FormService $formService
) {
}

/**
Expand Down
14 changes: 3 additions & 11 deletions src/Form/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@

class Builder
{
protected ContainerInterface $container;
protected UrlGeneratorInterface $urlGenerator;
protected TranslatorInterface $translator;

public function __construct(
ContainerInterface $container,
UrlGeneratorInterface $urlGenerator,
TranslatorInterface $translator
protected ContainerInterface $container,
protected UrlGeneratorInterface $urlGenerator,
protected TranslatorInterface $translator
) {
$this->container = $container;
$this->urlGenerator = $urlGenerator;
$this->translator = $translator;
}

/**
* @param string $name
* @param array<string,mixed> $config
*
* @return FormBuilderInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Extension/FormTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function apply(FormInterface $form, array $schema): array
return $schema;
}

$type = get_class($form->getConfig()->getType()->getInnerType());
$type = $form->getConfig()->getType()->getInnerType()::class;

$formType = null;

Expand Down
16 changes: 4 additions & 12 deletions src/Form/FormErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@

class FormErrorNormalizer implements NormalizerInterface
{
protected TranslatorInterface $translator;
protected ConfigurationRepository $configurationRepository;

public function __construct(TranslatorInterface $translator, ConfigurationRepository $configurationRepository)
{
$this->translator = $translator;
$this->configurationRepository = $configurationRepository;
public function __construct(
protected TranslatorInterface $translator,
protected ConfigurationRepository $configurationRepository
) {
}

/**
Expand All @@ -40,8 +37,6 @@ public function supportsNormalization($data, $format = null): bool
}

/**
* @param FormInterface $data
*
* @return array<int,array<mixed>>
*
* @see https://github.com/schmittjoh/serializer/blob/master/src/Handler/FormErrorHandler.php
Expand Down Expand Up @@ -79,7 +74,6 @@ protected function convertFormToArray(FormInterface $data): array
}

/**
* @param FormError $error
* @param string|null $customErrorMessageTemplate
*
* @return array<string,mixed>
Expand Down Expand Up @@ -112,8 +106,6 @@ protected function buildErrorEntry(FormError $error, ?string $customErrorMessage
}

/**
* @param FormError $error
*
* @return string|null
*
* @see https://github.com/schmittjoh/serializer/blob/master/src/Handler/FormErrorHandler.php
Expand Down
2 changes: 1 addition & 1 deletion src/Form/InputHandler/AbstractInputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
abstract class AbstractInputHandler implements InputHandlerInterface
{
protected FormInterface $form;
protected ?Request $request;
protected ?Request $request = null;

public function initialize(FormInterface $form, ?Request $request): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Output/AssetOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(OutputResponse $outputResponse): OutputResponse
{
$path = Folder::getByPath($this->getPath());

if ($path === null) {
if (!$path instanceof Folder) {
throw new \InvalidArgumentException(sprintf('Path %s not found', $this->getPath()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Output/DataObjectOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function handle(OutputResponse $outputResponse): OutputResponse

$path = Concrete::getByPath($this->getPath());

if ($path === null) {
if (!$path instanceof Concrete) {
throw new \InvalidArgumentException(sprintf('Path %s not found', $this->getPath()));
}

Expand Down
3 changes: 0 additions & 3 deletions src/Form/Output/OutputScratchpad.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class OutputScratchpad
protected static array $scratchpad = [];

/**
* @param string $key
* @param array<mixed> $payload
*/
public static function set(string $key, array $payload): void
Expand All @@ -21,8 +20,6 @@ public static function set(string $key, array $payload): void
}

/**
* @param string $key
*
* @return array<mixed>
*/
public static function get(string $key): array
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Transformer/OverwriteAbstractTransformerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
trait OverwriteAbstractTransformerTrait
{
/**
* @param FormInterface $form
* @param array<mixed> $schema
*
* @return array<mixed>
Expand All @@ -19,7 +18,9 @@ trait OverwriteAbstractTransformerTrait
protected function addLabel(FormInterface $form, array $schema): array
{
$translationDomain = $form->getConfig()->getOption('translation_domain');
if ($label = $form->getConfig()->getOption('label')) {
$label = $form->getConfig()->getOption('label');

if ($label !== null) {
// translation is handled in \Valantic\PimcoreFormsBundle\Form\Builder::getOptions
$schema['title'] = $label;
} else {
Expand All @@ -30,7 +31,6 @@ protected function addLabel(FormInterface $form, array $schema): array
}

/**
* @param FormInterface $form
* @param array<mixed> $schema
*
* @return array<mixed>
Expand Down
4 changes: 0 additions & 4 deletions src/Model/OutputResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function setMessages(array $messages): self
}

/**
* @param AbstractMessage $message
*
* @return $this
*/
public function addMessage(AbstractMessage $message): self
Expand All @@ -61,8 +59,6 @@ public function getOverallStatus(): bool
}

/**
* @param bool $status
*
* @return $this
*/
public function addStatus(bool $status): self
Expand Down
13 changes: 6 additions & 7 deletions src/Repository/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

class ConfigurationRepository
{
public const CONTAINER_TAG = 'valantic.picmore_forms.config';
public const EDITOR_STORAGE_DIRECTORY = PIMCORE_PRIVATE_VAR . '/bundles/valantic-forms';
public const EDITOR_STORAGE_FILE = self::EDITOR_STORAGE_DIRECTORY . '/forms.yml';
protected ParameterBagInterface $parameterBag;
final public const CONTAINER_TAG = 'valantic.picmore_forms.config';
final public const EDITOR_STORAGE_DIRECTORY = PIMCORE_PRIVATE_VAR . '/bundles/valantic-forms';
final public const EDITOR_STORAGE_FILE = self::EDITOR_STORAGE_DIRECTORY . '/forms.yml';

public function __construct(ParameterBagInterface $parameterBag)
{
$this->parameterBag = $parameterBag;
public function __construct(
protected ParameterBagInterface $parameterBag
) {
}

/**
Expand Down
Loading

0 comments on commit 05ff660

Please sign in to comment.