Skip to content

Commit 6599807

Browse files
authored
Merge pull request #78 from UseMuffin/develop
Develop
2 parents d58e86e + e9d53db commit 6599807

File tree

16 files changed

+289
-384
lines changed

16 files changed

+289
-384
lines changed

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ end_of_line = crlf
1515

1616
[*.yml]
1717
indent_style = space
18-
indent_size = 2
18+
indent_size = 2
19+
20+
[*.neon]
21+
indent_style = tab

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
.semver export-ignore
66
phpunit.xml.dist export-ignore
77
.travis.yml export-ignore
8+
.phpstan.neon export-ignore
9+
psalm.xml export-ignore
810
tests export-ignore
11+
.github export-ignore

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
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:root@127.0.0.1/cakephp'; fi
62+
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/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
73+
74+
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

.travis.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

README.md

Lines changed: 24 additions & 33 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://travis-ci.org/UseMuffin/Footprint)
4-
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Footprint.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Footprint)
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)
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

@@ -15,7 +15,7 @@ such as `user_id`, `created_by`, `company_id` similar to the core's `TimestampBe
1515

1616
Using [Composer][composer]:
1717

18-
```
18+
```bash
1919
composer require muffin/footprint
2020
```
2121

@@ -25,32 +25,34 @@ You then need to load the plugin by running console command:
2525
bin/cake plugin load Muffin/Footprint
2626
```
2727

28-
## Usage
28+
The Footprint plugin must be loaded **before** the [Authentication](https://github.com/cakephp/authentication) plugin,
29+
so you should move the
2930

30-
### Trait
31+
```php
32+
$this->addPlugin('Muffin/Footprint');
33+
```
3134

32-
First, you will need to include the `Muffin\Footprint\Auth\FootprintAwareTrait`
33-
to your `AppController`:
35+
statement above the
3436

3537
```php
36-
use Muffin\Footprint\Auth\FootprintAwareTrait;
38+
$this->addPlugin('Authentication');
39+
```
3740

38-
class AppController extends Controller
39-
{
40-
use FootprintAwareTrait;
41+
in your `Application::bootstrap()` manually if required.
4142

42-
// Specify the user model if required. Defaults to "Users".
43-
$this->_userModel = 'YourPlugin.Members';
44-
}
45-
```
43+
## Usage
4644

47-
This will attach the `Muffin\Footprint\Event\FootprintListener` to models
48-
which will inject the currently logged in user's instance on `Model.beforeSave`
49-
and `Model.beforeFind` in the `_footprint` key of `$options`.
45+
### Middleware
5046

51-
Your controller needs to have either `cakephp/authentication` plugin's `AuthenticationComponent`
52-
or CakePHP core's deprecated `AuthComponent` loaded so that the user identity
53-
can be fetched.
47+
Add the `FootprintMiddleware` to the middleware queue in your `Application::middleware()`
48+
method:
49+
50+
```php
51+
$middleware->add('Muffin/Footprint.Footprint');
52+
```
53+
54+
It must be added **after** `AuthenticationMiddleware` to ensure that it can read
55+
the identify info after authentication is done.
5456

5557
### Behavior
5658

@@ -67,7 +69,7 @@ You can customize that like so:
6769
$this->addBehavior('Muffin/Footprint.Footprint', [
6870
'events' => [
6971
'Model.beforeSave' => [
70-
'user_id' => 'new',
72+
'user_id' => 'new',
7173
'company_id' => 'new',
7274
'modified_by' => 'always'
7375
]
@@ -83,16 +85,6 @@ fields when creating a record, on the `modified_by` field again when updating
8385
the record and it will use the associated user record's company `id` in the
8486
`company_id` field when creating a record.
8587

86-
## Warning
87-
88-
If you have the `FootprintBehavior` attached to a model do not load the model inside
89-
`Controller::initialize()` method directly or indirectly. If you do so the
90-
footprint (user entity) won't be set for the model and the behavior won't work
91-
as expected. You can load your model in `Controller::beforeFilter()` if needed.
92-
93-
This is because the `FootprintListener` which sets the user entity to the models
94-
is attached after `Controller::initialize()` is run.
95-
9688
## Patches & Features
9789

9890
* Fork
@@ -114,4 +106,3 @@ Copyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT Lic
114106
[composer]:http://getcomposer.org
115107
[mit]:http://www.opensource.org/licenses/mit-license.php
116108
[muffin]:http://usemuffin.com
117-
[Ceeram/Blame]:http://github.com/ceeram/blame

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@
5252
"TestApp\\": "tests/test_app/TestApp",
5353
"Cake\\Test\\Fixture\\": "vendor/cakephp/cakephp/tests/Fixture"
5454
}
55+
},
56+
"config": {
57+
"allow-plugins": {
58+
"dealerdirect/phpcodesniffer-composer-installer": true
59+
}
5560
}
5661
}

phpstan.neon

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
parameters:
2-
level: 6
3-
checkGenericClassInNonGenericObjectType: false
4-
checkMissingIterableValueType: false
5-
treatPhpDocTypesAsCertain: false
6-
ignoreErrors:
7-
-
8-
message: "#^Negated boolean expression is always true\\.$#"
9-
count: 1
10-
path: src/Model/Behavior/FootprintBehavior.php
2+
level: 7
3+
checkGenericClassInNonGenericObjectType: false
4+
checkMissingIterableValueType: false
5+
treatPhpDocTypesAsCertain: false
6+
paths:
7+
- src/
8+
ignoreErrors:
9+
-
10+
message: "#^Call to an undefined method object\\:\\:getEventManager\\(\\)\\.$#"
11+
count: 1
12+
path: src/Plugin.php

psalm.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="2"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
16+
<issueHandlers>
17+
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
18+
<MissingClosureParamType errorLevel="suppress"/>
19+
<MissingClosureReturnType errorLevel="suppress"/>
20+
<PropertyNotSetInConstructor errorLevel="suppress"/>
21+
</issueHandlers>
22+
</psalm>

0 commit comments

Comments
 (0)