Skip to content

Commit 013cee6

Browse files
committed
CakePHP 6 upgrade
1 parent b2b3538 commit 013cee6

32 files changed

Lines changed: 243 additions & 147 deletions

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- 'master'
7-
- '3.next-cake5'
7+
- '4.next-cake5'
88
pull_request:
99
branches:
1010
- '*'
@@ -19,18 +19,11 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
php-version: ['8.1', '8.4']
23-
dependencies: ['highest']
24-
include:
25-
- php-version: '8.1'
26-
dependencies: 'lowest'
27-
- php-version: '8.2'
28-
dependencies: 'highest'
29-
- php-version: '8.3'
30-
dependencies: 'highest'
22+
php-version: ['8.5']
23+
dependencies: ['highest', 'lowest']
3124

3225
steps:
33-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v4
3427

3528
- name: Setup PHP
3629
uses: shivammathur/setup-php@v2
@@ -47,19 +40,19 @@ jobs:
4740
composer-options: ${{ matrix.composer-options }}
4841

4942
- name: Run PHPUnit
50-
run: vendor/bin/phpunit
43+
run: composer test
5144

5245
cs-stan:
5346
name: Coding Standard & Static Analysis
5447
runs-on: ubuntu-22.04
5548

5649
steps:
57-
- uses: actions/checkout@v3
50+
- uses: actions/checkout@v4
5851

5952
- name: Setup PHP
6053
uses: shivammathur/setup-php@v2
6154
with:
62-
php-version: '8.2'
55+
php-version: '8.5'
6356
extensions: mbstring, intl
6457
coverage: none
6558
tools: phive, cs2pr

‎.travis.yml‎

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

‎README.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CakePHP extension for PHPStan
1+
# CakePHP 6 extension for PHPStan
22

