From c83692f277792a617b2e3f4b55463782f42aa643 Mon Sep 17 00:00:00 2001 From: Lorenzo Milesi Date: Thu, 11 Aug 2022 09:47:33 +0200 Subject: [PATCH] Update PHP-CS-Fixer to v3.x (#460) --- .gitignore | 3 +- .php-cs-fixer.dist.php | 43 ++++++++++++++++ .php_cs.dist | 49 ------------------- CHANGELOG.md | 2 +- composer.json | 3 +- src/User/Bootstrap.php | 2 +- .../Controller/RegistrationController.php | 6 +-- src/User/Filter/AccessRuleFilter.php | 2 +- src/User/Helper/SecurityHelper.php | 5 +- src/User/Model/Profile.php | 4 +- src/User/Model/SocialNetworkAccount.php | 16 +++--- src/User/Model/Token.php | 10 ++-- src/User/Model/User.php | 48 +++++++++--------- src/User/Module.php | 6 +-- src/User/Service/UserConfirmationService.php | 4 +- src/User/resources/views/mail/welcome.php | 1 + 16 files changed, 98 insertions(+), 106 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist diff --git a/.gitignore b/.gitignore index 1f8808c..50f7380 100644 --- a/.gitignore +++ b/.gitignore @@ -47,8 +47,7 @@ codeception.yml # Code Style Checkers and Mess Detectors /phpcs.xml -/.php_cs.cache -/.php_cs +.php-cs-fixer.cache # composer composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..c43072a --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,43 @@ + + +For the full copyright and license information, please view +the LICENSE file that was distributed with this source code. +EOF; + + +$finder = PhpCsFixer\Finder::create() + ->exclude(['resources']) + ->in("src/User") +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PSR1' => true, + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'header_comment' => ['header' => $header], + 'combine_consecutive_unsets' => true, + 'no_extra_blank_lines' => [ + 'tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait',], + ], + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_order' => true, + 'phpdoc_align' => true, + 'no_trailing_whitespace' => true, + 'no_whitespace_in_blank_line' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_whitespace_before_comma_in_array' => true, + 'trim_array_spaces' => true, + 'explicit_string_variable' => true, + 'binary_operator_spaces' => true, + ]) + ->setFinder($finder) +; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index a9d6959..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,49 +0,0 @@ - - -For the full copyright and license information, please view -the LICENSE file that was distributed with this source code. -EOF; - -$finder = PhpCsFixer\Finder::create() - ->exclude([ - '.github', - 'docs', - 'temp', - 'tests', - 'vendor', - 'src/User/resources' - ]) - ->in(__DIR__); - - return PhpCsFixer\Config::create() - ->setRules(array( - '@PSR1' => true, - '@PSR2' => true, - 'header_comment' => ['header' => $header], - 'array_syntax' => array('syntax' => 'short'), - 'combine_consecutive_unsets' => true, - 'no_extra_consecutive_blank_lines' => array( - 'break', - 'continue', - 'extra', - 'return', - 'throw', - 'use', - 'parenthesis_brace_block', - 'square_brace_block', - 'curly_brace_block' - ), - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_order' => true, - 'phpdoc_align' => true - - )) - ->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d215b..0cc0aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # CHANGELOG ## 1.6.0 work in progress - **WARNING**: this release (long time due) makes a step forward in PHP compatibility, leaving behind obsolete versions. While yii2-usuario should still work without issues on 5.6, from now on testing and development will @@ -24,6 +23,7 @@ look forward and manitain only >=7.4 versions. - Ehn #412: Allow role names to support UTF-8 chars (4khobta) - Ehn #448: Remove deprecated SwiftMailer, use SymfonyMailer instead (TonisOrmisson) - Ehn #428: Translations of the placeholders in the login widget (anapaulaxenon) +- Update PHP-CS-Fixer configuration to new version (maxxer) ## 1.5.1 April 5, 2020 diff --git a/composer.json b/composer.json index 8802a94..2c478dd 100644 --- a/composer.json +++ b/composer.json @@ -52,10 +52,9 @@ "2amigos/qrcode-library": "Needed if you want to enable 2FA with QR Code generation. Require version ^1.1" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3", "php": ">=7.4", - "yiisoft/yii2-symfonymailer": "~2.0.0", - "friendsofphp/php-cs-fixer": "^2.3", "squizlabs/php_codesniffer": "*", "phpmd/phpmd": "@stable", "codeception/verify": "^0.3.3", diff --git a/src/User/Bootstrap.php b/src/User/Bootstrap.php index 0ae7e8d..a614e7a 100755 --- a/src/User/Bootstrap.php +++ b/src/User/Bootstrap.php @@ -365,7 +365,7 @@ class Bootstrap implements BootstrapInterface $mapping = array_merge($defaults, $userClassMap); foreach ($mapping as $name => $definition) { - $map[$this->getRoute($routes, $name) . "\\$name"] = $definition; + $map[$this->getRoute($routes, $name) . "\\{$name}"] = $definition; } return $map; diff --git a/src/User/Controller/RegistrationController.php b/src/User/Controller/RegistrationController.php index bad49ab..6abb039 100644 --- a/src/User/Controller/RegistrationController.php +++ b/src/User/Controller/RegistrationController.php @@ -110,13 +110,13 @@ class RegistrationController extends Controller // Create a temporay $user so we can get the attributes, then get // the intersection between the $form fields and the $user fields. - $user = $this->make(User::class, [] ); + $user = $this->make(User::class, []); $fields = array_intersect_key($form->attributes, $user->attributes); - // Becomes password_hash + // Becomes password_hash $fields['password'] = $form['password']; - $user = $this->make(User::class, [], $fields ); + $user = $this->make(User::class, [], $fields); $user->setScenario('register'); $mailService = MailFactory::makeWelcomeMailerService($user); diff --git a/src/User/Filter/AccessRuleFilter.php b/src/User/Filter/AccessRuleFilter.php index b32721f..cb65826 100644 --- a/src/User/Filter/AccessRuleFilter.php +++ b/src/User/Filter/AccessRuleFilter.php @@ -37,7 +37,7 @@ class AccessRuleFilter extends AccessRule /** @var User $identity */ $identity = $user->identity; if (!$identity->gdpr_consent) { - Yii::$app->response->redirect([ "/$consentAction"])->send(); + Yii::$app->response->redirect(["/{$consentAction}"])->send(); } } } diff --git a/src/User/Helper/SecurityHelper.php b/src/User/Helper/SecurityHelper.php index 5fec4ab..372ec5b 100644 --- a/src/User/Helper/SecurityHelper.php +++ b/src/User/Helper/SecurityHelper.php @@ -13,8 +13,8 @@ namespace Da\User\Helper; use Yii; use yii\base\Exception; -use yii\base\Security; use yii\base\InvalidConfigException; +use yii\base\Security; class SecurityHelper { @@ -76,8 +76,7 @@ class SecurityHelper if (!isset($minPasswordRequirements)) { if (isset(Yii::$app->getModule('user')->minPasswordRequirements)) { $minPasswordRequirements = Yii::$app->getModule('user')->minPasswordRequirements; - } - else { + } else { $minPasswordRequirements = [ 'lower' => 1, 'digit' => 1, diff --git a/src/User/Model/Profile.php b/src/User/Model/Profile.php index 72c1450..7d00e91 100644 --- a/src/User/Model/Profile.php +++ b/src/User/Model/Profile.php @@ -25,7 +25,7 @@ use yii\base\InvalidParamException; use yii\db\ActiveRecord; /** - * @property int $user_id + * @property int $user_id * @property string $name * @property string $public_email * @property string $gravatar_email @@ -34,7 +34,7 @@ use yii\db\ActiveRecord; * @property string $website * @property string $bio * @property string $timezone - * @property User $user + * @property User $user */ class Profile extends ActiveRecord { diff --git a/src/User/Model/SocialNetworkAccount.php b/src/User/Model/SocialNetworkAccount.php index 3251880..e076327 100644 --- a/src/User/Model/SocialNetworkAccount.php +++ b/src/User/Model/SocialNetworkAccount.php @@ -22,17 +22,17 @@ use yii\helpers\Url; /** * /** - * @property int $id Id - * @property int $user_id User id, null if account is not bind to user - * @property string $provider Name of service - * @property string $client_id Account id - * @property string $data Account properties returned by social network (json encoded) - * @property string $decodedData Json-decoded properties + * @property int $id Id + * @property int $user_id User id, null if account is not bind to user + * @property string $provider Name of service + * @property string $client_id Account id + * @property string $data Account properties returned by social network (json encoded) + * @property string $decodedData Json-decoded properties * @property string $code * @property string $email * @property string $username - * @property int $created_at - * @property User $user User that this account is connected for + * @property int $created_at + * @property User $user User that this account is connected for */ class SocialNetworkAccount extends ActiveRecord { diff --git a/src/User/Model/Token.php b/src/User/Model/Token.php index 2ee8e97..54c4abd 100644 --- a/src/User/Model/Token.php +++ b/src/User/Model/Token.php @@ -24,13 +24,13 @@ use yii\helpers\Url; /** * Token Active Record model. * - * @property int $user_id + * @property int $user_id * @property string $code - * @property int $type + * @property int $type * @property string $url - * @property bool $isExpired - * @property int $created_at - * @property User $user + * @property bool $isExpired + * @property int $created_at + * @property User $user */ class Token extends ActiveRecord { diff --git a/src/User/Model/User.php b/src/User/Model/User.php index 3671c93..eb30c83 100644 --- a/src/User/Model/User.php +++ b/src/User/Model/User.php @@ -31,33 +31,33 @@ use yii\web\IdentityInterface; * * @property bool $isAdmin * @property bool $isBlocked - * @property bool $isConfirmed whether user account has been confirmed or not - * @property bool $gdpr_deleted whether user requested deletion of his account - * @property bool $gdpr_consent whether user has consent personal data processing + * @property bool $isConfirmed whether user account has been confirmed or not + * @property bool $gdpr_deleted whether user requested deletion of his account + * @property bool $gdpr_consent whether user has consent personal data processing * * Database fields: - * @property int $id - * @property string $username - * @property string $email - * @property string $unconfirmed_email - * @property string $password_hash - * @property string $auth_key - * @property string $auth_tf_key - * @property int $auth_tf_enabled - * @property string $registration_ip - * @property int $confirmed_at - * @property int $blocked_at - * @property int $flags - * @property int $created_at - * @property int $updated_at - * @property int $last_login_at - * @property int $gdpr_consent_date date of agreement of data processing - * @property string $last_login_ip - * @property int $password_changed_at - * @property int $password_age - * Defined relations: + * @property int $id + * @property string $username + * @property string $email + * @property string $unconfirmed_email + * @property string $password_hash + * @property string $auth_key + * @property string $auth_tf_key + * @property int $auth_tf_enabled + * @property string $registration_ip + * @property int $confirmed_at + * @property int $blocked_at + * @property int $flags + * @property int $created_at + * @property int $updated_at + * @property int $last_login_at + * @property int $gdpr_consent_date date of agreement of data processing + * @property string $last_login_ip + * @property int $password_changed_at + * @property int $password_age + * Defined relations: * @property SocialNetworkAccount[] $socialNetworkAccounts - * @property Profile $profile + * @property Profile $profile */ class User extends ActiveRecord implements IdentityInterface { diff --git a/src/User/Module.php b/src/User/Module.php index 3522be9..1212d13 100755 --- a/src/User/Module.php +++ b/src/User/Module.php @@ -229,11 +229,11 @@ class Module extends BaseModule * @var boolean whether to disable IP logging into user table */ public $disableIpLogging = false; - + /** * @var array Minimum requirements when a new password is automatically generated. - * Array structure: `requirement => minimum number characters`. - * + * Array structure: `requirement => minimum number characters`. + * * Possible array keys: * - lower: minimum number of lowercase characters; * - upper: minimum number of uppercase characters; diff --git a/src/User/Service/UserConfirmationService.php b/src/User/Service/UserConfirmationService.php index aa18f4b..ab52ed4 100644 --- a/src/User/Service/UserConfirmationService.php +++ b/src/User/Service/UserConfirmationService.php @@ -19,7 +19,7 @@ use Da\User\Traits\MailAwareTrait; class UserConfirmationService implements ServiceInterface { use MailAwareTrait; - + protected $model; public function __construct(User $model) @@ -31,7 +31,7 @@ class UserConfirmationService implements ServiceInterface { $model = $this->model; $event = $this->make(UserEvent::class, [$model]); - + $this->model->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION, $event); if ((bool)$this->model->updateAttributes(['confirmed_at' => time()])) { $this->model->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event); diff --git a/src/User/resources/views/mail/welcome.php b/src/User/resources/views/mail/welcome.php index 50b6390..6a54c05 100644 --- a/src/User/resources/views/mail/welcome.php +++ b/src/User/resources/views/mail/welcome.php @@ -10,6 +10,7 @@ */ use yii\helpers\Html; +use yii\helpers\Url; /** * @var \Da\User\Module $module