Skip to content

Commit

Permalink
Updates for Cake 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 31, 2022
1 parent 060cd10 commit 83ecacf
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 90 deletions.
49 changes: 5 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,12 @@ on: [push, pull_request]

jobs:
testsuite:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
prefer-lowest: ['']
php-version: ['8.1', '8.2']
include:
- php-version: '8.1'
prefer-lowest: 'prefer-lowest'

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
coverage: pcov

- name: Composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
elif ${{ matrix.php-version == '8.2' }}; then
composer update --ignore-platform-req=php
else
composer update
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: matrix.php-version == '8.1'
uses: codecov/codecov-action@v3
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
Expand All @@ -59,10 +20,10 @@ jobs:
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: vimeo/psalm:4, phpstan:1.9, cs2pr
tools: vimeo/psalm:5, phpstan:1.9, cs2pr

- name: Composer Install
run: composer require --dev cakephp/cakephp-codesniffer:5.x-dev
run: composer require --dev cakephp/cakephp-codesniffer:^5.0

- name: Run phpcs
run: vendor/bin/phpcs --report=checkstyle --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ | cs2pr
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"require-dev": {
"friendsofcake/cakephp-test-utilities": "dev-cake-5.x",
"markstory/asset_compress": "5.x-dev",
"phpunit/phpunit": "^9.5.19"
},
"autoload": {
Expand All @@ -53,11 +54,12 @@
"wiki": "http://cakephp.nu/cakephp-crud/",
"irc": "irc://irc.freenode.org/friendsofcake"
},
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
27 changes: 1 addition & 26 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,7 @@ parameters:
path: src/Listener/ViewSearchListener.php

-
message: "#^Call to method css\\(\\) on an unknown class AssetCompress\\\\View\\\\Helper\\\\AssetCompressHelper\\.$#"
count: 1
path: src/View/CrudView.php

-
message: "#^Call to method script\\(\\) on an unknown class AssetCompress\\\\View\\\\Helper\\\\AssetCompressHelper\\.$#"
count: 2
path: src/View/CrudView.php

-
message: "#^Binary operation \"\\+\" between string and array\\{data\\-enable\\-seconds\\?\\: 'true', data\\-date\\-format\\: string, data\\-alt\\-format\\?\\: mixed, data\\-alt\\-input\\?\\: 'true', data\\-no\\-calendar\\?\\: 'true', data\\-enable\\-time\\?\\: 'true', data\\-alt\\-input\\-class\\?\\: string, class\\: array\\{'input\\-group', 'flatpickr'\\}\\} results in an error\\.$#"
count: 1
path: src/View/Widget/DateTimeWidget.php

-
message: "#^Binary operation \"\\+\\=\" between array\\<string\\>\\|string\\|null and array\\{data\\-enable\\-seconds\\?\\: 'true', data\\-date\\-format\\: string, data\\-alt\\-format\\?\\: mixed, data\\-alt\\-input\\?\\: 'true', data\\-no\\-calendar\\?\\: 'true', data\\-enable\\-time\\?\\: 'true'\\} results in an error\\.$#"
count: 1
path: src/View/Widget/DateTimeWidget.php

-
message: "#^Offset 'data\\-wrap' does not exist on array\\{data\\-enable\\-seconds\\?\\: 'true', data\\-date\\-format\\: string, data\\-alt\\-format\\?\\: mixed, data\\-alt\\-input\\?\\: 'true', data\\-no\\-calendar\\?\\: 'true', data\\-enable\\-time\\?\\: 'true'\\}\\.$#"
count: 1
path: src/View/Widget/DateTimeWidget.php

-
message: "#^Offset 'iconClass' on array\\{data\\-enable\\-seconds\\?\\: 'true', data\\-date\\-format\\: string, data\\-alt\\-format\\?\\: mixed, data\\-alt\\-input\\?\\: 'true', data\\-no\\-calendar\\?\\: 'true', data\\-enable\\-time\\?\\: 'true'\\} in isset\\(\\) does not exist\\.$#"
message: "#^Binary operation \"\\+\" between string and non\\-empty\\-array results in an error\\.$#"
count: 1
path: src/View/Widget/DateTimeWidget.php

Expand Down
20 changes: 13 additions & 7 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<file src="src/View/CrudView.php">
<UndefinedDocblockClass occurrences="3">
<code>$this-&gt;AssetCompress</code>
<code>$this-&gt;AssetCompress</code>
<code>$this-&gt;AssetCompress</code>
</UndefinedDocblockClass>
<files psalm-version="dev-master@">
<file src="src/Listener/ViewListener.php">
<UndefinedPropertyAssignment occurrences="1">
<code>$event-&gt;getSubject()-&gt;element</code>
</UndefinedPropertyAssignment>
</file>
<file src="src/Listener/ViewSearchListener.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$input['type']</code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="src/View/Widget/DateTimeWidget.php">
<PossiblyNullArrayAccess occurrences="2">
<code>$data['name']</code>
<code>$data['templateVars']</code>
</PossiblyNullArrayAccess>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$data['type']</code>
</PossiblyUndefinedArrayOffset>
</file>
</files>
4 changes: 4 additions & 0 deletions src/Listener/ViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ViewListener extends BaseListener
*
* @param \Cake\Event\EventInterface $event Event.
* @return void
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
*/
public function beforeFind(EventInterface $event): void
{
Expand All @@ -57,6 +58,7 @@ public function beforeFind(EventInterface $event): void
*
* @param \Cake\Event\EventInterface $event Event.
* @return void
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
*/
public function beforePaginate(EventInterface $event): void
{
Expand All @@ -77,6 +79,7 @@ public function beforePaginate(EventInterface $event): void
*
* @param \Cake\Event\EventInterface $event Event.
* @return void
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
*/
public function beforeRender(EventInterface $event): void
{
Expand Down Expand Up @@ -125,6 +128,7 @@ public function beforeRender(EventInterface $event): void
*
* @param \Cake\Event\EventInterface $event Event.
* @return void
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
*/
public function setFlash(EventInterface $event): void
{
Expand Down
11 changes: 1 addition & 10 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Cake\Utility\Text;
use Cake\View\Helper;
use Cake\View\Helper\FormHelper;
use DateTimeInterface;

/**
* @property \BootstrapUI\View\Helper\FormHelper $Form
Expand Down Expand Up @@ -206,15 +205,7 @@ public function formatDate(string $field, mixed $value, array $options): string
return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
}

if (
is_int($value)
|| is_string($value)
|| $value instanceof DateTimeInterface
) {
return $this->Time->timeAgoInWords($value, $options);
}

return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
return $this->Time->timeAgoInWords($value, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/CrudViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CrudViewHelperTest extends TestCase
protected CrudViewHelper $CrudView;

/**
* @var \Cake\View\View&\PHPUnit_Framework_MockObject_MockObject
* @var \Cake\View\View&\PHPUnit\Framework\MockObject\MockObject
*/
protected $View;

Expand Down

0 comments on commit 83ecacf

Please sign in to comment.