Skip to content

Commit fadfed9

Browse files
authored
Merge pull request #89 from UseMuffin/cake-5
Cake 5
2 parents 9a2d09f + c8892e6 commit fadfed9

File tree

17 files changed

+104
-196
lines changed

17 files changed

+104
-196
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
.gitignore export-ignore
55
.semver export-ignore
66
phpunit.xml.dist export-ignore
7-
.travis.yml export-ignore
87
.phpstan.neon export-ignore
98
psalm.xml export-ignore
109
tests export-ignore
1110
.github export-ignore
11+
phpcs.xml export-ignore

.github/workflows/ci.yml

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,94 +8,14 @@ on:
88
branches:
99
- '*'
1010

11+
permissions:
12+
contents: read
13+
1114
jobs:
1215
testsuite:
13-
runs-on: ubuntu-18.04
14-
strategy:
15-
fail-fast: false
16-
matrix:
17-
php-version: ['7.4', '8.0', '8.1']
18-
db-type: [mysql, pgsql]
19-
prefer-lowest: ['']
20-
include:
21-
- php-version: '7.2'
22-
db-type: 'sqlite'
23-
prefer-lowest: 'prefer-lowest'
24-
25-
services:
26-
postgres:
27-
image: postgres
28-
ports:
29-
- 5432:5432
30-
env:
31-
POSTGRES_PASSWORD: postgres
32-
33-
steps:
34-
- uses: actions/checkout@v2
35-
36-
- name: Setup Service
37-
if: matrix.db-type == 'mysql'
38-
run: |
39-
sudo service mysql start
40-
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
41-
42-
- name: Setup PHP
43-
uses: shivammathur/setup-php@v2
44-
with:
45-
php-version: ${{ matrix.php-version }}
46-
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
47-
coverage: pcov
48-
49-
- name: Composer install
50-
run: |
51-
composer --version
52-
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
53-
composer update --prefer-lowest --prefer-stable
54-
else
55-
composer install
56-
fi
57-
58-
- name: Run PHPUnit
59-
run: |
60-
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
61-
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
62-
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
63-
64-
if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
65-
vendor/bin/phpunit --coverage-clover=coverage.xml
66-
else
67-
vendor/bin/phpunit
68-
fi
69-
70-
- name: Code Coverage Report
71-
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
72-
uses: codecov/codecov-action@v2
16+
uses: ADmad/.github/.github/workflows/testsuite-with-db.yml@master
17+
secrets: inherit
7318

7419
cs-stan:
75-
name: Coding Standard & Static Analysis
76-
runs-on: ubuntu-18.04
77-
78-
steps:
79-
- uses: actions/checkout@v2
80-
81-
- name: Setup PHP
82-
uses: shivammathur/setup-php@v2
83-
with:
84-
php-version: '7.4'
85-
extensions: mbstring, intl
86-
coverage: none
87-
tools: vimeo/psalm:4.21, phpstan:1.4
88-
89-
- name: Composer Install
90-
run: composer require cakephp/cakephp-codesniffer:^4.2
91-
92-
- name: Run phpcs
93-
run: vendor/bin/phpcs --standard=CakePHP src/ tests/
94-
95-
- name: Run psalm
96-
if: success() || failure()
97-
run: psalm --output-format=github
98-
99-
- name: Run phpstan
100-
if: success() || failure()
101-
run: phpstan analyse
20+
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
21+
secrets: inherit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/composer.lock
22
/plugins
33
/vendor
4+
.phpunit.cache
45
.phpunit.result.cache
56
.idea

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Footprint
22

