Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php-versions: ['7.4', '8.0', '8.1', '8.2']

runs-on: ${{ matrix.operating-system }}

Expand Down
35 changes: 30 additions & 5 deletions .php_cs → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
->name('*.php');


return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config)
->setUsingCache(true)
->setIndent("\t")
->setLineEnding("\n")
//->setUsingLinter(false)
->setRiskyAllowed(true)
->setRules(
[
'@PHPUnit60Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'this',
],

'concat_space' => [
'concat_space' => [
'spacing' => 'one',
],

Expand All @@ -36,7 +36,10 @@
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,

'array_indentation' => true,

'no_whitespace_in_blank_line' => true,
'no_trailing_whitespace' => true,

'phpdoc_add_missing_param_annotation' => [ 'only_untyped' => true, ],
'phpdoc_indent' => true,
Expand Down Expand Up @@ -84,6 +87,7 @@

'single_line_after_imports' => true,
'single_blank_line_before_namespace' => true,
'single_line_comment_spacing' => true,
'blank_line_after_namespace' => true,
'single_blank_line_at_eof' => true,
'ternary_to_null_coalescing' => true,
Expand All @@ -102,11 +106,11 @@
],

'blank_line_before_statement' => [
'statements' => [ 'continue', 'try', 'switch', 'die', 'exit', 'throw', 'return', 'yield', 'do' ],
'statements' => [ 'continue', 'try', 'switch', 'exit', 'throw', 'return', 'yield', 'do' ],
],

'no_superfluous_phpdoc_tags' => [
'remove_inheritdoc' => false, // specifically for this, for now
'remove_inheritdoc' => true,
],
'no_superfluous_elseif' => true,

Expand All @@ -118,6 +122,7 @@
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'heredoc_to_nowdoc' => true,
'heredoc_indentation' => true,


'no_singleline_whitespace_before_semicolons' => true,
Expand Down Expand Up @@ -148,6 +153,26 @@
'elseif' => true,

'simple_to_complex_string_variable' => true,

'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],

'trailing_comma_in_multiline' => true,
'single_line_comment_style' => true,

'is_null' => true,
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => null,
],

'empty_loop_condition' => [
'style' => 'for',
],
]
)
->setFinder($finder);
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "*",
"squizlabs/php_codesniffer": "*",
"slevomat/coding-standard": "~7.0.2",
"php": ">=7.1"
"slevomat/coding-standard": "^8.3",
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": ">=7.0",
"phpunit/phpunit": "^9.5",
"donatj/drop": "^1.0",
"friendsofphp/php-cs-fixer": "^2.18"
"friendsofphp/php-cs-fixer": "^3.14"
},
"authors": [
{
Expand Down
16 changes: 6 additions & 10 deletions src/Corpus/Sniffs/ControlStructures/ClosingBraceNewlineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@ class ClosingBraceNewlineSniff implements Sniff {

public const CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET = 'MustNewlineFollowingCurlyBracket';

/**
* @inheritDoc
*/
public function register() {
public function register() : array {
return [ T_CLOSE_CURLY_BRACKET ];
}

/**
* @inheritDoc
*/
public function process( File $phpcsFile, $stackPtr ) {
public function process( File $phpcsFile, $stackPtr ) : void {
$tokens = $phpcsFile->getTokens();

$prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
Expand All @@ -68,9 +62,11 @@ public function process( File $phpcsFile, $stackPtr ) {
return;
}

$fix = $phpcsFile->addFixableError('Must be a newline following closing curly bracket',
$fix = $phpcsFile->addFixableError(
'Must be a newline following closing curly bracket',
$stackPtr,
self::CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET);
self::CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET
);
if( $fix ) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->addNewline($stackPtr);
Expand Down
13 changes: 4 additions & 9 deletions src/Corpus/Sniffs/ControlStructures/OpeningOneTrueBraceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ class OpeningOneTrueBraceSniff implements Sniff {

public const CODE_BRACE_ON_NEWLINE = 'BraceOnNewLine';

/**
* @inheritDoc
*/
public function register() {
public function register() : array {
return [ T_OPEN_CURLY_BRACKET ];
}

/**
* @inheritDoc
*/
public function process( File $phpcsFile, $stackPtr ) {
public function process( File $phpcsFile, $stackPtr ) : void {
$tokens = $phpcsFile->getTokens();
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, 0, true);
if( !$prev || $tokens[$prev]['line'] === $tokens[$stackPtr]['line'] ) {
Expand All @@ -67,7 +61,8 @@ public function process( File $phpcsFile, $stackPtr ) {
$fix = $phpcsFile->addFixableError(
'Opening brace should be on the same line as the declaration',
$stackPtr,
self::CODE_BRACE_ON_NEWLINE);
self::CODE_BRACE_ON_NEWLINE
);
if( $fix ) {
$phpcsFile->fixer->beginChangeset();
for( $i = $prev + 1; $i < $stackPtr; $i++ ) {
Expand Down
13 changes: 4 additions & 9 deletions src/Corpus/Sniffs/General/BinaryOperationNewlineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,20 @@ class BinaryOperationNewlineSniff implements Sniff {

public const CODE_BOOLEAN_OPERATION_SHOULD_LEAD_LINE = 'BooleanOperationShouldLeadLine';

/**
* @inheritDoc
*/
public function register() {
public function register() : array {
return [ T_BOOLEAN_AND, T_BOOLEAN_OR ];
}

/**
* @inheritDoc
*/
public function process( File $phpcsFile, $stackPtr ) {
public function process( File $phpcsFile, $stackPtr ) : void {
$tokens = $phpcsFile->getTokens();

$nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
if( $tokens[$stackPtr]['line'] + 1 !== $tokens[$nextPtr]['line'] ) {
return;
}

$fix = $phpcsFile->addFixableError('Boolean %s should start line and not end previous line',
$fix = $phpcsFile->addFixableError(
'Boolean %s should start line and not end previous line',
$stackPtr,
self::CODE_BOOLEAN_OPERATION_SHOULD_LEAD_LINE,
[ $tokens[$stackPtr]['content'] ]
Expand Down
10 changes: 2 additions & 8 deletions src/Corpus/Sniffs/General/ReturnTrailingNewlineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,11 @@ class ReturnTrailingNewlineSniff implements Sniff {

public const CODE_RETURN_HAS_TRAILING_NEWLINE = 'ReturnHasTrailingNewline';

/**
* @inheritDoc
*/
public function register() {
public function register() : array {
return [ T_RETURN ];
}

/**
* @inheritDoc
*/
public function process( File $phpcsFile, $stackPtr ) {
public function process( File $phpcsFile, $stackPtr ) : void {
$tokens = $phpcsFile->getTokens();

$eosPtr = $phpcsFile->findEndOfStatement($stackPtr);
Expand Down
10 changes: 2 additions & 8 deletions src/Corpus/Sniffs/Methods/MethodParameterFormattingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ class MethodParameterFormattingSniff implements Sniff {

public const CODE_OVERLY_LONG_ARGUMENT_LIST = 'OverlyLongArgumentList';

/**
* @inheritDoc
*/
public function register() {
public function register() : array {
return [ T_FUNCTION, T_CLOSURE ];
}

/**
* @inheritDoc
*/
public function process( File $phpcsFile, $stackPtr ) {
public function process( File $phpcsFile, $stackPtr ) : void {
$tokens = $phpcsFile->getTokens();

$scopePtr = $tokens[$stackPtr]['scope_opener'] ?? $phpcsFile->findEndOfStatement($stackPtr);
Expand Down