33
![Build Status](https://github.com/CakeDC/cakephp-phpstan/actions/workflows/ci.yml/badge.svg)
44
[![Downloads](https://poser.pugx.org/CakeDC/cakephp-phpstan/d/total.svg)](https://packagist.org/packages/CakeDC/cakephp-phpstan)
@@ -13,6 +13,10 @@ and multiple rules.
1313

1414
# Installation
1515

16+
Requires PHP 8.5+, CakePHP 6, and PHPStan 2.1.26+. CakePHP 6 is currently in development; configure `"minimum-stability": "dev"` and `"prefer-stable": true` in the root Composer project to allow its dependencies.
17+
18+
When upgrading, move custom console helpers to `Console/Helper`. Commands implement `execute(): ?int` and access arguments and console IO through properties.
19+
1620
To use this extension, require it through [Composer](https://getcomposer.org/):
1721

1822
```
@@ -39,11 +43,11 @@ Features included:
3943
1. Provide correct return type for `Cake\ORM\Locator\LocatorInterface::get()`
4044
1. Provide correct return type for `Cake\Controller\Controller::loadComponent()`
4145
1. Provide correct return type for `Cake\Controller\Controller::fetchTable()`
42-
1. Provide correct return type for `Cake\Controller\Component::fetchTable()`
46+
1. Provide correct return type for `fetchTable()` on components using `Cake\ORM\Locator\LocatorAwareTrait`
4347
1. Provide correct return type for `Cake\Command\Command::fetchTable()`
4448
1. Provide correct return type for `Cake\Mailer\Mailer::fetchTable()`
4549
1. Provide correct return type for `Cake\View\Cell::fetchTable()`
46-
1. Provide correct return type for `Cake\Console\ConsoleIo::helper()`
50+
1. Provide correct return type for `Cake\Console\ConsoleIo::helper()` and `Cake\Console\ConsoleIoInterface::helper()`
4751

4852
# Table class return type extensions
4953
### SelectQueryFindListReturnTypeExtension

‎composer.json‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cakedc/cakephp-phpstan",
3-
"description": "CakePHP plugin extension for PHPStan.",
3+
"description": "CakePHP 6 plugin extension for PHPStan.",
44
"type": "phpstan-extension",
55
"license": "MIT",
66
"authors": [
@@ -11,14 +11,14 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=8.1.0",
14+
"php": ">=8.5",
1515
"phpstan/phpstan": "^2.1.26",
16-
"cakephp/cakephp": "^5.0"
16+
"cakephp/cakephp": "^6.0"
1717
},
1818
"require-dev": {
1919
"phpstan/phpstan-phpunit": "^2.0",
20-
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.1",
21-
"cakephp/cakephp-codesniffer": "^5.0",
20+
"phpunit/phpunit": "^13.0",
21+
"cakephp/cakephp-codesniffer": "6.x-dev",
2222
"phpstan/phpstan-deprecation-rules": "^2.0",
2323
"phpstan/phpstan-strict-rules": "^2.0"
2424
},
@@ -44,7 +44,7 @@
4444
"scripts": {
4545
"cs-check": "phpcs -p",
4646
"cs-fix": "phpcbf -p",
47-
"test": "phpunit --stderr",
47+
"test": "@php -d memory_limit=1G vendor/bin/phpunit --stderr",
4848
"stan-integration": [
4949
"phpstan analyse --debug -c phpstan-test-app.neon",
5050
"phpstan analyse --debug -c phpstan-test-plugin.neon"
@@ -61,5 +61,7 @@
6161
"allow-plugins": {
6262
"dealerdirect/phpcodesniffer-composer-installer": true
6363
}
64-
}
64+
},
65+
"minimum-stability": "dev",
66+
"prefer-stable": true
6567
}

‎phpstan-test-app.neon‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ parameters:
1111
ignoreErrors:
1212
-
1313
identifier: missingType.generics
14-
-
15-
identifier: method.deprecated

‎phpunit.xml‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
bootstrap="./vendor/autoload.php"
4-
backupGlobals="false"
5-
colors="true"
6-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
7-
cacheDirectory=".phpunit.cache">
8-
9-
<testsuite name="CakeDCPhpStan">
10-
<directory>./tests</directory>
11-
</testsuite>
12-
13-
<source>
14-
<include>
15-
<directory suffix=".php">./src</directory>
16-
</include>
17-
</source>
1+
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheDirectory="tmp/phpunit">
2+
<testsuites>
3+
<testsuite name="CakeDCPhpStan">
4+
<directory>tests/TestCase</directory>
5+
</testsuite>
6+
</testsuites>
7+
<source>
8+
<include><directory suffix=".php">src</directory></include>
9+
</source>
1810
</phpunit>

‎src/Rule/Controller/ControllerMethodMustBeUsedRule.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Cake\Controller\Controller;
1717
use PhpParser\Node;
1818
use PhpParser\Node\Expr\MethodCall;
19+
use PhpParser\Node\Identifier;
1920
use PhpParser\Node\Stmt\Expression;
2021
use PHPStan\Analyser\Scope;
2122
use PHPStan\Rules\Rule;
@@ -62,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array
6263
$methodCall = $node->expr;
6364

6465
// Check if the method name is one we care about
65-
if (!$methodCall->name instanceof Node\Identifier) {
66+
if (!$methodCall->name instanceof Identifier) {
6667
return [];
6768
}
6869

‎src/Rule/Debug/DisallowDebugFuncCallRule.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Expr\ConstFetch;
88
use PhpParser\Node\Expr\FuncCall;
9+
use PhpParser\Node\Name;
910
use PHPStan\Analyser\Scope;
1011
use PHPStan\Rules\Rule;
1112
use PHPStan\Rules\RuleErrorBuilder;
@@ -44,7 +45,7 @@ public function getNodeType(): string
4445
public function processNode(Node $node, Scope $scope): array
4546
{
4647
assert($node instanceof FuncCall);
47-
if (!$node->name instanceof Node\Name) {
48+
if (!$node->name instanceof Name) {
4849
return [];
4950
}
5051
$usedName = $node->name->name;

‎src/Rule/LoadObjectExistsCakeClassRule.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
use CakeDC\PHPStan\Rule\Traits\ParseClassNameFromArgTrait;
1717
use PhpParser\Node;
1818
use PhpParser\Node\Arg;
19+
use PhpParser\Node\ArrayItem;
20+
use PhpParser\Node\Expr\Array_;
1921
use PhpParser\Node\Expr\ConstFetch;
2022
use PhpParser\Node\Expr\MethodCall;
23+
use PhpParser\Node\Identifier;
2124
use PhpParser\Node\Scalar\String_;
2225
use PHPStan\Analyser\Scope;
2326
use PHPStan\Rules\Rule;
@@ -49,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
4952
{
5053
assert($node instanceof MethodCall);
5154
$args = $node->getArgs();
52-
if (!$node->name instanceof Node\Identifier) {
55+
if (!$node->name instanceof Identifier) {
5356
return [];
5457
}
5558
$reference = $scope->getType($node->var)->getReferencedClasses()[0] ?? null;
@@ -100,13 +103,13 @@ protected function getInputClassName(String_ $nameArg, ?Arg $options): ?string
100103
$className = $nameArg->value;
101104
if (
102105
$options === null
103-
|| !$options->value instanceof Node\Expr\Array_
106+
|| !$options->value instanceof Array_
104107
) {
105108
return $className;
106109
}
107110
foreach ($options->value->items as $item) {
108111
if (
109-
!$item instanceof Node\Expr\ArrayItem
112+
!$item instanceof ArrayItem
110113
|| !$item->key instanceof String_
111114
|| $item->key->value !== 'className'
112115
) {

‎src/Rule/Mailer/GetMailerExistsClassRule.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CakeDC\PHPStan\Utility\CakeNameRegistry;
1717
use PhpParser\Node;
1818
use PhpParser\Node\Expr\MethodCall;
19+
use PhpParser\Node\Identifier;
1920
use PhpParser\Node\Scalar\String_;
2021
use PHPStan\Analyser\Scope;
2122
use PHPStan\Rules\Rule;
@@ -56,7 +57,7 @@ public function processNode(Node $node, Scope $scope): array
5657
{
5758
assert($node instanceof MethodCall);
5859
if (
59-
!$node->name instanceof Node\Identifier
60+
!$node->name instanceof Identifier
6061
|| $node->name->name !== 'getMailer'
6162
) {
6263
return [];

0 commit comments

Comments
 (0)