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
10 changes: 5 additions & 5 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

ARG PHP_VERSION=8.4
ARG COMPOSER_VERSION=2.10
ARG CS_BRANCH=3.13.5
ARG CS_BRANCH=4.0.1

FROM composer:${COMPOSER_VERSION} AS composer_image

FROM php:${PHP_VERSION}-cli-alpine AS dev_image
ARG CS_BRANCH
COPY --from=ghcr.io/mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN set -eu; \
apk upgrade --no-cache --quiet; \
Expand All @@ -20,7 +19,8 @@ RUN set -eu; \
# xdebug code coverage requires more memory than default amount.
COPY --from=composer_image --link /usr/bin/composer /usr/local/bin/composer
WORKDIR /usr/src/cs-test/
RUN set -eu; \
ARG CS_BRANCH
RUN set -eux; \
git clone https://github.com/PHPCSStandards/PHP_CodeSniffer.git --branch ${CS_BRANCH} --single-branch . \
&& composer install \
&& composer require --dev --no-scripts --no-plugins max-antipin/php-code-sniffs
Expand All @@ -34,5 +34,5 @@ RUN --mount=type=bind,from=git-files,source=.,target=.git,readonly \
composer validate; \
composer install --no-autoloader --no-progress; \
composer dump-autoload --classmap-authoritative --strict-psr --strict-ambiguous
COPY phpunit.9.xml /usr/src/cs-test/phpunit.xml
COPY --from=source ./AntipinCS/ /usr/src/cs-test/src/Standards/AntipinCS/
COPY --link phpunit.cs.xml /usr/src/cs-test/phpunit.xml
COPY --from=source --link ./AntipinCS/ /usr/src/cs-test/src/Standards/AntipinCS/
2 changes: 1 addition & 1 deletion .docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ services:
volumes: *volumes
configs:
phpunit-cs:
file: ./phpunit.9.xml
file: ./phpunit.cs.xml
xdebug:
file: ./xdebug.ini
30 changes: 0 additions & 30 deletions .docker/phpunit.9.xml

This file was deleted.

40 changes: 40 additions & 0 deletions .docker/phpunit.cs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
backupGlobals="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
beStrictAboutCoverageMetadata="true"
executionOrder="random"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
failOnPhpunitDeprecation="true"
requireCoverageMetadata="true"
cacheDirectory=".phpunit.cache"
colors="true">
<testsuites>
<testsuite name="AntipinCS">
<directory>src/Standards/AntipinCS/Tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/Standards/AntipinCS/</directory>
</include>
<exclude>
<directory>src/Standards/AntipinCS/Tests/</directory>
</exclude>
</source>
<coverage pathCoverage="true" includeUncoveredFiles="true">
<report>
<html outputDirectory="/tmp/coverage-report/" lowUpperBound="50" highLowerBound="90"/>
</report>
</coverage>
</phpunit>
35 changes: 2 additions & 33 deletions AntipinCS/Sniffs/Functions/ParameterTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,7 @@ public function process(File $phpcsFile, int $stackPtr): void
);
return;
}
$this->processBracket($phpcsFile, $token['parenthesis_opener']);
if ($token['code'] === T_CLOSURE) {
$use = $phpcsFile->findNext(T_USE, ($token['parenthesis_closer'] + 1), $token['scope_opener']);
if ($use !== false) {
$openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
if (false === $openBracket) {
throw new RuntimeException('Parse error');
}
$this->processBracket($phpcsFile, $openBracket);
}
}
}

