Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake 5 #39

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ phpunit.xml.dist export-ignore
psalm.xml export-ignore
psalm-baseline.xml export-ignore
.readthedocs.yml export-ignore
docs export-ignore
tests export-ignore
CONTRIBUTING.md export-ignore
40 changes: 12 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- '*'

permissions:
contents: read

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

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
tools: phpstan:1, vimeo/psalm:4

- name: Composer Install
run: composer require --dev cakephp/cakephp-codesniffer:^4.0

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --standard=vendor/cakephp/cakephp-codesniffer/CakePHP -p src/ tests/

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

- name: Run phpstan
if: always()
run: phpstan
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
secrets: inherit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
composer.lock
vendor
.phpunit.result.cache
.phpunit.cache
phpstan.neon
phpunit.xml.dist
psalm.xml
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
}
],
"require":{
"cakephp/cakephp":"^4.0",
"friendsofcake/crud":"^6.0"
"cakephp/cakephp":"^5.0",
"friendsofcake/crud":"^7.0"
},
"require-dev":{
"phpunit/phpunit":"^8.5 || ^9.3",
"friendsofcake/cakephp-test-utilities":"^2.0"
"phpunit/phpunit":"^10.1 || ^11.0",
"friendsofcake/cakephp-test-utilities":"^3.0"
},
"autoload":{
"psr-4":{
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/actions/configuration/enabled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enabled
Test or modify if the Crud Action is enabled or not.

When a CrudAction is disabled, Crud will not handle any requests to the action, and CakePHP will raise the normal
``\Cake\Error\MissingActionException`` exception if you haven't implemented the action in your controller.
``\Cake\Controller\Exception\MissingActionException`` exception if you haven't implemented the action in your controller.

.. warning::

Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/after_find.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Logging the Found Item
public function delete($id)
{
$this->Crud->on('afterFind', function(\Cake\Event\EventInterface $event) {
$this->log("Found item: " . $event->subject()->entity->id . " in the database");
$this->log("Found item: " . $event->getSubject()->entity->id . " in the database");
});
return $this->Crud->execute();
Expand Down
8 changes: 4 additions & 4 deletions docs/_partials/events/after_save.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Check Created Status
public function edit($id)
{
$this->Crud->on('afterSave', function(\Cake\Event\EventInterface $event) {
if ($event->subject()->created) {
if ($event->getSubject()->created) {
$this->log("The entity was created");
} else {
$this->log("The entity was updated");
Expand All @@ -40,7 +40,7 @@ Check Success Status
public function edit($id)
{
$this->Crud->on('afterSave', function(\Cake\Event\EventInterface $event) {
if ($event->subject()->success) {
if ($event->getSubject()->success) {
$this->log("The entity was saved successfully");
} else {
$this->log("The entity was NOT saved successfully");
Expand All @@ -58,8 +58,8 @@ Get Entity ID
public function add()
{
$this->Crud->on('afterSave', function(\Cake\Event\EventInterface $event) {
if ($event->subject()->created) {
$this->log("The entity was created with id: " . $event->subject()->id);
if ($event->getSubject()->created) {
$this->log("The entity was created with id: " . $event->getSubject()->id);
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/before_find.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Add Conditions
public function delete($id)
{
$this->Crud->on('beforeFind', function(\Cake\Event\EventInterface $event) {
$event->subject()->query->where(['author' => $this->Authentication->getIdentityData('id')]);
$event->getSubject()->query->where(['author' => $this->Authentication->getIdentityData('id')]);
});
return $this->Crud->execute();
Expand Down
4 changes: 2 additions & 2 deletions docs/_partials/events/set_flash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ If you'd like to configure it on the fly you can use the eventManager to change
.. code-block:: phpinline
$this->eventManager()->on('Crud.setFlash', function (\Cake\Event\EventInterface $event) {
if ($event->subject()->success) {
$event->subject()->params['class'] = 'alert alert-success alert-dismissible';
if ($event->getSubject()->success) {
$event->getSubject()->params['class'] = 'alert alert-success alert-dismissible';
}
});
Expand Down
6 changes: 0 additions & 6 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ Installation

Installing CRUD Users requires only a few steps

Requirements
------------

* CakePHP 3.x
* PHP 5.6+

Getting the Code
----------------

Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
parameters:
level: 8
checkMissingIterableValueType: false
paths:
- src
universalObjectCratesClasses:
- Crud\Event\Subject
ignoreErrors:
-
identifier: missingType.iterableValue
-
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Authentication\\.$#"
count: 4
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<phpunit
bootstrap="./tests/bootstrap.php"
>

<testsuites>
<testsuite name="Twitter Bootstrap Test Cases">
<testsuite name="Crud Users Test Cases">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
errorLevel="4"
resolveFromConfigFile="true"
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"
findUnusedBaselineEntry="true"
findUnusedCode="false"
usePhpDocMethodsWithoutMagicCall="true"
>
<projectFiles>
<directory name="src" />
Expand Down
12 changes: 6 additions & 6 deletions src/Action/ForgotPasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ForgotPasswordAction extends BaseAction
use ViewTrait;
use ViewVarTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'scope' => 'entity',
'findMethod' => 'all',
Expand Down Expand Up @@ -57,24 +57,24 @@ protected function _get(): void
/**
* HTTP POST handler
*
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _post()
protected function _post(): ?Response
{
$subject = $this->_subject([
'findMethod' => $this->_getFindConfig(),
]);

$this->_trigger('beforeForgotPassword', $subject);

$entity = $this->_table()
->find($subject->findMethod[0], $subject->findMethod[1])
$entity = $this->_model()
->find($subject->findMethod[0], ...$subject->findMethod[1])
->first();

if (empty($entity)) {
$this->_error($subject);

return;
return null;
}

$subject->set(['entity' => $entity]);
Expand Down
17 changes: 12 additions & 5 deletions src/Action/LoginAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LoginAction extends BaseAction
{
use RedirectTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'messages' => [
'success' => [
Expand All @@ -28,10 +28,11 @@ class LoginAction extends BaseAction
/**
* HTTP GET handler
*
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _get()
protected function _get(): ?Response
{
/** @psalm-suppress UndefinedMagicPropertyFetch */
$result = $this->_controller()->Authentication->getResult();
$subject = $this->_subject([
'success' => true,
Expand All @@ -43,15 +44,18 @@ protected function _get()
}

$this->_trigger('beforeRender', $subject);

return null;
}

/**
* HTTP POST handler
*
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _post()
protected function _post(): ?Response
{
/** @psalm-suppress UndefinedMagicPropertyFetch */
$result = $this->_controller()->Authentication->getResult();
$subject = $this->_subject([
'result' => $result,
Expand All @@ -62,6 +66,8 @@ protected function _post()
}

$this->_error($subject);

return null;
}

/**
Expand All @@ -72,6 +78,7 @@ protected function _post()
*/
protected function _success(Subject $subject): ?Response
{
/** @psalm-suppress UndefinedMagicPropertyFetch */
$subject->set([
'success' => true,
'identity' => $this->_controller()->Authentication->getIdentity(),
Expand Down
6 changes: 4 additions & 2 deletions src/Action/LogoutAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

namespace CrudUsers\Action;

use Cake\Http\Response;
use Crud\Action\BaseAction;
use Crud\Traits\RedirectTrait;

class LogoutAction extends BaseAction
{
use RedirectTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'messages' => [
'success' => [
Expand All @@ -25,11 +26,12 @@ class LogoutAction extends BaseAction
*
* @return \Cake\Http\Response|null
*/
protected function _get()
protected function _get(): ?Response
{
$subject = $this->_subject();
$this->_trigger('beforeLogout', $subject);

/** @psalm-suppress UndefinedMagicPropertyFetch */
$redirectUrl = $this->_controller()->Authentication->logout();
$redirectUrl = $this->getConfig('redirectUrl', $redirectUrl);
if ($redirectUrl === false) {
Expand Down
12 changes: 7 additions & 5 deletions src/Action/RegisterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RegisterAction extends BaseAction
use ViewTrait;
use ViewVarTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'scope' => 'entity',
'inflection' => 'singular',
Expand Down Expand Up @@ -60,7 +60,7 @@ class RegisterAction extends BaseAction
*
* @return void
*/
protected function _get()
protected function _get(): void
{
$subject = $this->_subject([
'success' => true,
Expand All @@ -76,9 +76,9 @@ protected function _get()
/**
* HTTP POST handler
*
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _post()
protected function _post(): ?Response
{
$subject = $this->_subject([
'entity' => $this->_entity($this->_request()->getData(), $this->saveOptions()),
Expand All @@ -89,12 +89,14 @@ protected function _post()
$this->_trigger('beforeRegister', $subject);

/** @var callable $callback */
$callback = [$this->_table(), $subject->saveMethod];
$callback = [$this->_model(), $subject->saveMethod];
if ($callback($subject->entity, $subject->saveOptions)) {
return $this->_success($subject);
}

$this->_error($subject);

return null;
}

/**
Expand Down
Loading