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
32 changes: 28 additions & 4 deletions Eventjet/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@
<!-- Forbid `AND` and `OR`, require `&&` and `||` -->
<rule ref="Squiz.Operators.ValidLogicalOperators"/>

<!-- Forbid `$this` inside static function -->
<rule ref="Squiz.Scope.StaticThisUsage"/>
<!-- `$this` in a static method is lint territory — PHPStan and Psalm both
flag it. Kept explicitly disabled so future imports of broader rulesets
can't silently re-enable it. -->
<rule ref="Squiz.Scope.StaticThisUsage">
<severity>0</severity>
</rule>

<!-- String concatenation -->
<rule ref="Squiz.Strings.ConcatenationSpacing">
Expand Down Expand Up @@ -148,8 +152,14 @@
</properties>
</rule>

<!-- report invalid format of inline phpDocs with @var -->
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<!-- The other codes (InvalidCommentType, MissingVariable, NoAssignment) are
genuine formatting/structural checks, but InvalidFormat (malformed
`@var` syntax) is lint territory — PHPStan and Psalm both fail to bind
the type when the annotation is malformed. Excluded explicitly so a
future ruleset import can't silently re-enable just that code. -->
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration">
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
</rule>

<!-- checks if Throwable is used instead of Exception -->
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
Expand Down Expand Up @@ -303,4 +313,18 @@
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators">
<severity>0</severity>
</rule>

<!-- Forbid whitespace after `[` and before `]` in single-line arrays;
enforce a single space after commas in single-line arrays -->
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>

<!-- Forbid leading/trailing empty lines inside doc comments -->
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing"/>