protected function processBracket(File $phpcsFile, int $openBracket): void
{
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$openBracket]['parenthesis_owner'])) {
$stackPtr = $tokens[$openBracket]['parenthesis_owner'];
} else {
$stackPtr = $phpcsFile->findPrevious(T_USE, ($openBracket - 1));
if (false === $stackPtr) {
$phpcsFile->addError(
'Unknown error',
$openBracket,
'Unknown',
[],
9
);
}
# else: use condition found, skip it.
return;
}
$stackPtr = $token['parenthesis_owner'];
$params = $phpcsFile->getMethodParameters($stackPtr);
if (empty($params)) {
return;
Expand Down Expand Up @@ -163,7 +132,7 @@ private function ignoreMethod(File $phpcsFile, int $stackPtr): bool
* use ValueError;
* use \ErrorException;
* use PHP_CodeSniffer\Files\File;
* use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest as SomeKindOfTests;
* use PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase as SomeKindOfTests;
* use PHPstan\Command\{AnalyseCommand,AnalyserResult as TmpResult,AnalyseApplication\TestApp};
* use function file_get_contents;
* use const JSON_BIGINT_AS_STRING;
Expand Down
3 changes: 1 addition & 2 deletions AntipinCS/Sniffs/Functions/ReturnTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function process(File $phpcsFile, int $stackPtr): void
static $skipMethods = ['__construct' => true, '__destruct' => true];
if (
!isset($skipTypes[$token['type']])
&& ($methodName = $phpcsFile->getDeclarationName($stackPtr)) !== null
&& isset($skipMethods[$methodName])
&& isset($skipMethods[$phpcsFile->getDeclarationName($stackPtr)])
) {
return;
}
Expand Down
12 changes: 5 additions & 7 deletions AntipinCS/Tests/Classes/PropertyTypeDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

namespace MaxAntipin\PHPCS\Standards\AntipinCS\Tests\Classes;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
use MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Classes\PropertyTypeDeclarationSniff;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* Unit test class for the PropertyTypeDeclaration sniff.
*
* @covers \MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Classes\PropertyTypeDeclarationSniff
*/
final class PropertyTypeDeclarationUnitTest extends AbstractSniffUnitTest
#[CoversClass(PropertyTypeDeclarationSniff::class)]
final class PropertyTypeDeclarationUnitTest extends AbstractSniffTestCase
{
/**
* Returns the lines where errors should occur.
Expand Down
12 changes: 5 additions & 7 deletions AntipinCS/Tests/Functions/ParameterTypeDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

namespace MaxAntipin\PHPCS\Standards\AntipinCS\Tests\Functions;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
use MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Functions\ParameterTypeDeclarationSniff;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* Unit test class for the ParameterTypeDeclaration sniff.
*
* @covers \MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Functions\ParameterTypeDeclarationSniff
*/
final class ParameterTypeDeclarationUnitTest extends AbstractSniffUnitTest
#[CoversClass(ParameterTypeDeclarationSniff::class)]
final class ParameterTypeDeclarationUnitTest extends AbstractSniffTestCase
{
/**
* Get a list of all test files to check.
Expand Down
10 changes: 5 additions & 5 deletions AntipinCS/Tests/Functions/ReturnTypeDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace MaxAntipin\PHPCS\Standards\AntipinCS\Tests\Functions;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
use MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Functions\ReturnTypeDeclarationSniff;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* @covers \MaxAntipin\PHPCS\Standards\AntipinCS\Sniffs\Functions\ReturnTypeDeclarationSniff
*/
final class ReturnTypeDeclarationUnitTest extends AbstractSniffUnitTest
#[CoversClass(ReturnTypeDeclarationSniff::class)]
final class ReturnTypeDeclarationUnitTest extends AbstractSniffTestCase
{
/**
* Get a list of all test files to check.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fix-lint:
php ./vendor/bin/phpcbf

test-cs:
cd ../cs-test/ && php ./vendor/bin/phpunit --no-coverage --filter AntipinCS
cd ../cs-test/ && php ./vendor/bin/phpunit --no-coverage -v -s --filter AntipinCS

test-coverage:
cd ../cs-test/ && XDEBUG_MODE=coverage php ./vendor/bin/phpunit --filter AntipinCS
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ Run test containers with all PHP versions and code coverage:
```Shell
docker compose -f .docker/compose-test.yaml up --quiet-build
```

Two errors with property hooks:
- There must not be more than one property declared per statement
- Missing type declaration for property "$this"

```Shell
cat AntipinCS/Tests/Functions/ReturnTypeDeclarationUnitTest.2.inc | ./vendor/bin/phpcs --stdin-path=/php-code-sniffs/AntipinCS/Tests/Functions/ReturnTypeDeclarationUnitTest.2.php -v -s -
```
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpcsstandards/phpcsdevtools": "^1.2",
"max-antipin/packagist-export-ignore": "^1"
"max-antipin/packagist-export-ignore": "^1",
"phpunit/phpunit": "^11"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<property name="ignore" type="array">
<element key="PHP_CodeSniffer\Sniffs\Sniff" value="process"/>
<element key="PHP_CodeSniffer\Sniffs\AbstractVariableSniff" value="processMemberVar,processVariable,processVariableInString"/>
<element key="PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest" value="getTestFiles"/>
<element key="PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase" value="getTestFiles"/>
</property>
</properties>
</rule>
Expand Down
Loading