Skip to content

Commit

Permalink
Update for Cake 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 19, 2023
1 parent 6392338 commit 6c58455
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: phpstan:1, vimeo/psalm:4
tools: phpstan:1.10, vimeo/psalm:5

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

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --standard=vendor/cakephp/cakephp-codesniffer/CakePHP -p src/ tests/
Expand Down
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
12 changes: 7 additions & 5 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.x-dev",
"friendsofcake/crud":"dev-cake-5"
},
"require-dev":{
"phpunit/phpunit":"^8.5 || ^9.3",
"friendsofcake/cakephp-test-utilities":"^2.0"
"phpunit/phpunit":"^10.1",
"friendsofcake/cakephp-test-utilities":"dev-cake-5.x"
},
"autoload":{
"psr-4":{
Expand All @@ -44,5 +44,7 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
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
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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
13 changes: 8 additions & 5 deletions src/Action/ForgotPasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
use Crud\Traits\ViewTrait;
use Crud\Traits\ViewVarTrait;

/**
* @method \Cake\ORM\Table _model()
*/
class ForgotPasswordAction extends BaseAction
{
use FindMethodTrait;
use RedirectTrait;
use ViewTrait;
use ViewVarTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'scope' => 'entity',
'findMethod' => 'all',
Expand Down Expand Up @@ -57,24 +60,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()
$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
14 changes: 9 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,9 +28,9 @@ 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
{
$result = $this->_controller()->Authentication->getResult();
$subject = $this->_subject([
Expand All @@ -43,14 +43,16 @@ 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
{
$result = $this->_controller()->Authentication->getResult();
$subject = $this->_subject([
Expand All @@ -62,6 +64,8 @@ protected function _post()
}

$this->_error($subject);

return null;
}

/**
Expand Down
5 changes: 3 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,7 +26,7 @@ class LogoutAction extends BaseAction
*
* @return \Cake\Http\Response|null
*/
protected function _get()
protected function _get(): ?Response
{
$subject = $this->_subject();
$this->_trigger('beforeLogout', $subject);
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
21 changes: 12 additions & 9 deletions src/Action/ResetPasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace CrudUsers\Action;

use Cake\Datasource\EntityInterface;
use Cake\Http\Exception\BadRequestException;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;
Expand All @@ -25,7 +26,7 @@ class ResetPasswordAction extends BaseAction
use ViewTrait;
use ViewVarTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'scope' => 'entity',
'findMethod' => 'all',
Expand Down Expand Up @@ -79,7 +80,7 @@ protected function _get(?string $token = null): void

$subject = $this->_subject([
'success' => true,
'entity' => $this->_table()->newEmptyEntity(),
'entity' => $this->_model()->newEmptyEntity(),
'token' => $token,
]);

Expand All @@ -92,9 +93,9 @@ protected function _get(?string $token = null): void
* Thin proxy for _put
*
* @param string|null $token Token
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _post($token = null)
protected function _post(?string $token = null): ?Response
{
return $this->_put($token);
}
Expand All @@ -103,9 +104,9 @@ protected function _post($token = null)
* HTTP PUT handler
*
* @param string|null $token Token
* @return \Cake\Http\Response|null|void
* @return \Cake\Http\Response|null
*/
protected function _put($token = null)
protected function _put(?string $token = null): ?Response
{
$entity = $this->_verify($this->_token($token));

Expand All @@ -115,6 +116,8 @@ protected function _put($token = null)
}

$this->_error($subject);

return null;
}

/**
Expand All @@ -123,9 +126,9 @@ protected function _put($token = null)
* @param \Crud\Event\Subject $subject Event subject
* @return \Cake\Datasource\EntityInterface|false
*/
protected function _save(Subject $subject)
protected function _save(Subject $subject): EntityInterface|false
{
$entity = $this->_table()->patchEntity(
$entity = $this->_model()->patchEntity(
$subject->entity,
$this->_request()->getData(),
$this->saveOptions()
Expand All @@ -135,7 +138,7 @@ protected function _save(Subject $subject)
$this->_trigger('beforeSave', $subject);

/** @var callable $callable */
$callable = [$this->_table(), $this->saveMethod()];
$callable = [$this->_model(), $this->saveMethod()];

/** @var \Cake\Datasource\EntityInterface|false $success */
$success = $callable($entity, $this->saveOptions());
Expand Down
16 changes: 9 additions & 7 deletions src/Action/VerifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VerifyAction extends BaseAction
use ViewTrait;
use ViewVarTrait;

protected $_defaultConfig = [
protected array $_defaultConfig = [
'enabled' => true,
'scope' => 'entity',
'findMethod' => 'all',
Expand Down Expand Up @@ -70,10 +70,10 @@ class VerifyAction extends BaseAction
/**
* HTTP GET handler
*
* @param string $token Token
* @return \Cake\Http\Response|null|void
* @param string|null $token Token
* @return \Cake\Http\Response|null
*/
protected function _get($token = null)
protected function _get(?string $token = null): ?Response
{
$token = $this->_token($token);
$entity = $this->_verify($token);
Expand All @@ -83,6 +83,8 @@ protected function _get($token = null)
}

$this->_error();

return null;
}

/**
Expand All @@ -91,9 +93,9 @@ protected function _get($token = null)
* @param \Cake\Datasource\EntityInterface $entity Entity
* @return \Cake\Datasource\EntityInterface|false
*/
protected function _save(EntityInterface $entity)
protected function _save(EntityInterface $entity): EntityInterface|false
{
$entity = $this->_table()->patchEntity(
$entity = $this->_model()->patchEntity(
$entity,
['verified' => true],
$this->saveOptions()
Expand All @@ -103,7 +105,7 @@ protected function _save(EntityInterface $entity)
$this->_trigger('beforeSave', $subject);

/** @var callable $callback */
$callback = [$this->_table(), $this->saveMethod()];
$callback = [$this->_model(), $this->saveMethod()];

/** @var \Cake\Datasource\EntityInterface|false $success */
$success = $callback($entity, $this->saveOptions());
Expand Down
Loading

0 comments on commit 6c58455

Please sign in to comment.