Skip to content

Commit

Permalink
Rely on @PhpCsFixer sets and remove custom $type (#6)
Browse files Browse the repository at this point in the history
* First step: no type

* Rely on @PhpCsFixer sets
  • Loading branch information
Slamdunk committed Feb 7, 2020
1 parent ab6c077 commit 67e3351
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$config = new SlamCsFixer\Config(SlamCsFixer\Config::LIB);
$config = new SlamCsFixer\Config();
$config->getFinder()
->notPath('_files/utf8-ansi.php')
->in(__DIR__ . '/lib')
Expand Down
192 changes: 69 additions & 123 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,79 @@

final class Config extends PhpCsFixerConfig
{
public const APP_V1 = 'APP_V1';
public const APP_V2 = 'APP_V2';
public const LIB = 'LIB';
public const RULES = [
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@DoctrineAnnotation' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'Slam/final_abstract_public' => true,
'Slam/final_internal_class' => true,
'Slam/function_reference_space' => true,
'Slam/php_only_braces' => true,
'Slam/php_only_slam_inline_comment_spacer' => true,
'Slam/utf8' => true,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'backtick_to_shell_exec' => true,
'binary_operator_spaces' => ['default' => 'align_single_space'],
'braces' => false, // See Slam/php_only_braces
'class_keyword_remove' => false,
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'comment_to_phpdoc' => false,
'concat_space' => ['spacing' => 'one'],
'date_time_immutable' => false,
'error_suppression' => false,
'final_class' => false,
'final_internal_class' => false,
'final_public_method_for_abstract_class' => false,
'final_static_access' => true,
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => true,
'header_comment' => false,
'heredoc_indentation' => false,
'linebreak_after_opening_tag' => true,
'list_syntax' => true,
'mb_str_functions' => false,
'method_argument_space' => ['keep_multiple_spaces_after_comma' => true],
'native_constant_invocation' => true,
'native_function_invocation' => true,
'no_blank_lines_before_namespace' => false,
'no_multiline_whitespace_around_double_arrow' => false,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_class_elements' => ['order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method']],
'ordered_interfaces' => true,
'php_unit_internal_class' => false,
'php_unit_size_class' => false,
'php_unit_strict' => false,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_line_span' => true,
'phpdoc_to_param_type' => false,
'phpdoc_to_return_type' => false,
'pow_to_exponentiation' => false,
'psr0' => true,
'random_api_migration' => true,
'self_static_accessor' => true,
'simple_to_complex_string_variable' => false,
'simplified_null_return' => false,
'single_line_throw' => false,
'space_after_semicolon' => true,
'static_lambda' => false,
'unary_operator_spaces' => false,
];

/**
* @param array<string, mixed> $overriddenRules
*/
public function __construct(string $type = self::APP_V2, array $overriddenRules = [])
public function __construct(array $overriddenRules = [])
{
parent::__construct(\sprintf('%s:%s', __NAMESPACE__, $type));
parent::__construct(__NAMESPACE__);
\putenv('PHP_CS_FIXER_FUTURE_MODE=1');

// @codeCoverageIgnoreStart
Expand All @@ -38,124 +101,7 @@ public function __construct(string $type = self::APP_V2, array $overriddenRules
new Utf8Fixer(),
]);

$rules = [
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'Slam/final_abstract_public' => self::APP_V1 !== $type,
'Slam/final_internal_class' => self::APP_V1 !== $type,
'Slam/function_reference_space' => true,
'Slam/php_only_braces' => true,
'Slam/php_only_slam_inline_comment_spacer' => true,
'Slam/utf8' => self::APP_V1 !== $type,
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
'array_indentation' => true,
'array_syntax' => ['syntax' => self::LIB === $type ? 'short' : 'long'],
'backtick_to_shell_exec' => true,
'binary_operator_spaces' => ['default' => 'align_single_space'],
'blank_line_before_statement' => true,
'braces' => false,
'class_definition' => ['singleItemSingleLine' => true],
'class_keyword_remove' => false,
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'comment_to_phpdoc' => false,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'date_time_immutable' => false,
'declare_strict_types' => self::APP_V1 !== $type,
'doctrine_annotation_array_assignment' => true,
'doctrine_annotation_spaces' => true,
'encoding' => self::APP_V1 !== $type,
'error_suppression' => false,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'final_class' => false,
'final_internal_class' => false,
'final_public_method_for_abstract_class' => false,
'final_static_access' => true,
'fully_qualified_strict_types' => true,
'function_to_constant' => ['functions' => ['get_class', 'get_called_class', 'php_sapi_name', 'phpversion', 'pi']],
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => true,
'header_comment' => false,
'heredoc_indentation' => false,
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => true,
'logical_operators' => self::LIB === $type,
'mb_str_functions' => self::APP_V2 === $type,
'method_argument_space' => ['keep_multiple_spaces_after_comma' => true],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'native_constant_invocation' => self::LIB === $type,
'native_function_invocation' => self::LIB === $type,
'no_alternative_syntax' => true,
'no_binary_string' => true,
'no_blank_lines_before_namespace' => false,
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'use_trait', 'curly_brace_block', 'parenthesis_brace_block', 'square_brace_block']],
'no_multiline_whitespace_around_double_arrow' => false,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_cast' => true,
'no_unset_on_property' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_class_elements' => ['order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method']],
'ordered_imports' => true,
'ordered_interfaces' => true,
'php_unit_internal_class' => false,
'php_unit_method_casing' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_size_class' => false,
'php_unit_strict' => false,
'php_unit_test_annotation' => true,
'php_unit_test_case_static_method_calls' => true,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_line_span' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_to_param_type' => false,
'phpdoc_to_return_type' => false,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => true,
'phpdoc_var_annotation_correct_order' => true,
'pow_to_exponentiation' => false,
'protected_to_private' => true,
'psr0' => true,
'random_api_migration' => true,
'return_assignment' => true,
'self_static_accessor' => true,
'semicolon_after_instruction' => true,
'simple_to_complex_string_variable' => false,
'simplified_null_return' => true,
'single_line_comment_style' => true,
'single_line_throw' => false,
'single_quote' => ['strings_containing_single_quote_chars' => true],
'space_after_semicolon' => true,
'static_lambda' => false,
'strict_comparison' => self::APP_V1 !== $type,
'strict_param' => self::APP_V1 !== $type,
'string_line_ending' => true,
'unary_operator_spaces' => false,
'void_return' => false,
'yoda_style' => true,
];
$rules = self::RULES;
if (! empty($overriddenRules)) {
$rules = \array_merge($rules, $overriddenRules);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/FinalAbstractPublicFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function isRisky()
return true;
}

