Skip to content

Commit

Permalink
Improve Psalm level (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 17, 2023
1 parent 13476b3 commit 5babb22
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0'?>
<psalm errorLevel='8'
<psalm errorLevel='1'
resolveFromConfigFile='true'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='https://getpsalm.org/schema/config'
Expand Down
22 changes: 16 additions & 6 deletions src/NonDefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

namespace Tpay\CodingStandards;

use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use PhpCsFixerCustomFixers\Fixer\DataProviderStaticFixer;
use ReflectionClass;

final class NonDefaultConfig
{
/** @return null|array<string, mixed> */
Expand All @@ -24,14 +20,28 @@ public static function getNonDefaultConfig(string $name): ?array
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'native_constant_invocation' => ['fix_built_in' => false, 'include' => [], 'scope' => 'all', 'strict' => true],
'native_function_invocation' => ['include' => [], 'scope' => 'all', 'strict' => true],
'no_extra_blank_lines' => ['tokens' => array_diff((new ReflectionClass(NoExtraBlankLinesFixer::class))->getStaticPropertyValue('availableTokens'), ['use_trait'])],
'no_extra_blank_lines' => ['tokens' => [
'attribute',
'break',
'case',
'continue',
'curly_brace_block',
'default',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'switch',
'throw',
'use',
]],
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'function', 'const']],
'php_unit_data_provider_name' => ['prefix' => 'data', 'suffix' => ''],
'php_unit_data_provider_static' => ['force' => true],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_line_span' => ['const' => 'single', 'method' => 'single', 'property' => 'single'],
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
DataProviderStaticFixer::name() => ['force' => true],
][$name] ?? null;
}
}
18 changes: 12 additions & 6 deletions src/PhpCsFixerConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ public static function createWithLegacyRules(): ConfigInterface

private static function create(int $type): ConfigInterface
{
$fixers = [
...(new FixerFactory())->registerBuiltInFixers()->getFixers(),
...(new Fixers()),
];

$rules = [];

foreach ($fixers as $fixer) {
foreach (self::getFixers() as $fixer) {
if ($fixer instanceof DeprecatedFixerInterface) {
continue;
}
Expand All @@ -54,6 +49,17 @@ private static function create(int $type): ConfigInterface
->setRules($rules);
}

/** @return iterable<FixerInterface> */
private static function getFixers(): iterable
{
foreach ((new FixerFactory())->registerBuiltInFixers()->getFixers() as $fixer) {
yield $fixer;
}
foreach (new Fixers() as $fixer) {
yield $fixer;
}
}

/** @return array<string, mixed>|bool */
private static function getConfig(int $type, FixerInterface $fixer)
{
Expand Down

0 comments on commit 5babb22

Please sign in to comment.