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
24 changes: 10 additions & 14 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#syntax=docker/dockerfile:1.16

ARG PHP_VERSION=8.3
ARG COMPOSER_VERSION=2.9
ARG PHP_VERSION=8.4
ARG COMPOSER_VERSION=2.10
ARG CS_BRANCH=3.13.5

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 update \
&& apk upgrade \
&& apk add --no-cache git linux-headers make \
&& apk add --update --no-cache --virtual .build-dependencies $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& pecl clear-cache \
&& apk del .build-dependencies \
&& mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
&& rm /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini; \
set -eux; \
sed -i "s|\(memory_limit =\) [1-9]\+[a-zA-Z]\+|\1 1G|" "$PHP_INI_DIR/php.ini"
apk upgrade --no-cache --quiet; \
apk add --no-cache git make; \
install-php-extensions xdebug; \
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"; \
rm /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini; \
set -eux; \
sed -i "s|\(memory_limit =\) [1-9]\+[a-zA-Z]\+|\1 1G|" "$PHP_INI_DIR/php.ini"
# 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/
Expand Down
4 changes: 2 additions & 2 deletions .docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
php-dev:
build:
args:
- PHP_VERSION=${PHP_VERSION:-8.3}
- PHP_VERSION=${PHP_VERSION:-8.4}
context: ../.
dockerfile: ./.docker/Dockerfile
target: dev_image
Expand All @@ -22,7 +22,7 @@ services:
- ../.:/usr/src/app/
- ../AntipinCS/:/usr/src/cs-test/src/Standards/AntipinCS/:ro
- ../var/coverage-report/:/tmp/coverage-report/
dev-coverage:
php-dev-coverage:
build:
args:
- PHP_VERSION=8.4
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ Makefile export-ignore
*.dist export-ignore
Tests export-ignore