protected function applyFix(SplFileInfo $file, Tokens $tokens)
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
$classes = \array_keys($tokens->findGivenKind(\T_CLASS));

Expand All @@ -61,7 +61,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
}
}

private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIndex)
private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIndex): void
{
for ($index = $classCloseIndex - 1; $index > $classOpenIndex; --$index) {
if ($tokens[$index]->equals('}')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/FinalInternalClassFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function isRisky()
return true;
}

protected function applyFix(SplFileInfo $file, Tokens $tokens)
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
$classes = \array_keys($tokens->findGivenKind(\T_CLASS));

Expand Down
2 changes: 1 addition & 1 deletion lib/FunctionReferenceSpaceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function isCandidate(Tokens $tokens)
return $tokens->isTokenKindFound(\T_FUNCTION);
}

protected function applyFix(SplFileInfo $file, Tokens $tokens)
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
for ($index = $tokens->count() - 1; $index > 0; --$index) {
if (! $tokens[$index]->isGivenKind(\T_FUNCTION)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/InlineCommentSpacerFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function isCandidate(Tokens $tokens)
return $tokens->isTokenKindFound(\T_COMMENT);
}

protected function applyFix(SplFileInfo $file, Tokens $tokens)
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
foreach ($tokens as $index => $token) {
$content = $token->getContent();
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpFileOnlyProxyFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(FixerInterface $fixer)
$this->fixer = $fixer;
}

public function configure(?array $configuration = null)
public function configure(?array $configuration = null): void
{
if (! $this->fixer instanceof ConfigurationDefinitionFixerInterface) {
return;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function resolve(array $configuration)
return $this->fixer->getConfigurationDefinition();
}

public function setWhitespacesConfig(WhitespacesFixerConfig $config)
public function setWhitespacesConfig(WhitespacesFixerConfig $config): void
{
if (! $this->fixer instanceof WhitespacesAwareFixerInterface) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/Utf8Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function isRisky()
return true;
}

protected function applyFix(SplFileInfo $file, Tokens $tokens)
protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
$content = $tokens->generateCode();
if (false === \mb_check_encoding($content, 'UTF-8')) {
Expand Down
6 changes: 2 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- phar://phpstan.phar/conf/config.levelmax.neon
- phar://phpstan.phar/conf/config.level5.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon
Expand All @@ -9,6 +9,4 @@ parameters:
- lib/
- tests/
ignoreErrors:
- '#Parameter .+ given#'
- '#Method .+ has no return typehint specified#'
- '#Method .+ has parameter .+ with no value type specified in iterable type array#'
- '#^Parameter \#2 \$items of method PhpCsFixer\\Tokenizer\\Tokens::insertAt\(\) expects .+, array<int, PhpCsFixer\\Tokenizer\\Token> given.$#'
Loading

0 comments on commit 67e3351

Please sign in to comment.