Skip to content

Commit

Permalink
Merge pull request #175 from FriendsOfCake/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
ADmad committed Aug 18, 2022
2 parents 7b4fb4c + 11a5311 commit 0f93824
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 127 deletions.
2 changes: 0 additions & 2 deletions .coveralls.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ trim_trailing_whitespace = true
[*.yml]
indent_style = space
indent_size = 2

[*.neon]
indent_style = tab
63 changes: 35 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CrudJSONApi CI
name: CI

on:
push:
Expand All @@ -10,27 +10,29 @@ on:

jobs:
testsuite:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: [ '7.2', '7.3', '7.4' ]
php-version: [ '7.4', '8.0', '8.1' ]
db-type: [ mysql ]
name: PHP ${{ matrix.php-version }} & ${{ matrix.db-type }}
prefer-lowest: ['']
include:
- php-version: '7.2'
db-type: 'mysql'
prefer-lowest: 'prefer-lowest'

steps:

- name: Setup MySQL latest
if: matrix.db-type == 'mysql' && matrix.php-version == '7.2'
if: matrix.db-type == 'mysql' && matrix.php-version != '7.2'
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql --default-authentication-plugin=mysql_native_password --disable-log-bin

- name: Setup MySQL 5.6
if: matrix.db-type == 'mysql' && matrix.php-version == '7.4'
if: matrix.db-type == 'mysql' && matrix.php-version == '7.2'
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:5.6 --character-set-server=utf8

- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -49,41 +51,48 @@ jobs:
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}

- name: composer install
run: composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
fi
- name: Configure PHPUnit matcher
if: matrix.php-version == '7.4' && matrix.db-type == 'mysql'
uses: mheap/phpunit-matcher-action@master
uses: mheap/phpunit-matcher-action@v1

- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.2' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'; fi
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.4' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.php-version }} == '7.2' ]]; then
vendor/bin/phpunit
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} != '7.2' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'; fi
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.2' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.4' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml --verbose
else
vendor/bin/phpunit --verbose
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v3

coding-standard:
name: Coding Standard
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: '7.4'
extensions: mbstring, intl, apcu
coverage: none

Expand All @@ -96,7 +105,7 @@ jobs:
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}
Expand All @@ -109,17 +118,15 @@ jobs:

static-analysis:
name: Static Analysis
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: '7.4'
extensions: mbstring, intl, apcu
coverage: none
tools: cs2pr
Expand Down
21 changes: 0 additions & 21 deletions .scrutinizer.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .stickler.yml

This file was deleted.

