From db5c43a554a215d62f01007f2f6a8060d5a85ecd Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Sat, 21 Dec 2024 11:12:16 -0500 Subject: [PATCH] tweaks for php 8.3 --- DependencyInjection/Configuration.php | 2 +- .../EntitiesToPropertyTransformer.php | 16 +++++----- .../EntityToPropertyTransformer.php | 4 +-- composer.json | 19 ++++++----- phpstan.neon | 32 +++++++++++++++++++ 5 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 phpstan.neon diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5bd9542..9e267c8 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritDoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('tetranz_select2_entity'); $rootNode = $treeBuilder->getRootNode(); diff --git a/Form/DataTransformer/EntitiesToPropertyTransformer.php b/Form/DataTransformer/EntitiesToPropertyTransformer.php index d6a9fd8..d6ae56a 100644 --- a/Form/DataTransformer/EntitiesToPropertyTransformer.php +++ b/Form/DataTransformer/EntitiesToPropertyTransformer.php @@ -52,30 +52,30 @@ public function __construct(ObjectManager $em, $class, $textProperty = null, $pr /** * Transform initial entities to array * - * @param mixed $entities + * @param mixed $value * @return array */ - public function transform($entities) + public function transform($value): mixed { - if (empty($entities)) { + if (empty($value)) { return array(); } $data = array(); - foreach ($entities as $entity) { + foreach ($value as $entity) { $text = is_null($this->textProperty) ? (string) $entity : $this->accessor->getValue($entity, $this->textProperty); if ($this->em->contains($entity)) { - $value = (string) $this->accessor->getValue($entity, $this->primaryKey); + $v = (string) $this->accessor->getValue($entity, $this->primaryKey); } else { - $value = $this->newTagPrefix . $text; + $v = $this->newTagPrefix . $text; $text = $text.$this->newTagText; } - $data[$value] = $text; + $data[$v] = $text; } return $data; @@ -87,7 +87,7 @@ public function transform($entities) * @param array $values * @return array */ - public function reverseTransform($values) + public function reverseTransform($values): mixed { if (!is_array($values) || empty($values)) { return array(); diff --git a/Form/DataTransformer/EntityToPropertyTransformer.php b/Form/DataTransformer/EntityToPropertyTransformer.php index 72a30a9..252ecee 100644 --- a/Form/DataTransformer/EntityToPropertyTransformer.php +++ b/Form/DataTransformer/EntityToPropertyTransformer.php @@ -56,7 +56,7 @@ public function __construct(ObjectManager $em, $class, $textProperty = null, $pr * @param mixed $entity * @return array */ - public function transform($entity) + public function transform($entity): mixed { $data = array(); if (empty($entity)) { @@ -85,7 +85,7 @@ public function transform($entity) * @param string $value * @return mixed|null|object */ - public function reverseTransform($value) + public function reverseTransform($value): mixed { if (empty($value)) { return null; diff --git a/composer.json b/composer.json index 7a23ddd..07bc335 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,15 @@ } ], "require": { - "php": ">=7.1.3", + "php": "^8.2", "doctrine/orm": ">=2.4", - "twig/twig": ">=2.9", - "symfony/property-access": ">=4.0", - "symfony/dependency-injection": ">=4.0", - "symfony/http-kernel": ">=4.0", - "symfony/form": ">=4.0", - "symfony/config": ">=4.0", - "symfony/routing": ">=4.0" + "twig/twig": "^3.15", + "symfony/property-access": "^6.4 || ^7.1" , + "symfony/dependency-injection": "^6.4 || ^7.1" , + "symfony/http-kernel": "^6.4 || ^7.1" , + "symfony/form": "^6.4 || ^7.1" , + "symfony/config": "^6.4 || ^7.1" , + "symfony/routing": "^6.4 || ^7.1" }, "autoload": { "psr-4": { "Tetranz\\Select2EntityBundle\\": "" } @@ -27,5 +27,8 @@ "extra": { "branch-alias": { } + }, + "require-dev": { + "phpstan/phpstan": "^2.0" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a992c5d --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,32 @@ +parameters: + level: 0 + inferPrivatePropertyTypeFromConstructor: true + paths: + - . + + excludePaths: +# - 'src/Resources/skeleton' +# - */cache/* + analyse: + - ./vendor + + ignoreErrors: + # False positive: clients are not dependencies of this project. +# - +# message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUserFromToken\(\) has invalid type [a-zA-Z0-9\\_]#' +# path: ./src/Client/Provider +# - +# message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUser\(\) has invalid type [a-zA-Z0-9\\_]#' +# path: ./src/Client/Provider + # False positive: using `::class` is not an error for those providers `::getProviderClass()` method. +# - +# message: '#Class [a-zA-Z0-9\\_]+ not found#' +# path: ./src/DependencyInjection/Providers + + # The DependencyInjection returns are very complex to deal with +# - +# message: '#.*NodeParentInterface\|null.*#' +# path: ./src/DependencyInjection/Providers + +# - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#' +# - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::scalarNode\(\).#'