Skip to content

Commit

Permalink
Cake5 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed Oct 15, 2023
1 parent 495589f commit 1022e36
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 198 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:

jobs:
testsuite:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['8.1', '8.2']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']
include:
- php-version: '7.2'
- php-version: '8.1'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

Expand All @@ -31,7 +31,7 @@ jobs:
POSTGRES_PASSWORD: postgres

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

- name: Setup Service
if: matrix.db-type == 'mysql'
Expand Down Expand Up @@ -62,27 +62,27 @@ jobs:
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
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: success() && matrix.php-version == '7.4'
if: success() && matrix.php-version == '8.1'
uses: codecov/codecov-action@v3

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: cs2pr, vimeo/psalm:4, phpstan:1
Expand All @@ -91,7 +91,7 @@ jobs:
run: composer install

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

- name: Run psalm
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/composer.lock
/phpunit.xml
/vendor/
.phpunit.result.cache
/.phpunit.cache
/.idea/
/config/Migrations/schema-dump-default.lock
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "A CakePHP plugin which allows you to authenticate using social providers like Facebook/Google/Twitter etc.",
"type": "cakephp-plugin",
"require": {
"cakephp/cakephp": "^4.1",
"cakephp/cakephp": "^5.0",
"socialconnect/auth": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^8.5.0 || ^9.5.0",
"cakephp/cakephp-codesniffer": "^4.0"
"phpunit/phpunit": "^10.1",
"cakephp/cakephp-codesniffer": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -24,8 +24,8 @@
},
"license": "MIT",
"scripts": {
"cs-check": "vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "vendor/bin/phpcbf -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
"cs-check": "phpcs --colors -p ./src ./tests",
"cs-fix": "phpcbf --colors -p ./src ./tests"
},
"config": {
"allow-plugins": {
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Sentry">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
</ruleset>
42 changes: 24 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
stopOnFailure="false"
>
<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.1/phpunit.xsd"
cacheDirectory=".phpunit.cache">

<testsuites>
<testsuite name="social-auth">
<directory>tests/</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

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

<php>
<ini name="memory_limit" value="-1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
<!-- Postgres
<env name="DB_URL" value="postgres://root@localhost/cake_test_db"/>
-->
<!-- Mysql
<env name="DB_URL" value="mysql://root@localhost/cake_test_db"/>
-->
</php>
</phpunit>
16 changes: 8 additions & 8 deletions src/Database/Type/SerializedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ADmad\SocialAuth\Database\Type;

use Cake\Database\DriverInterface;
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use PDO;

Expand All @@ -20,10 +20,10 @@ class SerializedType extends BaseType
* Convert a value data into a serialized string.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return string|null
*/
public function toDatabase($value, DriverInterface $driver)
public function toDatabase(mixed $value, Driver $driver): mixed
{
if ($value === null || is_string($value)) {
return $value;
Expand All @@ -36,10 +36,10 @@ public function toDatabase($value, DriverInterface $driver)
* Convert string values to PHP data structure.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return mixed
*/
public function toPHP($value, DriverInterface $driver)
public function toPHP(mixed $value, Driver $driver): mixed
{
if ($value === null) {
return $value;
Expand All @@ -58,10 +58,10 @@ public function toPHP($value, DriverInterface $driver)
* Get the correct PDO binding type for string data.
*
* @param mixed $value The value being bound.
* @param \Cake\Database\DriverInterface $driver The driver.
* @param \Cake\Database\Driver $driver The driver.
* @return int
*/
public function toStatement($value, DriverInterface $driver)
public function toStatement(mixed $value, Driver $driver): int
{
if ($value === null) {
return PDO::PARAM_NULL;
Expand All @@ -76,7 +76,7 @@ public function toStatement($value, DriverInterface $driver)
* @param mixed $value The value to convert.
* @return mixed Converted value.
*/
public function marshal($value)
public function marshal(mixed $value): mixed
{
if (is_array($value) || $value === null) {
return $value;
Expand Down
42 changes: 22 additions & 20 deletions src/Middleware/SocialAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
use Cake\Http\Session as CakeSession;
use Cake\Log\Log;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\Table;
use Cake\Routing\Router;
use Cake\Utility\Hash;
use Exception;
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\StreamFactory;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -127,7 +129,7 @@ class SocialAuthMiddleware implements MiddlewareInterface, EventDispatcherInterf
*
* @var array
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'requestMethod' => 'POST',
'loginUrl' => '/users/login',
'loginRedirect' => '/',
Expand All @@ -150,35 +152,35 @@ class SocialAuthMiddleware implements MiddlewareInterface, EventDispatcherInterf
*
* @var \SocialConnect\Auth\Service|null
*/
protected $_service;
protected ?Service $_service = null;

/**
* Session for SocialConnect service.
*
* @var \SocialConnect\Provider\Session\SessionInterface|null
*/
protected $_session;
protected ?SessionInterface $_session;

/**
* User model instance.
*
* @var \Cake\ORM\Table
*/
protected $_userModel;
protected Table $_userModel;

/**
* Profile model instance.
*
* @var \Cake\ORM\Table
*/
protected $_profileModel;
protected Table $_profileModel;

/**
* Error.
*
* @var string
*/
protected $_error;
protected string $_error;

/**
* Constructor.
Expand Down Expand Up @@ -322,7 +324,7 @@ protected function _setupModelInstances(): void
* @param \Cake\Http\ServerRequest $request Request instance.
* @return \Cake\Datasource\EntityInterface|null
*/
protected function _getProfile($providerName, ServerRequest $request): ?EntityInterface
protected function _getProfile(string $providerName, ServerRequest $request): ?EntityInterface
{
$return = $this->_getSocialIdentity($providerName, $request);
if ($return === null) {
Expand Down Expand Up @@ -352,7 +354,7 @@ protected function _getProfile($providerName, ServerRequest $request): ?EntityIn
* @param \Cake\Http\ServerRequest $request Request instance.
* @return array{identity: \SocialConnect\Common\Entity\User, access_token: \SocialConnect\Provider\AccessTokenInterface}|null
*/
protected function _getSocialIdentity($providerName, ServerRequest $request): ?array
protected function _getSocialIdentity(string $providerName, ServerRequest $request): ?array
{
try {
$provider = $this->_getService($request)->getProvider($providerName);
Expand Down Expand Up @@ -444,11 +446,11 @@ protected function _getUser(EntityInterface $profile, CakeSession $session): ?En
* @param string $providerName Provider name.
* @param \SocialConnect\Common\Entity\User $identity Social connect entity.
* @param \SocialConnect\Provider\AccessTokenInterface $accessToken Access token
* @param \Cake\Datasource\EntityInterface $profile Social profile entity
* @param \Cake\Datasource\EntityInterface|null $profile Social profile entity
* @return \Cake\Datasource\EntityInterface
*/
protected function _patchProfile(
$providerName,
string $providerName,
SocialConnectUser $identity,
AccessTokenInterface $accessToken,
?EntityInterface $profile = null
Expand Down Expand Up @@ -603,8 +605,8 @@ protected function _setRedirectUrl(ServerRequest $request): void
$redirectUrl = $request->getQuery(static::QUERY_STRING_REDIRECT);
if (
empty($redirectUrl)
|| substr($redirectUrl, 0, 1) !== '/'
|| substr($redirectUrl, 0, 2) === '//'
|| !str_starts_with($redirectUrl, '/')
|| str_starts_with($redirectUrl, '//')
) {
return;
}
Expand All @@ -616,9 +618,9 @@ protected function _setRedirectUrl(ServerRequest $request): void
* Get URL to redirect to after authentication.
*
* @param \Cake\Http\ServerRequest $request Request instance.
* @return string|array
* @return array|string
*/
protected function _getRedirectUrl(ServerRequest $request)
protected function _getRedirectUrl(ServerRequest $request): array|string
{
$redirectUrl = $request->getSession()->read('SocialAuth.redirectUrl');
if ($redirectUrl) {
Expand All @@ -634,15 +636,15 @@ protected function _getRedirectUrl(ServerRequest $request)
* Trigger "beforeRedirect" event.
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request instance.
* @param string|array $redirectUrl Redirect URL.
* @param array|string $redirectUrl Redirect URL.
* @param string $status Auth status.
* @return string|array
* @return array|string
*/
protected function _triggerBeforeRedirect(
$request,
$redirectUrl,
ServerRequestInterface $request,
array|string $redirectUrl,
string $status = self::AUTH_STATUS_SUCCESS
) {
): array|string {
$event = $this->dispatchEvent(self::EVENT_BEFORE_REDIRECT, [
'redirectUrl' => $redirectUrl,
'status' => $status,
Expand All @@ -664,7 +666,7 @@ protected function _triggerBeforeRedirect(
* @param \Exception $exception The exception to log a message for.
* @return string Error message
*/
protected function _getLogMessage($request, $exception): string
protected function _getLogMessage(ServerRequestInterface $request, Exception $exception): string
{
$message = sprintf(
'[%s] %s',
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/SocialProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SocialProfile extends Entity
/**
* @var array<string, bool>
*/
protected $_accessible = [
protected array $_accessible = [
'*' => true,
'id' => false,
];
Expand Down
Loading

0 comments on commit 1022e36

Please sign in to comment.