PK ƶbT
.7Ou Ou lib/Doctrine/ruleset.xmlnu ٘
The Doctrine coding standard.
error
Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead
5
PK ƶbT]n; ; Makefilenu ٘ .PHONY: test test-report test-fix update-compatibility-patch
PHP_VERSION:=$(shell php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")
PATCH_FILE="tests/php$(PHP_VERSION)-compatibility.patch"
test: test-report test-fix
test-report: vendor
@if [ -f "$(PATCH_FILE)" ]; then git apply $(PATCH_FILE) ; fi
@vendor/bin/phpcs `find tests/input/* | sort` --report=summary --report-file=phpcs.log; diff -u tests/expected_report.txt phpcs.log; if [ $$? -ne 0 ] && [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; exit 1; fi
@if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi
test-fix: vendor
@if [ -f "$(PATCH_FILE)" ]; then git apply $(PATCH_FILE) ; fi
@cp -R tests/input/ tests/input2/
@vendor/bin/phpcbf tests/input2; diff -u tests/input2 tests/fixed; if [ $$? -ne 0 ]; then rm -rf tests/input2/; if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi; exit 1; fi
@rm -rf tests/input2/;
@if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi
update-compatibility-patch-74:
@git apply tests/php74-compatibility.patch
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@git diff -- tests/expected_report.txt tests/fixed > .tmp-patch && mv .tmp-patch tests/php74-compatibility.patch && git apply -R tests/php74-compatibility.patch
@git commit -m 'Update compatibility patch' tests/php74-compatibility.patch
update-compatibility-patch-80:
@git apply tests/php80-compatibility.patch
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@git diff -- tests/expected_report.txt tests/fixed > .tmp-patch-80 && mv .tmp-patch-80 tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch
@git commit -m 'Update compatibility patch' tests/php80-compatibility.patch
vendor: composer.json
composer update
touch -c vendor
PK ƶbT README.mdnu ٘ # Doctrine Coding Standard
[![Build Status](https://github.com/doctrine/coding-standard/workflows/Continuous%20Integration/badge.svg)](https://github.com/doctrine/coding-standard/actions?query=workflow%3A%22Continuous+Integration%22+)
[![Continuous Integration](https://github.com/doctrine/coding-standard/workflows/Continuous%20Integration/badge.svg?branch=8.2.x)](https://github.com/doctrine/coding-standard/actions)
[![Total Downloads](https://img.shields.io/packagist/dt/doctrine/coding-standard.svg?style=flat-square)](https://packagist.org/packages/doctrine/coding-standard)
[![Latest Stable Version](https://img.shields.io/packagist/v/doctrine/coding-standard.svg?style=flat-square)](https://packagist.org/packages/doctrine/coding-standard)
The Doctrine Coding Standard is a set of [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) rules applied to all Doctrine projects. Doctrine Coding Standard is heavily based on [Slevomat Coding Standard](https://github.com/slevomat/coding-standard).
## More resources:
* [Website](https://www.doctrine-project.org/)
* [Documentation](https://www.doctrine-project.org/projects/coding-standard.html)
* [Downloads](https://github.com/doctrine/coding-standard/coding-standard)
PK ƶbTU.7 7
.gitignorenu ٘ vendor/
phpcs.xml
composer.lock
tests/input2
phpcs.log
PK ƶbT2& & phpcs.xml.distnu ٘
Check the code of the sniffs in doctrine/coding-standards.
lib
PK ƶbTU> > .github/CODEOWNERSnu ٘ /lib/Doctrine/ruleset.xml @doctrine/coding-standard-approvers
PK ƶbTɂ6 6 , .github/workflows/continuous-integration.ymlnu ٘ # https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Continuous Integration"
on:
pull_request:
push:
branches:
- "*.*.x"
schedule:
- cron: "0 17 * * *"
jobs:
coding-standards:
name: "Coding Standards"
runs-on: "ubuntu-18.04"
strategy:
matrix:
php-version:
- "7.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"
- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Run squizlabs/php_codesniffer"
run: "vendor/bin/phpcs"
validate-against-schema:
name: "Validate against schema"
runs-on: "ubuntu-18.04"
strategy:
matrix:
php-version:
- "7.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Build Docker image"
uses: "./.docker/validate-against-schema"
- name: "Lint XML configuration files"
uses: "./.docker/validate-against-schema"
with:
args: "xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd lib/Doctrine/ruleset.xml"
test-report:
name: "Test report"
runs-on: "ubuntu-18.04"
strategy:
matrix:
php-version:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"
- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Test reports"
run: "make test-report"
test-fixes:
name: "Test fixes"
runs-on: "ubuntu-18.04"
strategy:
matrix:
php-version:
- "7.1"
- "7.4"
- "8.0"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest"
- name: "Test fixes"
run: "make test-fix"
PK ƶbT1A 1 .github/workflows/release-on-milestone-closed.ymlnu ٘ name: "Automatic Releases"
on:
milestone:
types:
- "closed"
jobs:
release:
name: "Git tag, release & create merge-up PR"
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Release"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create Merge-Up Pull Request"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create new milestones"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
PK ƶbTiے .github/dependabot.ymlnu ٘ version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "11:00"
open-pull-requests-limit: 10
reviewers:
- doctrine/coding-standard-approvers
labels:
- Dependencies
versioning-strategy: increase-if-necessary
ignore:
- dependency-name: slevomat/coding-standard
versions:
- 7.0.0
- 7.0.1
- 7.0.2
- 7.0.4
- 7.0.5
PK ƶbT s .gitattributesnu ٘ /.docker export-ignore
/.doctrine-project.json export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/docs/ export-ignore
/phpcs.xml.dist export-ignore
/tests/ export-ignore
/bin/ export-ignore
PK ƶbTve&9 9 * .docker/validate-against-schema/Dockerfilenu ٘ FROM alpine:3.11.3
RUN apk add --no-cache libxml2-utils
PK ƶbT"X X .doctrine-project.jsonnu ٘ {
"active": true,
"name": "Coding Standard",
"slug": "coding-standard",
"docsSlug": "doctrine-coding-standard",
"versions": [
{
"name": "9.0",
"branchName": "9.0.x",
"slug": "9.0",
"upcoming": true
},
{
"name": "8.2",
"branchName": "8.2.x",
"slug": "8.2",
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "8.1",
"branchName": "8.1.x",
"slug": "8.1",
"maintained": false
},
{
"name": "8.0",
"branchName": "8.0.x",
"slug": "8.0",
"maintained": false
},
{
"name": "7.0",
"branchName": "7.0.x",
"slug": "7.0",
"maintained": false
},
{
"name": "6.0",
"branchName": "6.x",
"slug": "6.0",
"maintained": false
},
{
"name": "5.0",
"branchName": "5.x",
"slug": "5.0",
"maintained": false
},
{
"name": "4.0",
"branchName": "4.x",
"slug": "4.0",
"maintained": false
}
]
}
PK ƶbTս tests/php74-compatibility.patchnu ٘ diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index fd5432c..233e24d 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -15,7 +15,7 @@ tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
-tests/input/example-class.php 38 0
+tests/input/example-class.php 41 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
@@ -23,9 +23,9 @@ tests/input/LowCaseTypes.php 2 0
tests/input/namespaces-spacing.php 7 0
tests/input/NamingCamelCase.php 6 0
tests/input/negation-operator.php 2 0
-tests/input/new_with_parentheses.php 18 0
+tests/input/new_with_parentheses.php 19 0
tests/input/not_spacing.php 8 0
-tests/input/null_coalesce_equal_operator.php 1 0
+tests/input/null_coalesce_equal_operator.php 5 0
tests/input/null_coalesce_operator.php 3 0
tests/input/optimized-functions.php 1 0
tests/input/PropertyTypeHintSpacing.php 6 0
@@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
tests/input/traits-uses.php 11 0
-tests/input/type-hints.php 4 0
+tests/input/type-hints.php 5 0
tests/input/UnusedVariables.php 1 0
tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
+A TOTAL OF 386 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 322 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
index dbec9cb..dca22ed 100644
--- a/tests/fixed/example-class.php
+++ b/tests/fixed/example-class.php
@@ -25,14 +25,12 @@ class Example implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
- /** @var int|null */
- private $foo;
+ private ?int $foo = null;
/** @var string[] */
- private $bar;
+ private array $bar;
- /** @var bool */
- private $baz;
+ private bool $baz;
/** @var ControlStructureSniff|int|string|null */
private $baxBax;
diff --git a/tests/fixed/new_with_parentheses.php b/tests/fixed/new_with_parentheses.php
index 6e81bbe..47a06ec 100644
--- a/tests/fixed/new_with_parentheses.php
+++ b/tests/fixed/new_with_parentheses.php
@@ -24,5 +24,5 @@ $y = [new stdClass()];
$z = new stdClass() ? new stdClass() : new stdClass();
-$q = $q ?: new stdClass();
-$e = $e ?? new stdClass();
+$q = $q ?: new stdClass();
+$e ??= new stdClass();
diff --git a/tests/fixed/null_coalesce_equal_operator.php b/tests/fixed/null_coalesce_equal_operator.php
index b997469..6703d30 100644
--- a/tests/fixed/null_coalesce_equal_operator.php
+++ b/tests/fixed/null_coalesce_equal_operator.php
@@ -2,12 +2,12 @@
declare(strict_types=1);
-$bar = $bar ?? 'bar';
+$bar ??= 'bar';
-$bar['baz'] = $bar['baz'] ?? 'baz';
+$bar['baz'] ??= 'baz';
-$bar = $bar ?? 'bar';
+$bar ??= 'bar';
-$object->property = $object->property ?? 'Default Value';
+$object->property ??= 'Default Value';
-Test::$foo = Test::$foo ?? 123;
+Test::$foo ??= 123;
diff --git a/tests/fixed/null_coalesce_operator.php b/tests/fixed/null_coalesce_operator.php
index 8846dd1..51c361c 100644
--- a/tests/fixed/null_coalesce_operator.php
+++ b/tests/fixed/null_coalesce_operator.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
$foo = $_GET['foo'] ?? 'foo';
-$bar = $bar ?? 'bar';
+$bar ??= 'bar';
$bar = $bar['baz'] ?? 'baz';
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
index 0e952fc..9824fb0 100644
--- a/tests/fixed/type-hints.php
+++ b/tests/fixed/type-hints.php
@@ -10,7 +10,7 @@ use Traversable;
class TraversableTypeHints
{
/** @var Traversable */
- private $parameter;
+ private Traversable $parameter;
/**
* @param Iterator $iterator
PK ƶbTMs tests/fixed/use-ordering.phpnu ٘ format(DateTimeInterface::ATOM)) . PHP_EOL;
PK ƶbTuq q $ tests/fixed/assignment-operators.phpnu ٘ property = $object->property ?? 'Default Value';
Test::$foo = Test::$foo ?? 123;
PK ƶbTP tests/fixed/traits-uses.phpnu ٘ $a + $b;
$uselessParentheses = static fn ($x) => $x + $y;
$withReturnType = static fn (): int => 1 + 2;
$withTypesInArguments = static fn (int $a, int $b): int => $a + $b;
$spacing = static fn (int $x) => $x * 2;
$nested = static fn ($x) => static fn ($y) => $x * $y + $z;
$returningObject = static fn () => new stdClass();
$multiLineArrowFunctions = Collection::from([1, 2])
->map(
static fn (int $v): int => $v * 2
)
->reduce(
static fn (int $tmp, int $v): int => $tmp + $v
);
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
$arrayWithArrowFunctions = [
'true' => static fn () => true,
'false' => static fn () => false,
];
$singleLineArrayReturn = Collection::map(
static fn () => [1, 2]
);
$wrongMultiLineArrayReturn = Collection::map(
static fn () => [
1,
2,
]
);
PK ƶbTW ! tests/fixed/useless-semicolon.phpnu ٘ 'value',
'key2' => 'value',
];
PK ƶbT
# # % tests/fixed/concatenation_spacing.phpnu ٘ 0) {
echo 1;
} elseif (! $test === 0) {
echo 0;
} else {
echo -1;
}
while (! true) {
echo 1;
}
do {
echo 1;
} while (! true);
PK ƶbTC.ȅ tests/fixed/binary_operators.phpnu ٘ = 10;
}
PK ƶbT4
H ! tests/fixed/ControlStructures.phpnu ٘ */
public function varAndIfNoSpaceBetween(): iterable
{
$var = 1;
if (self::VERSION !== 0) {
return;
}
yield 0;
}
/** @return iterable */
public function ifAndYieldSpaceBetween(): iterable
{
if (self::VERSION === 0) {
yield 0;
}
yield 1;
}
/** @return iterable */
public function ifAndYieldFromSpaceBetween(): iterable
{
if (self::VERSION === 0) {
yield 0;
}
yield from [];
}
public function ifAndThrowSpaceBetween(): void
{
if (self::VERSION === 0) {
return;
}
throw new InvalidArgumentException();
}
public function ifAndReturnSpaceBetween(): int
{
if (self::VERSION === 0) {
return 0;
}
return 1;
}
public function noSpaceAroundCase(): void
{
switch (self::VERSION) {
case 1:
case 2:
// do something
break;
case 3:
// do something else
break;
default:
}
}
public function spaceBelowBlocks(): void
{
if (true) {
echo 1;
}
do {
echo 2;
} while (true);
while (true) {
echo 3;
}
for ($i = 0; $i < 1; $i++) {
echo $i;
}
foreach ([] as $item) {
echo $item;
}
switch (true) {
default:
}
try {
echo 4;
} catch (Throwable $throwable) {
}
echo 5;
}
public function spaceAroundMultilineIfs(): void
{
if (
true
&& false
) {
echo 1;
} elseif (
false
|| true
) {
echo 2;
}
}
public function spacingAroundCasesWithBreakAndReturn(): void
{
switch (true) {
case 1:
throw new InvalidArgumentException();
case 2:
return;
case 3:
break;
case 4:
echo 1;
}
}
}
PK ƶbT6Q &