From 07d1e86a6346070074b301bfbf3eb0665ae16a98 Mon Sep 17 00:00:00 2001 From: "Richard B. Porter" Date: Thu, 5 Sep 2024 02:29:50 +0000 Subject: [PATCH 1/2] Increase phpstan to level 4 --- UsersCommands.php | 16 ++++++++-------- phpstan.neon | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/UsersCommands.php b/UsersCommands.php index d57d6cf..e7f4947 100644 --- a/UsersCommands.php +++ b/UsersCommands.php @@ -240,10 +240,10 @@ public function toggle() { throw new UserAbortException(); } - if (Drush::drush($this->siteAliasManager()->getSelf(), 'user:block', [$block_list])->mustRun()) { - \Drupal::state()->set('utog_previous', $previous); - \Drupal::state()->set('utog_status', 'blocked'); - } + // drush->mustRun() will throw an exception if not successful. + Drush::drush($this->siteAliasManager()->getSelf(), 'user:block', [$block_list])->mustRun(); + \Drupal::state()->set('utog_previous', $previous); + \Drupal::state()->set('utog_status', 'blocked'); } else { if (\Drupal::configFactory()->getEditable('user.settings')->get('notify.status_activated')) { @@ -271,10 +271,10 @@ public function toggle() { throw new UserAbortException(); } - if (Drush::drush($this->siteAliasManager()->getSelf(), 'user:unblock', [$unblock_list])->mustRun()) { - \Drupal::state()->set('utog_previous', []); - \Drupal::state()->set('utog_status', 'unblocked'); - } + // drush->mustRun() will throw an exception if not successful. + Drush::drush($this->siteAliasManager()->getSelf(), 'user:unblock', [$unblock_list])->mustRun(); + \Drupal::state()->set('utog_previous', []); + \Drupal::state()->set('utog_status', 'unblocked'); } } } diff --git a/phpstan.neon b/phpstan.neon index 382a4f4..2e764e7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 4 scanDirectories: - vendor/drush/drush/src-symfony-compatibility ignoreErrors: From 649ed13fb6ad89d4a2f14170af6cd06fb8095e1d Mon Sep 17 00:00:00 2001 From: "Richard B. Porter" Date: Thu, 5 Sep 2024 02:39:38 +0000 Subject: [PATCH 2/2] Increase phpstan level to 6 --- UsersCommands.php | 12 ++++++------ phpstan.neon | 2 +- tests/ListTest.php | 16 ++++++++-------- tests/ToggleTest.php | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/UsersCommands.php b/UsersCommands.php index e7f4947..0130e63 100644 --- a/UsersCommands.php +++ b/UsersCommands.php @@ -23,7 +23,7 @@ class UsersCommands extends DrushCommands implements SiteAliasManagerAwareInterf /** * Display a list of Drupal users. * - * @param array $options + * @param array $options * An associative array of options. * * @command users:list @@ -80,7 +80,7 @@ public function listAll( 'no-roles' => InputOption::VALUE_REQUIRED, 'last-login' => InputOption::VALUE_REQUIRED, ], - ) { + ): RowsOfFields { // Use an entityQuery to dynamically set property conditions. $query = \Drupal::entityQuery('user') ->accessCheck(FALSE) @@ -138,7 +138,7 @@ public function listAll( * * @throws \Exception */ - public function validateList(CommandData $commandData) { + public function validateList(CommandData $commandData): void { $input = $commandData->input(); $options = [ @@ -197,7 +197,7 @@ public function validateList(CommandData $commandData) { * @aliases utog * @bootstrap full */ - public function toggle() { + public function toggle(): void { // Get all users. $ids = \Drupal::entityQuery('user') ->accessCheck(FALSE) @@ -285,10 +285,10 @@ public function toggle() { * @param \Drupal\user\Entity\User $account * A user account object. * - * @return array + * @return array * An array of user information. */ - protected function infoArray(User $account) { + protected function infoArray(User $account): array { /** @var \Drupal\Core\Datetime\DateFormatter $date_formatter */ $date_formatter = \Drupal::service('date.formatter'); diff --git a/phpstan.neon b/phpstan.neon index 2e764e7..356ff4a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 6 scanDirectories: - vendor/drush/drush/src-symfony-compatibility ignoreErrors: diff --git a/tests/ListTest.php b/tests/ListTest.php index 1f138de..8163fce 100644 --- a/tests/ListTest.php +++ b/tests/ListTest.php @@ -40,7 +40,7 @@ protected function tearDown() :void { /** * Test all users are returned. */ - public function testAllUsers() { + public function testAllUsers(): void { $this->drush('users:list', []); $output = $this->getOutput(); @@ -53,7 +53,7 @@ public function testAllUsers() { /** * Test role option. */ - public function testUsersReturnedByMultipleRoles() { + public function testUsersReturnedByMultipleRoles(): void { $this->drush('role:create', ['publisher']); $this->drush('user:create', ['baz']); $this->drush('user:role:add', ['publisher', 'baz']); @@ -74,7 +74,7 @@ public function testUsersReturnedByMultipleRoles() { /** * Test no-role option. */ - public function testUsersReturnedByMultipleNoRoles() { + public function testUsersReturnedByMultipleNoRoles(): void { $this->drush('role:create', ['publisher']); $this->drush('user:create', ['baz']); $this->drush('user:role:add', ['publisher', 'baz']); @@ -94,7 +94,7 @@ public function testUsersReturnedByMultipleNoRoles() { /** * Test status option. */ - public function testUsersReturnedByStatus() { + public function testUsersReturnedByStatus(): void { $this->drush( 'users:list', [], @@ -110,7 +110,7 @@ public function testUsersReturnedByStatus() { /** * Test last-login option. */ - public function testUsersReturnedByLogin() { + public function testUsersReturnedByLogin(): void { // Update the login time for user 1. Drush user:login does not do this. $now = time(); @@ -134,7 +134,7 @@ public function testUsersReturnedByLogin() { /** * Test status and role options in combination. */ - public function testUsersReturnedByStatusRole() { + public function testUsersReturnedByStatusRole(): void { $this->drush('user:create', ['baz']); $this->drush('user:block', ['baz']); $this->drush('user:role:add', ['editor', 'baz']); @@ -155,7 +155,7 @@ public function testUsersReturnedByStatusRole() { /** * Test status, role and last-login options in combination. */ - public function testUsersReturnedByStatusRoleLogin() { + public function testUsersReturnedByStatusRoleLogin(): void { // Update the login time for user 1. Drush user:login does not do this. $now = time(); @@ -200,7 +200,7 @@ public function testUsersReturnedByStatusRoleLogin() { /** * Test validation. */ - public function testValidation() { + public function testValidation(): void { // Role 'garbage' does not exist. $this->drush( 'users:list', diff --git a/tests/ToggleTest.php b/tests/ToggleTest.php index 995b4f3..564ef92 100644 --- a/tests/ToggleTest.php +++ b/tests/ToggleTest.php @@ -40,7 +40,7 @@ protected function tearDown() :void { /** * Test users are correctly blocked. */ - public function testUsersBlocked() { + public function testUsersBlocked(): void { $this->drush('users:toggle', []); $this->drush('user:information', ['foo, bar'], ['format' => 'json']); @@ -54,7 +54,7 @@ public function testUsersBlocked() { /** * Test users are correctly unblocked. */ - public function testUsersUnblocked() { + public function testUsersUnblocked(): void { // First block, then unblock. $this->drush('users:toggle', []); $this->drush('users:toggle', []);