Skip to content

Conversation

@thomasdail
Copy link

  • In the latest version of rector, strictBooleans is deprecated
❯ ./vendor/bin/rector


 [WARNING] The "strictBooleans" set is deprecated as mostly risky and not practical. Remove it from withPreparedSets()
           method and use "codeQuality" and "codingStyle" sets instead. They already contain more granular and stable
           rules on same note.
  • replace the strictBooleans set with the codingStyle set. Some new rules were applied:
❯ ./vendor/bin/rector
 74/74 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
2 files with changes
====================

1) tests/Unit/Actions/CreateUserEmailResetNotificationTest.php:33

    ---------- begin diff ----------
@@ @@

     // Send multiple reset requests to trigger throttling
     $action->handle(['email' => $user->email]);
+
     $status = $action->handle(['email' => $user->email]);

     expect($status)->toBe(Password::RESET_THROTTLED);
    ----------- end diff -----------

Applied rules:
 * NewlineBeforeNewAssignSetRector


2) app/Models/User.php:45

    ---------- begin diff ----------
@@ @@
     /**
      * @return array<string, string>
      */
-    public function casts(): array
+    protected function casts(): array
     {
         return [
             'id' => 'integer',
    ----------- end diff -----------

Applied rules:
 * MakeInheritedMethodVisibilitySameAsParentRector

])
->withSkip([
AddOverrideAttributeToOverriddenMethodsRector::class,
SeparateMultiUseImportsRector::class,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule seems annoying. I don't know what you think.

* @return array<string, string>
*/
public function casts(): array
protected function casts(): array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conflicts with arch()->preset()->strict();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you already have any solution @prishan @thomasdail because composer lint make this protected, but this make arch test error

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I excluded protected method check from arch test for now.

// arch()->preset()->strict();
// Custom strict preset excluding protected methods check
arch('strict-without-protected')
    ->expect('App\\*')
    ->toUseStrictTypes()
    ->toUseStrictEquality();

arch('classes-should-be-final')
    ->expect('App\\*')
    ->classes()
    ->toBeFinal()
    ->not->toBeAbstract();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I have to choose, I prefer protected function because it is written in the official documentation, I don't want to go against the laravel convention

For flexibility (yes we can just extend the preset), I created a custom preset that I took from strict present, but I only ignore protected for the model.

<?php

declare(strict_types=1);

pest()->presets()->custom('laravelStrict', function (array $userNamespaces): array {
    $expectations = [];

    foreach ($userNamespaces as $namespace) {
        // Apply strict rules but exclude models from protected method check
        $expectations[] = expect($namespace)
            ->classes()
            ->not->toHaveProtectedMethods()
            ->ignoring('App\Models');

        $expectations[] = expect($namespace)->classes()->not->toBeAbstract();
        $expectations[] = expect($namespace)->toUseStrictTypes();
        $expectations[] = expect($namespace)->toUseStrictEquality();
        $expectations[] = expect($namespace)->classes()->toBeFinal();
    }

    // Add other global expectations
    $expectations[] = expect(['sleep', 'usleep'])->not->toBeUsed();

    return $expectations;
});

arch()->preset()->php();
// arch()->preset()->strict();
arch()->preset()->laravelStrict();
arch()->preset()->security()->ignoring([
    'assert',
]);

arch('controllers')
    ->expect('App\Http\Controllers')
    ->not->toBeUsed();

what do you think @nunomaduro ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the best long term solution is.
For the time being, I went ahead and skipped the rector rule that broke the architecture test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants