Skip to content

Commit 9d91f04

Browse files
authored
CakePHP 5.1 deprecations (#155)
* Handle cakephp 5.1.0: Calling `Cake\ORM\ResultSet` methods, such as `first()`, on PaginatedResultSet is deprecated. You must call `items()` first (for example, `items()->first()`) * CakePHP 5.1 * resolve phpstan errors
1 parent 25e980d commit 9d91f04

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

.github/workflows/pull-request.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
php-versions: ['8.3']
12+
php-versions: ['8.1', '8.4']
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v2
@@ -115,3 +115,33 @@ jobs:
115115
rm -rf composer.lock
116116
composer install
117117
vendor/bin/phpunit plugins/${{matrix.plugin}}
118+
119+
#
120+
# CakePHP version compatability
121+
#
122+
cakephp_version_compatibility:
123+
name: CakePHP ${{ matrix.version }} Test
124+
runs-on: ubuntu-latest
125+
strategy:
126+
matrix:
127+
version: ['~5.0', '~5.1']
128+
steps:
129+
- name: Checkout
130+
uses: actions/checkout@v2
131+
132+
- name: Setup PHP
133+
uses: shivammathur/setup-php@v2
134+
with:
135+
php-version: '8.1'
136+
extensions: mbstring, intl
137+
138+
- name: PHP Version
139+
run: php -v
140+
141+
- name: CakePHP ${{matrix.version}} Compatability
142+
run: |
143+
composer self-update
144+
rm -rf composer.lock
145+
composer require cakephp/cakephp:${{matrix.version}} --no-update
146+
composer install --prefer-dist --no-progress
147+
composer test

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true
109109
* If you set 'className' => 'Null' core cache will be disabled.
110110
*/
111-
'_cake_core_' => [
111+
'_cake_translations_' => [
112112
'className' => FileEngine::class,
113113
'prefix' => 'myapp_cake_core_',
114114
'path' => CACHE . 'persistent' . DS,

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ parameters:
33
checkGenericClassInNonGenericObjectType: false
44
checkMissingIterableValueType: false
55
treatPhpDocTypesAsCertain: false
6+
reportUnmatchedIgnoredErrors: false
67
excludePaths:
78
- plugins/exception-render/src/OpenApiExceptionSchema.php

plugins/hal-view/src/JsonSerializer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ private function recursion(mixed &$mixed): mixed
117117
private function collection(mixed $collection): array
118118
{
119119
try {
120-
$entity = $collection->first();
120+
if ($collection instanceof PaginatedResultSet) {
121+
$entity = $collection->toArray()[0];
122+
} else {
123+
$entity = $collection->first();
124+
}
121125
$tableName = Inflector::tableize((new ReflectionClass($entity))->getShortName());
122126
} catch (ReflectionException $e) {
123127
$tableName = 'data';

plugins/json-ld-view/src/JsonSerializer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ private function collection(mixed $jsonLd): array
138138
$return = [];
139139

140140
try {
141-
$entity = $jsonLd->first();
141+
if ($jsonLd instanceof PaginatedResultSet) {
142+
$entity = $jsonLd->toArray()[0];
143+
} else {
144+
$entity = $jsonLd->first();
145+
}
146+
142147
if ($entity instanceof JsonLdDataInterface) {
143148
$return['@context'] = $entity->getJsonLdContext();
144149
}

0 commit comments

Comments
 (0)