<!-- Forbid spaces around `|` and `&` in union/intersection type hints -->
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
<properties>
<property name="withSpacesAroundOperators" value="no"/>
</properties>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"require": {
"php": "^8.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6 || ^0.7 || ^1.0",
"friendsofphp/php-cs-fixer": "^3.32",
"slevomat/coding-standard": "^8.4",
"friendsofphp/php-cs-fixer": "^3.65",
"slevomat/coding-standard": "^8.16",
"squizlabs/php_codesniffer": "^3.6.1",
"webimpress/coding-standard": "^1.1"
},
Expand Down
47 changes: 47 additions & 0 deletions php-cs-fixer-rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
'function_declaration' => [
'closure_fn_spacing' => 'none',
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'api',
'author',
'category',
'copyright',
'created',
'license',
'package',
'since',
'subpackage',
'version',
],
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
Expand All @@ -31,19 +45,25 @@
'heredoc_indentation' => [
'indentation' => 'start_plus_one',
],
'lambda_not_used_import' => true,
'native_constant_invocation' => [
'scope' => 'namespaced',
'strict' => true,
],
'native_function_casing' => true,
'native_function_invocation' => [
'include' => ['@all'],
'scope' => 'namespaced',
'strict' => true,
],
'native_type_declaration_casing' => true,
'new_with_parentheses' => [
'named_class' => true,
'anonymous_class' => false,
],
'no_alias_functions' => [
'sets' => ['@internal'],
],
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
Expand All @@ -59,12 +79,30 @@
],
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_php4_constructor' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => [
// Psalm wants us to have an explicit type annotation whenever we assign `mixed` to a variable.
'allow_mixed' => true,
],
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => [
'statements' => [
'break',
'clone',
'continue',
'echo_print',
'negative_instanceof',
'others',
'return',
'switch_case',
'yield',
'yield_from',
],
],
'no_unneeded_final_method' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_concat_operator' => true,
Expand All @@ -73,8 +111,17 @@
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
// Wrong-order inline `@var` is lint territory — PHPStan and Psalm both
// fail to bind the type. Auto-canonicalizing it on the CS side hides the
// mistake from SA feedback instead of letting the user see and fix it,
// so keep this rule explicitly off (paired with the InvalidFormat exclude
// in Eventjet/ruleset.xml).
'phpdoc_var_annotation_correct_order' => false,
'php_unit_data_provider_static' => true,
'self_accessor' => true,
'simplified_if_return' => true,
'single_quote' => true,
'single_space_around_construct' => true,
// Loose comparison is lint territory — PHPStan and Psalm both flag it. Kept
Expand Down
1 change: 0 additions & 1 deletion php-cs-fixer-strict-rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
'sort_algorithm' => 'none',
'null_adjustment' => 'always_last',
],
'self_accessor' => true,
'static_lambda' => true,
'trailing_comma_in_multiline' => [
'elements' => [
Expand Down
14 changes: 14 additions & 0 deletions tests/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ final class RulesTest extends TestCase
['HeredocNotIndented.php', 'phpcs'],
// PHP CS Fixer has no rule for multiple classes per file
['multiple-classes-per-file.php', 'php-cs-fixer'],
// PHP CS Fixer has no equivalent sniff
['bracketed-namespace.php', 'php-cs-fixer'],
['deprecated-function.php', 'php-cs-fixer'],
['text-before-open-tag.php', 'php-cs-fixer'],
['catch-exception.php', 'php-cs-fixer'],
['assignment-in-condition.php', 'php-cs-fixer'],
['dead-catch.php', 'php-cs-fixer'],
['snake-case-variable.php', 'php-cs-fixer'],
['forbidden-class-comment.php', 'php-cs-fixer'],
['multiple-namespaces.php', 'php-cs-fixer'],
// PHPCS has no equivalent sniff
['blank-line-after-phpdoc.php', 'phpcs'],
['trailing-comma-singleline.php', 'phpcs'],
['multiline-double-arrow.php', 'phpcs'],
];

private static function phpCsFixerCommand(string $file): string
Expand Down
2 changes: 2 additions & 0 deletions tests/check-sa-overlap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ fi
cd "$(dirname "$0")/.."

EXPECTED_REL=(
tests/fixtures/valid/inline-doc-comment.php
tests/fixtures/valid/loose-comparison.php
tests/fixtures/valid/ThisInStatic.php
)

for f in "${EXPECTED_REL[@]}"; do
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/invalid/array-bracket-spacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

declare(strict_types=1);

$foo = ['a' => 1];
$bar = $foo[ 'a' ];
5 changes: 5 additions & 0 deletions tests/fixtures/invalid/array-not-trimmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

$foo = [ 'a', 'b' ];
8 changes: 8 additions & 0 deletions tests/fixtures/invalid/assignment-in-condition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

$bar = 0;
if (($foo = $bar) === 0) {
echo $foo;
}
11 changes: 11 additions & 0 deletions tests/fixtures/invalid/blank-line-after-phpdoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

/**
* Does something
*/

function foo(): void
{
}
9 changes: 9 additions & 0 deletions tests/fixtures/invalid/bracketed-namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Invalid {
class Foo
{
}
}
13 changes: 13 additions & 0 deletions tests/fixtures/invalid/catch-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Invalid;

use Exception;

try {
throw new Exception('boom');
} catch (Exception $e) {
echo $e->getMessage();
}
10 changes: 10 additions & 0 deletions tests/fixtures/invalid/control-signature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

function controlSignatureCheck(bool $cond): void
{
if($cond) {
echo 'yes';
}
}
16 changes: 16 additions & 0 deletions tests/fixtures/invalid/dead-catch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Invalid;

use RuntimeException;
use Throwable;

try {
throw new RuntimeException('boom');
} catch (Throwable $t) {
echo $t->getMessage();
} catch (RuntimeException $e) {
echo $e->getMessage();
}
7 changes: 7 additions & 0 deletions tests/fixtures/invalid/deprecated-function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

use function utf8_encode;

$foo = utf8_encode('test');
14 changes: 14 additions & 0 deletions tests/fixtures/invalid/else-if.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

function elseIfCheck(int $foo): void
{
if ($foo === 1) {
echo 'one';
} else if ($foo === 2) {
echo 'two';
} else {
echo 'other';
}
}
10 changes: 10 additions & 0 deletions tests/fixtures/invalid/empty-comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

//
function foo(): void
{
}

foo();
9 changes: 9 additions & 0 deletions tests/fixtures/invalid/empty-phpdoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

/**
*/
function foo(): void
{
}
11 changes: 11 additions & 0 deletions tests/fixtures/invalid/extra-blank-lines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Invalid;

use stdClass;



new stdClass();
10 changes: 10 additions & 0 deletions tests/fixtures/invalid/forbidden-author-annotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

/**
* @author Jane Doe
*/
function foo(): void
{
}
12 changes: 12 additions & 0 deletions tests/fixtures/invalid/forbidden-class-comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Invalid;

/**
* Class ForbiddenClassComment
*/
class ForbiddenClassComment
{
}
7 changes: 7 additions & 0 deletions tests/fixtures/invalid/forbidden-function-sizeof.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

use function sizeof;

$count = sizeof([1, 2, 3]);
7 changes: 7 additions & 0 deletions tests/fixtures/invalid/group-use.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Invalid;

use Foo\{Bar, Baz};
10 changes: 10 additions & 0 deletions tests/fixtures/invalid/logical-operator-and.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

function logicalOperatorAndCheck(bool $a, bool $b): void
{
if ($a AND $b) {
echo 'yes';
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/invalid/logical-operator-spacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

function logicalOperatorSpacingCheck(bool $a, bool $b): bool
{
return $a&&$b;
}
Loading
Loading