Browse Source

make CustomFullyQualifiedStrictTypesFixer working

pull/9935/head
Michael Voříšek 1 week ago
parent
commit
7fb4cb4e28
  1. 12
      .php-cs-fixer-fully_qualified_strict_types.php
  2. 13
      .php-cs-fixer.dist.php

12
.php-cs-fixer-fully_qualified_strict_types.php

@ -12,7 +12,7 @@ declare(strict_types=1);
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Fixer\Import;
namespace PhpCsFixerCustom;
use PhpCsFixer\AbstractFixer;
use PhpCsFixer\DocBlock\TypeExpression;
@ -63,7 +63,7 @@ use PhpCsFixer\Tokenizer\Tokens;
*
* @phpstan-import-type _ImportType from \PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis
*/
final class FullyQualifiedStrictTypesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface
final class CustomFullyQualifiedStrictTypesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface
{
/** @use ConfigurableFixerTrait<_AutogeneratedInputConfiguration, _AutogeneratedComputedConfiguration> */
use ConfigurableFixerTrait;
@ -215,6 +215,11 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
);
}
public function getName(): string
{
return 'Custom/fully_qualified_strict_types';
}
/**
* {@inheritdoc}
*
@ -250,7 +255,7 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
'leading_backslash_in_global_namespace',
'Whether FQCN is prefixed with backslash when that FQCN is used in global namespace context.'
))
->setAllowedTypes(['bool'])
->setAllowedTypes(['bool', \Closure::class])
->setDefault(false)
->getOption(),
(new FixerOptionBuilder(
@ -522,6 +527,7 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
$res = $fqcn;
if ($namespaceName !== ''
|| $this->configuration['leading_backslash_in_global_namespace'] === true
|| ($this->configuration['leading_backslash_in_global_namespace'] instanceof \Closure && $this->configuration['leading_backslash_in_global_namespace']($res))
|| isset($this->cacheUseNameByShortNameLower[$importKind][strtolower(explode('\\', $res, 2)[0])])
) {
$res = '\\' . $res;

13
.php-cs-fixer.dist.php

@ -3,6 +3,7 @@
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use PhpCsFixerCustom\CustomFullyQualifiedStrictTypesFixer;
$finder = Finder::create()
->in([__DIR__])
@ -14,9 +15,14 @@ $finder = Finder::create()
->name('*.php.dist')
->name('*.sh');
require_once __DIR__ . '/.php-cs-fixer-fully_qualified_strict_types.php';
return (new Config())
->setParallelConfig(ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->registerCustomFixers([
new CustomFullyQualifiedStrictTypesFixer(),
])
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
@ -96,6 +102,13 @@ return (new Config())
'strict_comparison' => false,
'octal_notation' => false,
// TODO remove after https://github.com/roundcube/roundcubemail/pull/9481
'Custom/fully_qualified_strict_types' => ['leading_backslash_in_global_namespace' => static function (string $fqcn): bool {
$pluginsRegex = implode('|', array_map(static fn ($v) => preg_quote($v, '~'), scandir(__DIR__ . '/plugins')));
return !preg_match('~^(rc|html|' . $pluginsRegex . ')[^\\\]*$~', $fqcn);
}],
// TODO
'array_indentation' => false,
'general_phpdoc_annotation_remove' => false,

Loading…
Cancel
Save