Skip to content

Commit 2834a04

Browse files
authored
Merge pull request #413 from cakephp/5.next
Prepare for v5.2 release
2 parents 8565240 + 954f17d commit 2834a04

21 files changed

+139
-169
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ end_of_line = crlf
1515

1616
[*.yml]
1717
indent_size = 2
18+
19+
[*.neon]
20+
indent_style = tab

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
# Ignore files for distribution archives, generated using `git archive`
1313
.editorconfig export-ignore
14-
.git export-ignore
14+
.github export-ignore
1515
.gitattributes export-ignore
1616
.gitignore export-ignore
1717
phpcs.xml export-ignore
1818
phpunit.xml.dist export-ignore
1919
/CakePHP/Tests export-ignore
20+
phpstan.neon export-ignore
21+
.phive export-ignore

.github/workflows/ci.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ on:
1111

1212
jobs:
1313
testsuite:
14-
runs-on: ubuntu-22.04
14+
runs-on: ubuntu-24.04
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
php-version: ['8.1', '8.2', '8.3']
18+
php-version: ['8.1', '8.2', '8.3', '8.4']
1919
dependencies: ['highest']
2020
include:
2121
- php-version: '8.1'
@@ -40,20 +40,26 @@ jobs:
4040

4141
cs-stan:
4242
name: Coding Standard & Static Analysis
43-
runs-on: ubuntu-22.04
43+
runs-on: ubuntu-24.04
4444

4545
steps:
46-
- uses: actions/checkout@v3
46+
- uses: actions/checkout@v4
4747

4848
- name: Setup PHP
4949
uses: shivammathur/setup-php@v2
5050
with:
5151
php-version: '8.1'
52-
tools: cs2pr
52+
tools: phive, cs2pr
5353
coverage: none
5454

5555
- name: Composer install
5656
uses: ramsey/composer-install@v3
5757

58+
- name: Install PHP tools with phive.
59+
run: "phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5'"
60+
5861
- name: Run PHP CodeSniffer
5962
run: vendor/bin/phpcs --report=checkstyle | cs2pr
63+
64+
- name: Run PHPStan
65+
run: tools/phpstan analyse --error-format=github

.phive/phars.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpstan" version="2.0.3" installed="2.0.3" location="./tools/phpstan" copy="false"/>
4+
</phive>

CakePHP/Sniffs/Classes/ReturnTypeHintSniff.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
6767
$phpcsFile->addError(
6868
'Chaining methods (@return $this) should not have any return-type-hint.',
6969
$startIndex,
70-
'InvalidSelf'
70+
'InvalidSelf',
7171
);
7272

7373
return;
@@ -76,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
7676
$fix = $phpcsFile->addFixableError(
7777
'Chaining methods (@return $this) should not have any return-type-hint (Remove "self").',
7878
$startIndex,
79-
'InvalidSelf'
79+
'InvalidSelf',
8080
);
8181
if (!$fix) {
8282
return;
@@ -175,7 +175,7 @@ protected function assertNotThisOrStatic(File $phpCsFile, int $stackPointer): vo
175175
$phpCsFile->addError(
176176
'Class name repeated, expected `self` or `$this`.',
177177
$classNameIndex,
178-
'InvalidClass'
178+
'InvalidClass',
179179
);
180180
}
181181
}
@@ -228,9 +228,14 @@ protected function getClassNameWithNamespace(File $phpCsFile): ?string
228228
return null;
229229
}
230230

231+
$classPointer = $phpCsFile->findPrevious(TokenHelper::$typeKeywordTokenCodes, $lastToken);
232+
if (!$classPointer) {
233+
return null;
234+
}
235+
231236
return ClassHelper::getFullyQualifiedName(
232237
$phpCsFile,
233-
$phpCsFile->findPrevious(TokenHelper::$typeKeywordTokenCodes, $lastToken)
238+
$classPointer,
234239
);
235240
}
236241
}

