Skip to content

Commit

Permalink
Merge pull request #300 from FriendsOfCake/cake-5-update
Browse files Browse the repository at this point in the history
Update for Cake 5
  • Loading branch information
ADmad authored Jun 27, 2022
2 parents 41109f1 + 6f32e3f commit 34a22b4
Show file tree
Hide file tree
Showing 30 changed files with 207 additions and 174 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ on: [push, pull_request]

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

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -28,47 +28,49 @@ jobs:
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 install
composer update
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
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 == '7.4'
uses: codecov/codecov-action@v2
if: matrix.php-version == '8.1'
uses: codecov/codecov-action@v3

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

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: vimeo/psalm:4.22, phpstan:1.4
tools: vimeo/psalm:4.23, phpstan:1.7, cs2pr

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

- name: Run phpcs
run: vendor/bin/phpcs --report=checkstyle --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/
run: vendor/bin/phpcs --report=checkstyle --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ | cs2pr

- name: Run psalm
if: success() || failure()
if: always()
run: psalm --output-format=github

- name: Run phpstan
if: success() || failure()
if: always()
run: phpstan analyse --error-format=github
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
}
],
"require": {
"cakephp/cakephp": "^4.0",
"friendsofcake/crud": "^6.0",
"friendsofcake/bootstrap-ui": "^3.0"
"cakephp/cakephp": "5.x-dev",
"friendsofcake/crud": "dev-cake-5",
"friendsofcake/bootstrap-ui": "dev-cake-5"
},
"require-dev": {
"friendsofcake/cakephp-test-utilities": "^2.0",
"markstory/asset_compress": "^4.0",
"phpunit/phpunit": "~8.5.0 || ^9.3"
"friendsofcake/cakephp-test-utilities": "dev-cake-5.x",
"phpunit/phpunit": "^9.5.19"
},
"autoload": {
"psr-4": {
Expand All @@ -54,5 +53,7 @@
"wiki": "http://cakephp.nu/cakephp-crud/",
"irc": "irc://irc.freenode.org/friendsofcake"
},
"prefer-stable": true
"config": {
"sort-packages": true
}
}
15 changes: 12 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ parameters:
count: 1
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 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\\.$#"
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

Expand All @@ -71,7 +81,6 @@ parameters:
path: src/View/Widget/DateTimeWidget.php

-
message: "#^Parameter \\#1 \\$options of method Cake\\\\View\\\\StringTemplate\\:\\:formatAttributes\\(\\) expects array\\<string, mixed\\>\\|null, array\\<string\\>\\|string given\\.$#"
message: "#^Parameter \\#1 \\$options of method Cake\\\\View\\\\StringTemplate\\:\\:formatAttributes\\(\\) expects array\\<string, mixed\\>\\|null, array\\<string\\>\\|string\\|null given\\.$#"
count: 1
path: src/View/Widget/DateTimeWidget.php

33 changes: 12 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,23 @@
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="CrudView Tests">
<directory>./tests/TestCase</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
</extensions>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>

<php>
<!-- <env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/> -->
</php>
</phpunit>
16 changes: 16 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>
</file>
<file src="src/View/Widget/DateTimeWidget.php">
<PossiblyNullArrayAccess occurrences="2">
<code>$data['name']</code>
<code>$data['templateVars']</code>
</PossiblyNullArrayAccess>
</file>
</files>
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src" />
Expand Down
6 changes: 3 additions & 3 deletions src/Action/DashboardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class DashboardAction extends BaseAction
{
use ViewTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'view' => null,
];

/**
* HTTP GET handler
*
* @return void|\Cake\Http\Response
* @return void
*/
protected function _get()
protected function _get(): void
{
$pageTitle = $this->getConfig('scaffold.page_title', __d('CrudView', 'Dashboard'));
$this->setConfig('scaffold.page_title', $pageTitle);
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrumb/ActiveBreadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ActiveBreadcrumb extends Breadcrumb
* @inheritDoc
* @psalm-suppress MissingParamType
*/
public function __construct($title, $url = null, array $options = [])
public function __construct(string|array $title, string|array|null $url = null, array $options = [])
{
if (!isset($options['class'])) {
$options['class'] = '';
Expand Down
24 changes: 12 additions & 12 deletions src/Breadcrumb/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,43 @@ class Breadcrumb
* If the specified $url is a link, then this will
* also be wrapped by `<a>` tags.
*
* @var string|array
* @var array|string
**/
protected $title;
protected string|array $title;

/**
* Cake-relative URL or array of URL parameters, or
* external URL (starts with http://)
*
* @var string|array|null
* @var array|string|null
*/
protected $url = null;
protected string|array|null $url = null;

/**
* Array of options and HTML attributes.
*
* @var array
**/
protected $options = [];
protected array $options = [];

/**
* Contains a breadcrumb entry
*
* @param string|array $title If provided as a string, it represents the title of the crumb.
* @param array|string $title If provided as a string, it represents the title of the crumb.
* Alternatively, if you want to add multiple crumbs at once, you can provide an array, with each values being a
* single crumb. Arrays are expected to be of this form:
* - *title* The title of the crumb
* - *link* The link of the crumb. If not provided, no link will be made
* - *options* Options of the crumb. See description of params option of this method.
* @param string|array|null $url URL of the crumb. Either a string, an array of route params to pass to
* @param array|string|null $url URL of the crumb. Either a string, an array of route params to pass to
* Url::build() or null / empty if the crumb does not have a link.
* @param array $options Array of options. These options will be used as attributes HTML attribute the crumb will
* be rendered in (a <li> tag by default). It accepts two special keys:
* - *innerAttrs*: An array that allows you to define attributes for the inner element of the crumb (by default, to
* the link)
* - *templateVars*: Specific template vars in case you override the templates provided.
*/
public function __construct($title, $url = null, array $options = [])
public function __construct(string|array $title, string|array|null $url = null, array $options = [])
{
$this->title = $title;
$this->url = $url;
Expand All @@ -56,19 +56,19 @@ public function __construct($title, $url = null, array $options = [])
/**
* Returns the menu item title
*
* @return string|array
* @return array|string
*/
public function getTitle()
public function getTitle(): string|array
{
return $this->title;
}

/**
* Returns the menu item ur
*
* @return string|array|null
* @return array|string|null
*/
public function getUrl()
public function getUrl(): string|array|null
{
return $this->url;
}
Expand Down
39 changes: 39 additions & 0 deletions src/CrudViewPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

namespace CrudView;

use Cake\Core\BasePlugin;

/**
* Plugin class for CrudView
*/
class CrudViewPlugin extends BasePlugin
{
/**
* Plugin name.
*
* @var string|null
*/
protected ?string $name = 'CrudView';
/**
* Do bootstrapping or not
*
* @var bool
*/
protected bool $bootstrapEnabled = false;

/**
* Console middleware
*
* @var bool
*/
protected bool $consoleEnabled = false;

/**
* Load routes or not
*
* @var bool
*/
protected bool $routesEnabled = false;
}
2 changes: 1 addition & 1 deletion src/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function addToColumn(Cell $module, int $column = 1)
* @return int
* @throws \InvalidArgumentException the column count is invalid
*/
protected function _setColumns(int $value)
protected function _setColumns(int $value): int
{
$columnMap = [
1 => 12,
Expand Down
Loading

0 comments on commit 34a22b4

Please sign in to comment.