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
4 changes: 2 additions & 2 deletions .github/workflows/validate-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ concurrency:

jobs:
validate:
uses: croct-tech/github-workflows/.github/workflows/php-validations.yml@master
uses: croct-tech/github-workflows/.github/workflows/php-validations.yml@bump-php
secrets:
REPMAN_TOKEN: ${{ secrets.REPMAN_TOKEN }}

sniffs:
runs-on: ubuntu-latest
container:
image: crocttech/php-base-image:php8.1-dev
image: crocttech/php-base-image:php8.5-dev
env:
PACKAGE: coding-standard
steps:
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
],
"homepage": "https://github.com/croct-tech/coding-standard-php",
"require": {
"php": "^8.1",
"slevomat/coding-standard": "^8.0",
"squizlabs/php_codesniffer": "^3.7"
"php": "^8.5",
"slevomat/coding-standard": "^8.28",
"squizlabs/php_codesniffer": "^4.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.28",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2",
"phpunit/phpunit": "^10.0"
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^13.1"
},
"prefer-stable": true,
"autoload": {
Expand Down
1,460 changes: 803 additions & 657 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<config name="installed_paths" value="../../../src"/>
<config name="installed_paths" value="../../../src,../../../vendor/slevomat/coding-standard"/>

<arg name="cache" value=".cache/phpcs.cache.json"/>
<arg name="basepath" value="."/>
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ parameters:
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
checkMissingCallableSignature: true
checkGenericClassInNonGenericObjectType: true
13 changes: 6 additions & 7 deletions src/Croct/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
>
<description>The Croct Coding Standard.</description>

<config name="installed_paths" value="../../slevomat/coding-standard"/>

<!-- Croct sniffs -->

<!-- Force camel-cased names, except for constant-like methods -->
Expand Down Expand Up @@ -43,11 +41,12 @@
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="maxPadding" value="1" />
<property name="error" value="true"/>
</properties>
</rule>
<!-- Force whitespace after a type cast -->
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<!-- Require space after language constructs -->
<rule ref="Generic.WhiteSpace.LanguageConstructSpacing"/>
<!-- Disallow PHP 4 constructors -->
<rule ref="Generic.NamingConventions.ConstructorName"/>
<!-- Disallow backtick operator -->
Expand Down Expand Up @@ -394,6 +393,7 @@
<property name="allowFullyQualifiedGlobalClasses" value="true"/>
<property name="allowFullyQualifiedGlobalFunctions" value="true"/>
<property name="allowFullyQualifiedGlobalConstants" value="true"/>
<property name="allowFullyQualifiedExceptions" value="true"/>
</properties>
</rule>
<!-- Requires only one namespace in a file -->
Expand Down Expand Up @@ -510,9 +510,10 @@
</properties>
</rule>
<!-- Enforce the format of union type hints -->
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
<properties>
<property name="withSpaces" value="no"/>
<property name="withSpacesAroundOperators" value="no"/>
<property name="withSpacesInsideParentheses" value="no"/>
<property name="shortNullable" value="yes"/>
</properties>
</rule>
Expand Down Expand Up @@ -632,8 +633,6 @@
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<!-- Disallow blank line after function opening brace -->
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
<!-- Require space after language constructs -->
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<!-- Require space around logical operators -->
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<!-- Disallow spaces around `->` operator -->
Expand Down
9 changes: 5 additions & 4 deletions tests/Integration/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ array-indentation.php 10 0
assignment-operators.php 4 0
chained-method-call.php 2 0
class-references.php 10 0
concatenation-spacing.php 35 0
concatenation-spacing.php 29 6
constants-var.php 3 0
doc-comment-spacing.php 22 0
example-class.php 38 1
example-class.php 35 4
forbidden-comments.php 6 0
forbidden-functions.php 6 0
fully-qualified-exception.php 3 0
LowCaseTypes.php 4 0
namespaces-spacing.php 3 0
new-with-parentheses.php 16 0
Expand All @@ -27,9 +28,9 @@ traits-uses.php 7 0
UnusedVariables.php 3 0
useless-semicolon.php 2 0
----------------------------------------------------------------------
A TOTAL OF 247 ERRORS AND 1 WARNING WERE FOUND IN 23 FILES
A TOTAL OF 241 ERRORS AND 10 WARNINGS WERE FOUND IN 24 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 201 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 203 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


7 changes: 7 additions & 0 deletions tests/Integration/fixed/fully-qualified-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

try {
} catch (\Throwable) {
}
7 changes: 7 additions & 0 deletions tests/Integration/input/fully-qualified-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

try {
} catch (Exception $t) {
}
19 changes: 13 additions & 6 deletions tests/Sniffs/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ protected static function assertSniffError(File $phpcsFile, int $line, string $c

$sniffCode = \sprintf('%s.%s', static::getSniffName(), $code);

/** @var array<array<array<string|int>>> $errorsOnLine */
$errorsOnLine = $errors[$line];

self::assertTrue(
self::hasError($errors[$line], $sniffCode, $message),
self::hasError($errorsOnLine, $sniffCode, $message),
\sprintf(
'Expected error %s%s, but none found on line %d.%sErrors found on line %d:%s%s%s',
$sniffCode,
Expand All @@ -94,7 +97,7 @@ protected static function assertSniffError(File $phpcsFile, int $line, string $c
\PHP_EOL . \PHP_EOL,
$line,
\PHP_EOL,
self::getFormattedErrors($errors[$line]),
self::getFormattedErrors($errorsOnLine),
\PHP_EOL
)
);
Expand All @@ -106,13 +109,17 @@ protected static function assertSniffError(File $phpcsFile, int $line, string $c
protected static function assertNoSniffError(File $phpcsFile, int $line) : void
{
$errors = $phpcsFile->getErrors();

/** @var array<array<array<string|int>>> $errorsOnLine */
$errorsOnLine = $errors[$line];

self::assertFalse(
isset($errors[$line]),
\sprintf(
'Expected no error on line %s, but found:%s%s%s',
$line,
\PHP_EOL . \PHP_EOL,
isset($errors[$line]) ? self::getFormattedErrors($errors[$line]) : '',
isset($errors[$line]) ? self::getFormattedErrors($errorsOnLine) : '',
\PHP_EOL
)
);
Expand Down Expand Up @@ -161,11 +168,12 @@ protected static function getSniffClassName() : string
*/
protected static function getSniffClassReflection() : ReflectionClass
{
/** @var array<class-string, ReflectionClass<Sniff>> $reflections */
static $reflections = [];

/** @phpstan-var class-string $className */
$className = static::getSniffClassName();

/** @var class-string<Sniff> $className */
return $reflections[$className] ?? $reflections[$className] = new ReflectionClass($className);
}

Expand Down Expand Up @@ -211,7 +219,7 @@ static function (array $errors) : string {
\PHP_EOL,
\array_map(
static function (array $error) : string {
return \sprintf("\t%s: %s", $error['source'], $error['message']);
return \sprintf("\t%s: %s", (string) $error['source'], (string) $error['message']);
},
$errors
)
Expand All @@ -221,5 +229,4 @@ static function (array $error) : string {
)
);
}

}
Loading