[TOOLS][CS-FIXER] Fix incorrect transformation

This commit is contained in:
Hugo Sales 2021-10-10 09:35:36 +01:00 committed by Diogo Peralta Cordeiro
parent 9109c61af5
commit b65ee4c21d
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
6 changed files with 52 additions and 23 deletions

View File

@ -273,12 +273,13 @@ return $config
'phpdoc_single_line_var_spacing' => true, 'phpdoc_single_line_var_spacing' => true,
// Fixes casing of PHPDoc tags. // Fixes casing of PHPDoc tags.
'phpdoc_tag_casing' => true, 'phpdoc_tag_casing' => true,
// EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. // Would be neat, but breaks cases where the parents don't have annotations
'phpdoc_to_param_type' => true, // // EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
// EXPERIMENTAL: Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4. // 'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true, // // EXPERIMENTAL: Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4.
// EXPERIMENTAL: Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0. // 'phpdoc_to_property_type' => true,
'phpdoc_to_return_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 should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim' => true, 'phpdoc_trim' => true,
// Removes extra blank lines after summary and after description in PHPDoc. // Removes extra blank lines after summary and after description in PHPDoc.
@ -368,10 +369,10 @@ return $config
]) ])
->setFinder( ->setFinder(
PhpCsFixer\Finder::create() PhpCsFixer\Finder::create()
->exclude('vendor') ->exclude('vendor')
->exclude('var') ->exclude('var')
->exclude('docker') ->exclude('docker')
->exclude('src/Entity') ->exclude('src/Entity')
->notPath('src/Core/DB/DefaultSettings.php') ->notPath('src/Core/DB/DefaultSettings.php')
->in(__DIR__), ->in(__DIR__),
); );

View File

@ -11,7 +11,7 @@ if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null);
# work only with existing files # work only with existing files
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then
# use php-cs-fixer and get flag of correction # 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 git add "${staged}" # execute git add directly
fi fi
fi fi

View File

@ -91,8 +91,11 @@ class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface
/** /**
* Fill in the database $metadata for $class_name * 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(); $schema = $class_name::schemaDef();
@ -208,8 +211,12 @@ class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface
* Override StaticPHPDriver's method, * Override StaticPHPDriver's method,
* we care about classes that have the method `schemaDef`, * we care about classes that have the method `schemaDef`,
* instead of `loadMetadata`. * 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'); return !method_exists($class_name, 'schemaDef');
} }

View File

@ -107,7 +107,10 @@ class Authenticator extends AbstractFormLoginAuthenticator
return $user; return $user;
} }
public function checkCredentials($credentials, LocalUser $user) /**
* @param LocalUser $user
*/
public function checkCredentials($credentials, $user)
{ {
if (!$user->checkPassword($credentials['password'])) { if (!$user->checkPassword($credentials['password'])) {
throw new CustomUserMessageAuthenticationException(_m('Invalid login credentials.')); throw new CustomUserMessageAuthenticationException(_m('Invalid login credentials.'));

View File

@ -40,21 +40,29 @@ class ActorArrayTransformer extends ArrayTransformer
{ {
/** /**
* Transforms array of Actors into string of nicknames * 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( return parent::transform(
array_map( array_map(
fn ($actor) => $actor->getNickname(), fn ($actor) => $actor->getNickname(),
$a, $a,
), ),
); );
} }
/** /**
* Transforms string of nicknames into Actors * Transforms string of nicknames into Actors
*
* @param string $s
*
* @return array
*/ */
public function reverseTransform(string $s): array public function reverseTransform($s)
{ {
return array_map( return array_map(
fn ($nickmame) => Actor::getFromNickname($nickmame), fn ($nickmame) => Actor::getFromNickname($nickmame),

View File

@ -40,7 +40,12 @@ class ArrayTransformer implements DataTransformerInterface
{ {
// Can't use type annotations, to conform to interface // 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)) { if (!\is_array($a)) {
throw new TransformationFailedException(); throw new TransformationFailedException();
@ -48,7 +53,12 @@ class ArrayTransformer implements DataTransformerInterface
return Formatting::toString($a, Formatting::SPLIT_BY_SPACE); 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)) { if (empty($s)) {
return []; return [];