CakePHP/Sniffs/Commenting/DocBlockAlignmentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function process(File $phpcsFile, $stackPtr)
6161
$commentBorder = $phpcsFile->findNext(
6262
[T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG],
6363
$searchToken,
64-
$commentClose + 1
64+
$commentClose + 1,
6565
);
6666
if ($commentBorder !== false) {
6767
$tokensToIndent[$commentBorder] = $codeIndentation + 1;

CakePHP/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function process(File $phpcsFile, $stackPtr)
5959
$docCommentEnd = $phpcsFile->findPrevious(
6060
[T_DOC_COMMENT_CLOSE_TAG, T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET],
6161
$stackPtr - 1,
62-
null
62+
null,
6363
);
6464
if ($docCommentEnd === false || $tokens[$docCommentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
6565
$phpcsFile->addError(
6666
'Missing doc comment for function %s()',
6767
$stackPtr,
6868
'Missing',
69-
[$phpcsFile->getDeclarationName($stackPtr)]
69+
[$phpcsFile->getDeclarationName($stackPtr)],
7070
);
7171

7272
return;
@@ -77,14 +77,14 @@ public function process(File $phpcsFile, $stackPtr)
7777
$attribute = $phpcsFile->findNext(
7878
[T_ATTRIBUTE],
7979
$lastEndToken + 1,
80-
$stackPtr
80+
$stackPtr,
8181
);
8282
if ($attribute !== false) {
8383
if ($tokens[$lastEndToken]['line'] !== $tokens[$attribute]['line'] - 1) {
8484
$phpcsFile->addError(
8585
'There must be no blank lines after the function comment or attribute',
8686
$lastEndToken,
87-
'SpacingAfter'
87+
'SpacingAfter',
8888
);
8989

9090
return;
@@ -98,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr)
9898
$phpcsFile->addError(
9999
'There must be no blank lines after the function comment or attribute',
100100
$lastEndToken,
101-
'SpacingAfter'
101+
'SpacingAfter',
102102
);
103103
}
104104

@@ -152,7 +152,7 @@ protected function processThrows(File $phpcsFile, int $stackPtr, int $commentSta
152152
if ($tokens[$tag + 2]['code'] === T_DOC_COMMENT_STRING) {
153153
$matches = [];
154154
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[$tag + 2]['content'], $matches);
155-
$exception = $matches[1];
155+
$exception = $matches[1] ?? null;
156156
}
157157

158158
if ($exception === null) {

CakePHP/Sniffs/Commenting/TypeHintSniff.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use PHPStan\PhpDocParser\Parser\PhpDocParser;
3333
use PHPStan\PhpDocParser\Parser\TokenIterator;
3434
use PHPStan\PhpDocParser\Parser\TypeParser;
35+
use PHPStan\PhpDocParser\ParserConfig;
3536

3637
/**
3738
* Verifies order of types in type hints
@@ -128,7 +129,7 @@ public function process(File $phpcsFile, $stackPtr)
128129
'%s type hint is not formatted properly, expected "%s"',
129130
$tag,
130131
'IncorrectFormat',
131-
[$tokens[$tag]['content'], $sortedTypeHint]
132+
[$tokens[$tag]['content'], $sortedTypeHint],
132133
);
133134
if (!$fix) {
134135
continue;
@@ -140,7 +141,7 @@ public function process(File $phpcsFile, $stackPtr)
140141
'%s %s %s',
141142
$sortedTypeHint,
142143
$valueNode->variableName,
143-
$valueNode->description
144+
$valueNode->description,
144145
));
145146
if ($tagComment[-1] === ' ') {
146147
// tags above variables in code have a trailing space
@@ -152,13 +153,13 @@ public function process(File $phpcsFile, $stackPtr)
152153
$sortedTypeHint,
153154
$valueNode->isVariadic ? '...' : '',
154155
$valueNode->parameterName,
155-
$valueNode->description
156+
$valueNode->description,
156157
));
157158
} elseif ($valueNode instanceof ReturnTagValueNode) {
158159
$newComment = trim(sprintf(
159160
'%s %s',
160161
$sortedTypeHint,
161-
$valueNode->description
162+
$valueNode->description,
162163
));
163164
}
164165

@@ -278,10 +279,10 @@ protected function getSortedTypeHint(array $types): string
278279
protected function renderUnionTypes(array $typeNodes): string
279280
{
280281
// Remove parenthesis added by phpstan around union and intersection types
281-
return preg_replace(
282+
return (string)preg_replace(
282283
['/ ([\|&]) /', '/<\(/', '/\)>/', '/\), /', '/, \(/'],
283284
['${1}', '<', '>', ', ', ', '],
284-
implode('|', $typeNodes)
285+
implode('|', $typeNodes),
285286
);
286287
}
287288

@@ -294,13 +295,16 @@ protected static function getValueNode(string $tagName, string $tagComment): Php
294295
{
295296
static $phpDocParser;
296297
if (!$phpDocParser) {
297-
$constExprParser = new ConstExprParser();
298-
$phpDocParser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser);
298+
$config = new ParserConfig(usedAttributes: ['lines' => true, 'indexes' => true]);
299+
300+
$constExprParser = new ConstExprParser($config);
301+
$phpDocParser = new PhpDocParser($config, new TypeParser($config, $constExprParser), $constExprParser);
299302
}
300303

301304
static $phpDocLexer;
302305
if (!$phpDocLexer) {
303-
$phpDocLexer = new Lexer();
306+
$config = new ParserConfig(usedAttributes: ['lines' => true, 'indexes' => true]);
307+
$phpDocLexer = new Lexer($config);
304308
}
305309

306310
return $phpDocParser->parseTagValue(new TokenIterator($phpDocLexer->tokenize($tagComment)), $tagName);

CakePHP/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function process(File $phpcsFile, $stackPtr)
7272
$fix = $phpcsFile->addFixableError(
7373
'Missing blank line before return statement',
7474
$stackPtr,
75-
'BlankLineBeforeReturn'
75+
'BlankLineBeforeReturn',
7676
);
7777
if ($fix === true) {
7878
$phpcsFile->fixer->beginChangeset();

CakePHP/Sniffs/Functions/ClosureDeclarationSniff.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy