From b65ee4c21d271344a017456bc49412b7755049a9 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 10 Oct 2021 09:35:36 +0100 Subject: [PATCH] [TOOLS][CS-FIXER] Fix incorrect transformation --- .php-cs-fixer.php | 25 ++++++++++--------- bin/pre-commit | 2 +- .../Compiler/SchemaDefDriver.php | 11 ++++++-- src/Security/Authenticator.php | 5 +++- src/Util/Form/ActorArrayTransformer.php | 18 +++++++++---- src/Util/Form/ArrayTransformer.php | 14 +++++++++-- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 22e9f9b189..dba4bbcaf0 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -273,12 +273,13 @@ return $config 'phpdoc_single_line_var_spacing' => true, // Fixes casing of PHPDoc tags. 'phpdoc_tag_casing' => true, - // EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. - 'phpdoc_to_param_type' => true, - // EXPERIMENTAL: Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4. - 'phpdoc_to_property_type' => true, - // EXPERIMENTAL: Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. - 'phpdoc_to_return_type' => true, + // Would be neat, but breaks cases where the parents don't have annotations + // // EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. + // 'phpdoc_to_param_type' => true, + // // EXPERIMENTAL: Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4. + // 'phpdoc_to_property_type' => true, + // // EXPERIMENTAL: Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. + // 'phpdoc_to_return_type' => true, // PHPDoc should start and end with content, excluding the very first and last line of the docblocks. 'phpdoc_trim' => true, // Removes extra blank lines after summary and after description in PHPDoc. @@ -368,10 +369,10 @@ return $config ]) ->setFinder( PhpCsFixer\Finder::create() - ->exclude('vendor') - ->exclude('var') - ->exclude('docker') - ->exclude('src/Entity') - ->notPath('src/Core/DB/DefaultSettings.php') - ->in(__DIR__), + ->exclude('vendor') + ->exclude('var') + ->exclude('docker') + ->exclude('src/Entity') + ->notPath('src/Core/DB/DefaultSettings.php') + ->in(__DIR__), ); diff --git a/bin/pre-commit b/bin/pre-commit index 79824bb81e..68bde89e21 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -11,7 +11,7 @@ if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); # work only with existing files if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then # use php-cs-fixer and get flag of correction - if "${root}/bin/php-cs-fixer" -q fix "${staged}"; then + if "${root}/bin/php-cs-fixer" -q --config="${root}/.php-cs-fixer.php" fix "${staged}"; then git add "${staged}" # execute git add directly fi fi diff --git a/src/DependencyInjection/Compiler/SchemaDefDriver.php b/src/DependencyInjection/Compiler/SchemaDefDriver.php index 83cc4391bc..c3aaccaf95 100644 --- a/src/DependencyInjection/Compiler/SchemaDefDriver.php +++ b/src/DependencyInjection/Compiler/SchemaDefDriver.php @@ -91,8 +91,11 @@ class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface /** * Fill in the database $metadata for $class_name + * + * @param string $class_name + * @param ClassMetadataInfo $metadata */ - public function loadMetadataForClass(string $class_name, ClassMetadataInfo $metadata) + public function loadMetadataForClass($class_name, $metadata) { $schema = $class_name::schemaDef(); @@ -208,8 +211,12 @@ class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface * Override StaticPHPDriver's method, * we care about classes that have the method `schemaDef`, * instead of `loadMetadata`. + * + * @param string $class_name + * + * @return bool */ - public function isTransient(string $class_name): bool + public function isTransient($class_name) { return !method_exists($class_name, 'schemaDef'); } diff --git a/src/Security/Authenticator.php b/src/Security/Authenticator.php index 8e8fe5aa60..fa0c074e45 100644 --- a/src/Security/Authenticator.php +++ b/src/Security/Authenticator.php @@ -107,7 +107,10 @@ class Authenticator extends AbstractFormLoginAuthenticator return $user; } - public function checkCredentials($credentials, LocalUser $user) + /** + * @param LocalUser $user + */ + public function checkCredentials($credentials, $user) { if (!$user->checkPassword($credentials['password'])) { throw new CustomUserMessageAuthenticationException(_m('Invalid login credentials.')); diff --git a/src/Util/Form/ActorArrayTransformer.php b/src/Util/Form/ActorArrayTransformer.php index db2ad9e4eb..62cd864b71 100644 --- a/src/Util/Form/ActorArrayTransformer.php +++ b/src/Util/Form/ActorArrayTransformer.php @@ -40,21 +40,29 @@ class ActorArrayTransformer extends ArrayTransformer { /** * Transforms array of Actors into string of nicknames + * + * @param array $a + * + * @return string */ - public function transform(array $a): string + public function transform($a) { return parent::transform( array_map( - fn ($actor) => $actor->getNickname(), - $a, - ), + fn ($actor) => $actor->getNickname(), + $a, + ), ); } /** * Transforms string of nicknames into Actors + * + * @param string $s + * + * @return array */ - public function reverseTransform(string $s): array + public function reverseTransform($s) { return array_map( fn ($nickmame) => Actor::getFromNickname($nickmame), diff --git a/src/Util/Form/ArrayTransformer.php b/src/Util/Form/ArrayTransformer.php index a5b0b3b592..19a1581142 100644 --- a/src/Util/Form/ArrayTransformer.php +++ b/src/Util/Form/ArrayTransformer.php @@ -40,7 +40,12 @@ class ArrayTransformer implements DataTransformerInterface { // Can't use type annotations, to conform to interface - public function transform(array $a): string + /** + * @param array $a + * + * @return string + */ + public function transform($a) { if (!\is_array($a)) { throw new TransformationFailedException(); @@ -48,7 +53,12 @@ class ArrayTransformer implements DataTransformerInterface return Formatting::toString($a, Formatting::SPLIT_BY_SPACE); } - public function reverseTransform(string $s): array + /** + * @param string $s + * + * @return array + */ + public function reverseTransform($s) { if (empty($s)) { return [];