11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"neomerx/json-api": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "~8.5",
"phpunit/phpunit": "~8.5 || ^9.3",
"friendsofcake/cakephp-test-utilities": "^2.0.1",
"friendsofcake/search": "^6.0.0",
"cakephp/cakephp-codesniffer": "^4.0",
"dms/phpunit-arraysubset-asserts": "^0.1.0"
"dms/phpunit-arraysubset-asserts": "^0.4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -65,13 +65,18 @@
"scripts": {
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.49 psalm/phar:~3.17.0 && mv composer.backup composer.json",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.8.0 psalm/phar:~4.26.0 && mv composer.backup composer.json",
"phpstan": "phpstan analyse --memory-limit=3G src/",
"psalm": "psalm.phar --show-info=false",
"stan": [
"@phpstan",
"@psalm"
],
"test": "phpunit"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
16 changes: 16 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
ignoreErrors:
-
message: "#^Dead catch \\- Cake\\\\Core\\\\Exception\\\\CakeException is never thrown in the try block\\.$#"
count: 1
path: src/Error/JsonApiExceptionRenderer.php

-
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Crud\\.$#"
count: 1
path: src/Listener/PaginationListener.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\EntityInterface\\:\\:visibleProperties\\(\\)\\.$#"
count: 1
path: src/Schema/JsonApi/DynamicEntitySchema.php
29 changes: 11 additions & 18 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
parameters:
level: 8
checkMissingIterableValueType: false
excludes_analyse:
- */src/TestSuite/*

universalObjectCratesClasses:
- Crud\Event\Subject
ignoreErrors:
# ORM
- '#Call to an undefined method Cake\\Datasource\\EntityInterface::visibleProperties\(\)\.#'
includes:
- phpstan-baseline.neon

# Crud properties
- '#Access to an undefined property object::\$created#'
- '#Access to an undefined property object::\$entity#'
- '#Access to an undefined property object::\$id#'
- '#Access to an undefined property object::\$query#'
- '#Access to an undefined property object::\$success#'
- '#Access to an undefined property Cake\\Controller\\Controller::\$Crud.#'
parameters:
level: 6
paths:
- src
checkMissingIterableValueType: false
universalObjectCratesClasses:
- Crud\Event\Subject
bootstrapFiles:
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
6 changes: 5 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand All @@ -12,4 +12,8 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<universalObjectCrates>
<class name="Crud\Event\Subject" />
</universalObjectCrates>
</psalm>
1 change: 1 addition & 0 deletions src/Action/RelationshipsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ protected function _patch()

if (in_array($association->type(), [Association::MANY_TO_ONE, Association::ONE_TO_ONE], true)) {
//Set the relationship to the corresponding entity
/** @psalm-suppress TypeDoesNotContainNull */
if (array_key_exists('id', $data)) {
$entity->{$property} = $foreignTable->get($data['id']);
} elseif ($data === null) {
Expand Down
27 changes: 12 additions & 15 deletions src/Error/JsonApiExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ protected function _outputMessage(string $template): Response
* Method used for rendering 422 validation used for both CakePHP entity
* validation errors and JSON API (request data) documents.
*
* @param \Crud\Error\Exception\ValidationException $exception Exception
* @param \Crud\Error\Exception\ValidationException $error Exception
* @return \Cake\Http\Response
*/
public function validation(ValidationException $exception): Response
public function validation(ValidationException $error): Response
{
if (!$this->controller->getRequest()->accepts('application/vnd.api+json')) {
return parent::validation($exception);
return parent::validation($error);
}

$status = $exception->getCode();
$status = $error->getCode();

try {
$this->controller->setResponse($this->controller->getResponse()->withStatus($status));
Expand All @@ -103,7 +103,7 @@ public function validation(ValidationException $exception): Response
$this->controller->setResponse($this->controller->getResponse()->withStatus($status));
}

$errorCollection = $this->_getNeoMerxErrorCollection($exception->getValidationErrors());
$errorCollection = $this->_getNeoMerxErrorCollection($error->getValidationErrors());

$encoder = Encoder::instance();
$json = $encoder->encodeErrors($errorCollection);
Expand Down Expand Up @@ -180,16 +180,13 @@ protected function _addDebugNode(string $json): string

$debug = [];
$debug['class'] = get_class($viewVars['error']);

if (!isset($debug['trace'])) {
$debug['trace'] = Debugger::formatTrace(
$viewVars['error']->getTrace(),
[
'format' => 'array',
'args' => false,
]
);
}
$debug['trace'] = Debugger::formatTrace(
$viewVars['error']->getTrace(),
[
'format' => 'array',
'args' => false,
]
);

$result = json_decode($json, true);
$result['debug'] = $debug;
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/JsonApi/DocumentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ protected function _primaryDataMayHaveRelationships(): bool
}

// multiple hasMany relationships
$hasManys = $this->_getProperty($relationshipPathObject->dotted . '.data');
$count = count($this->_getProperty($relationshipPathObject->dotted . '.data'));

for ($i = 0; $i < count($hasManys); $i++) {
for ($i = 0; $i < $count; $i++) {
$pathObject = $this->_getPathObject($relationshipPathObject->dotted . '.data.' . $i);

$this->_relationshipDataMustHaveType($relationship, $pathObject);
Expand Down
5 changes: 3 additions & 2 deletions src/Listener/JsonApiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class JsonApiListener extends ApiListener
*
* We attach at priority 10 so normal bound events can run before us
*
* @return array
* @return array<string, mixed>
*/
public function implementedEvents(): array
{
Expand Down Expand Up @@ -1063,7 +1063,7 @@ protected function _getFindResult(Subject $subject)
protected function _getSingleEntity(Subject $subject): ?EntityInterface
{
if (!empty($subject->entities) && $subject->entities instanceof Query) {
// @phpstan-ignore-next-line
/** @psalm-suppress InvalidReturnStatement */
return (clone $subject->entities)->first();
}

Expand Down Expand Up @@ -1271,6 +1271,7 @@ protected function _checkRequestData(): void
$validator->validateCreateDocument();
}

/** @psalm-suppress TypeDoesNotContainType */
if ($requestMethod === 'PATCH' || $requestMethod === 'DELETE') {
$validator->validateUpdateDocument();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Listener/PaginationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PaginationListener extends BaseListener
*
* We attach at priority 10 so normal bound events can run before us
*
* @return array
* @return array<string, mixed>
*/
public function implementedEvents(): array
{
Expand Down Expand Up @@ -86,6 +86,7 @@ protected function _getJsonApiPaginationResponse(array $pagination): array
$query['sort'] = $request->getQuery('sort');
}

/** @psalm-suppress UndefinedMagicPropertyFetch */
$fullBase = (bool)$this->_controller()->Crud->getConfig('listeners.jsonApi.absoluteLinks');

$baseUrl = $request->getAttributes()['params'];
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/SearchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchListener extends BaseListener
* Returns a list of all events that will fire in the controller during its lifecycle.
* You can override this function to add your own listener callbacks
*
* @return array
* @return array<string, mixed>
*/
public function implementedEvents(): array
{
Expand Down

0 comments on commit 0f93824

Please sign in to comment.