*.inc text eol=lf
*.php text eol=lf
*.sh text eol=lf
.docker/* text eol=lf
4 changes: 2 additions & 2 deletions AntipinCS/Sniffs/Classes/PropertyTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr): void
/**
* Processes normal variables.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
Expand All @@ -76,7 +76,7 @@ protected function processVariable(File $phpcsFile, $stackPtr): void
/**
* Processes variables in double quoted strings.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
Expand Down
13 changes: 7 additions & 6 deletions AntipinCS/Sniffs/Functions/ParameterTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

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

use Generator;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
use RuntimeException;

class ParameterTypeDeclarationSniff implements Sniff
{
private const RX_FQCN =
private const string RX_FQCN =
'/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*(\\\\[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)+$/';

/**
Expand Down Expand Up @@ -120,10 +121,10 @@ private function ignoreMethod(File $phpcsFile, int $stackPtr): bool
$fToken = $tokens[$stackPtr];
if (
$this->itemsToIgnore === []
// Anonymous or arrow functions can not be ignored.
// Anonymous or arrow functions can't be ignored.
|| $fToken['type'] !== 'T_FUNCTION'
|| false === ($cStackPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr))
// Private methods can not be ignored.
// Private methods can't be ignored.
|| $phpcsFile->getMethodProperties($stackPtr)['scope'] === 'private'
|| ($cToken = $tokens[$cStackPtr]) && ($cToken['level'] - $fToken['level'] > 1)
|| !($names = $this->getParentNames($phpcsFile, $cStackPtr))
Expand Down Expand Up @@ -240,7 +241,7 @@ protected function findClassImports(File $phpcsFile, ?int $limitPtr = null): arr
) use (
$getTokenAs,
$trimStringTokens
): \Generator {
): Generator {
$tokens = $phpcsFile->getTokens();
$endPtr = $limitPtr;
$trimStringTokens($phpcsFile, $startPtr, $endPtr);
Expand All @@ -255,7 +256,7 @@ protected function findClassImports(File $phpcsFile, ?int $limitPtr = null): arr
) use (
$getTokenAs,
$trimStringTokens
): \Generator {
): Generator {
$trimStringTokens($phpcsFile, $startPtr, $endPtr);
$tokens = $phpcsFile->getTokens();
$alias = $tokens[$endPtr]['content'];
Expand Down Expand Up @@ -293,7 +294,7 @@ protected function findClassImports(File $phpcsFile, ?int $limitPtr = null): arr
}

/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param File $phpcsFile
* @param int $cStackPtr
* @return array<int, string>
*/
Expand Down
8 changes: 8 additions & 0 deletions AntipinCS/Sniffs/Functions/ReturnTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function process(File $phpcsFile, $stackPtr): void
);
return;
}
static $skipMethods = ['__construct' => true, '__destruct' => true];
if (
$token['code'] !== 311
&& ($methodName = $phpcsFile->getDeclarationName($stackPtr)) !== null
&& isset($skipMethods[$methodName])
) {
return;
}
$methodProperties = $phpcsFile->getMethodProperties($stackPtr);
if ($methodProperties['return_type'] === '') {
$phpcsFile->addError(
Expand Down
39 changes: 39 additions & 0 deletions AntipinCS/Tests/Functions/ReturnTypeDeclarationUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is auto-generated. DO NOT EDIT.
*/

declare(strict_types=1);

namespace MaxAntipin\YandexCloud\SDK\Service;

use MaxAntipin\YandexCloud\SDK\Service\Resource\ResourceManager\CloudResource;
use MaxAntipin\YandexCloud\SDK\Service\Resource\ResourceManager\FolderResource;
use Thesis\Grpc\Client as GRPCClient;
use Yandex\Cloud\Resourcemanager\V1\CloudServiceClient;
use Yandex\Cloud\Resourcemanager\V1\FolderServiceClient;

final class ResourceManagerService implements APIServiceInterface
{
public private(set) CloudResource $cloud {
get {
return $this->cloud ??= new CloudResource(new CloudServiceClient($this->client));
}
}

public private(set) FolderResource $folder {
get {
return $this->folder ??= new FolderResource(new FolderServiceClient($this->client));
}
}

public function __construct(
private readonly GRPCClient $client,
) {
}

public function __destruct()
{
}
}
32 changes: 24 additions & 8 deletions AntipinCS/Tests/Functions/ReturnTypeDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,34 @@
*/
final class ReturnTypeDeclarationUnitTest extends AbstractSniffUnitTest
{
/**
* Get a list of all test files to check.
*
* @param string $testFileBase The base path that the unit tests files will have.
*
* @return string[]
*/
protected function getTestFiles($testFileBase): array
{
return array_map(static fn (int $i): string => $testFileBase . $i . '.inc', range(1, 2));
}

/**
* @return array<int, int>
*/
protected function getErrorList(): array
protected function getErrorList(string $testFile = ''): array
{
return [
65 => 1,
68 => 1,
73 => 1,
75 => 1,
77 => 1,
];
return match ($testFile) {
'ReturnTypeDeclarationUnitTest.1.inc' => [
65 => 1,
68 => 1,
73 => 1,
75 => 1,
77 => 1,
],
'ReturnTypeDeclarationUnitTest.2.inc' => [],
default => throw new \RuntimeException('Unhandled test file: ' . $testFile)
};
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ up:
docker compose -f .docker/compose.yaml up -d --build
docker compose -f .docker/compose.yaml run --rm --remove-orphans php-dev composer install

run-coverage:
docker compose -f .docker/compose.yaml run --rm php-dev-coverage make test-coverage

down:
docker compose -f .docker/compose.yaml down

Expand All @@ -16,7 +19,13 @@ lint:
php ./vendor/bin/phpstan analyze
php ./vendor/bin/phpcs-check-feature-completeness

fix-lint:
php ./vendor/bin/phpcbf

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

test-coverage:
cd ../cs-test/ && XDEBUG_MODE=coverage php ./vendor/bin/phpunit --filter AntipinCS

check-build:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"license": "Unlicense",
"require": {
"php": ">=8.3",
"php": ">=8.4",
"squizlabs/php_codesniffer": "^3.13",
"dealerdirect/phpcodesniffer-composer-installer": "^1.2"
},
Expand All @@ -46,6 +46,7 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"lock": false
}
}
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<element key="PHP_CodeSniffer\Sniffs\AbstractVariableSniff" value="processMemberVar,processVariable,processVariableInString"/>
<element key="PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest" value="getTestFiles"/>
</property>
</properties>
</properties>
</rule>
</ruleset>
19 changes: 9 additions & 10 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
parameters:
phpVersion: 80200
level: 9
paths:
- AntipinCS
excludePaths:
- var (?)
- vendor
bootstrapFiles:
- vendor/autoload.php
parameters:
level: 9
paths:
- AntipinCS
excludePaths:
- var (?)
- vendor
bootstrapFiles:
- vendor/autoload.php
- vendor/squizlabs/php_codesniffer/src/Util/Tokens.php
Loading