3-
[![Build Status](https://img.shields.io/travis/UseMuffin/Footprint/master.svg?style=flat-square)](https://github.com/UseMuffin/Footprint/actions?query=workflow%3ACI+branch%3Amaster)
4-
[![Coverage](https://img.shields.io/github/workflow/status/UseMuffin/Footprint/CI/master?style=flat-square)](https://codecov.io/github/UseMuffin/Footprint)
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/UseMuffin/Footprint/ci.yml?style=flat-square)](https://github.com/UseMuffin/Footprint/actions?query=workflow%3ACI+branch%3Amaster)
4+
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Footprint/master?style=flat-square)](https://codecov.io/github/UseMuffin/Footprint)
55
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/footprint.svg?style=flat-square)](https://packagist.org/packages/muffin/footprint)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
77

@@ -26,19 +26,7 @@ bin/cake plugin load Muffin/Footprint
2626
```
2727

2828
The Footprint plugin must be loaded **before** the [Authentication](https://github.com/cakephp/authentication) plugin,
29-
so you should move the
30-
31-
```php
32-
$this->addPlugin('Muffin/Footprint');
33-
```
34-
35-
statement above the
36-
37-
```php
38-
$this->addPlugin('Authentication');
39-
```
40-
41-
in your `Application::bootstrap()` manually if required.
29+
so you should updated your `config/plugins.php` or `Application::bootstrap()` accordingly.
4230

4331
## Usage
4432

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@
3030
"source": "https://github.com/usemuffin/footprint"
3131
},
3232
"require": {
33-
"cakephp/cakephp": "^4.0"
33+
"cakephp/cakephp": "^5.0"
3434
},
3535
"require-dev": {
36-
"cakephp/cakephp-codesniffer": "^4.0",
37-
"phpunit/phpunit": "~8.5.0",
38-
"cakephp/authentication": "^2.3"
36+
"cakephp/cakephp-codesniffer": "^5.0",
37+
"phpunit/phpunit": "^10.1"
3938
},
4039
"scripts": {
41-
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
42-
"cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
40+
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
41+
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/"
4342
},
4443
"autoload": {
4544
"psr-4": {

phpcs.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CakePHP Core">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4+
5+
<rule ref="CakePHP" />
6+
7+
<arg value="s"/>
8+
</ruleset>

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 7
2+
level: 8
33
checkGenericClassInNonGenericObjectType: false
44
checkMissingIterableValueType: false
55
treatPhpDocTypesAsCertain: false
@@ -9,4 +9,4 @@ parameters:
99
-
1010
message: "#^Call to an undefined method object\\:\\:getEventManager\\(\\)\\.$#"
1111
count: 1
12-
path: src/Plugin.php
12+
path: src/FootprintPlugin.php

phpunit.xml.dist

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
bootstrap="./tests/bootstrap.php"
4-
colors="true"
5-
stopOnFailure="false"
6-
>
7-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
83
<testsuites>
94
<testsuite name="Slug Test Cases">
105
<directory>./tests/</directory>
116
</testsuite>
127
</testsuites>
13-
14-
<!-- Setup a listener for fixtures -->
15-
<listeners>
16-
<listener
17-
class="\Cake\TestSuite\Fixture\FixtureInjector"
18-
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
19-
<arguments>
20-
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
21-
</arguments>
22-
</listener>
23-
</listeners>
24-
25-
<filter>
26-
<whitelist>
8+
<extensions>
9+
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
10+
</extensions>
11+
<php>
12+
<ini name="memory_limit" value="-1"/>
13+
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
14+
</php>
15+
<source>
16+
<include>
2717
<directory suffix=".php">./src/</directory>
28-
</whitelist>
29-
</filter>
18+
</include>
19+
</source>
3020
</phpunit>

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedCode="false"
9+
findUnusedBaselineEntry="true"
810
>
911
<projectFiles>
1012
<directory name="src" />

src/Event/FootprintListener.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
namespace Muffin\Footprint\Event;
55

6+
use ArrayObject;
67
use Cake\Core\InstanceConfigTrait;
78
use Cake\Datasource\EntityInterface;
89
use Cake\Event\EventInterface;
910
use Cake\Event\EventListenerInterface;
11+
use Cake\ORM\Query\SelectQuery;
1012

1113
class FootprintListener implements EventListenerInterface
1214
{
@@ -17,7 +19,7 @@ class FootprintListener implements EventListenerInterface
1719
*
1820
* @var array<string, mixed>
1921
*/
20-
protected $_defaultConfig = [
22+
protected array $_defaultConfig = [
2123
'events' => [
2224
'Model.beforeFind' => -100,
2325
'Model.beforeRules' => -100,
@@ -32,7 +34,7 @@ class FootprintListener implements EventListenerInterface
3234
*
3335
* @var \Cake\Datasource\EntityInterface|null
3436
*/
35-
protected $_currentUser;
37+
protected ?EntityInterface $_currentUser;
3638

3739
/**
3840
* Constructor.
@@ -85,12 +87,15 @@ public function getUser(): ?EntityInterface
8587
* Universal callback.
8688
*
8789
* @param \Cake\Event\EventInterface $event Event.
88-
* @param \Cake\ORM\Query|\Cake\Datasource\EntityInterface $ormObject Query or Entity.
90+
* @param \Cake\Datasource\EntityInterface|\Cake\ORM\Query\SelectQuery $ormObject Query or Entity.
8991
* @param \ArrayObject $options Options.
9092
* @return void
9193
*/
92-
public function handleEvent(EventInterface $event, $ormObject, $options): void
93-
{
94+
public function handleEvent(
95+
EventInterface $event,
96+
EntityInterface|SelectQuery $ormObject,
97+
ArrayObject $options
98+
): void {
9499
$key = $this->getConfig('optionKey');
95100
if ($this->_currentUser && empty($options[$key])) {
96101
$options[$key] = $this->_currentUser;

0 commit comments

Comments
 (0)