- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24
Replace strictBooleans set with codingStyle set #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ]) | ||
| ->withSkip([ | ||
| AddOverrideAttributeToOverriddenMethodsRector::class, | ||
| SeparateMultiUseImportsRector::class, | 
There was a problem hiding this comment.
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.
        
          
                app/Models/User.php
              
                Outdated
          
        
      | * @return array<string, string> | ||
| */ | ||
| public function casts(): array | ||
| protected function casts(): array | 
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
strictBooleansis deprecatedstrictBooleansset with the codingStyle set. Some new rules were applied: