Skip to content
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

fix: FQCN rules after PHP-CS-Fixer updates #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stickeepaul
Copy link
Collaborator

@stickeepaul stickeepaul commented Jan 4, 2024

After some recent updates to PHP CS Fixer we noticed changes happening that we don't want like:

- @return \App\Carbon
+ @return Carbon

so this PR updates the baseline rules to revert back to what we had before.

Specifics

'global_namespace_import' => [
    'import_classes' => false,
    'import_constants' => false,
    'import_functions' => false
],

tells the global_namespace_import rule not to import global namespaced classes.

'fully_qualified_strict_types' => [
    'import_symbols' => true,
    'phpdoc_tags' => [
        // 'param',
        'phpstan-param',
        'phpstan-property',
        'phpstan-property-read',
        'phpstan-property-write',
        'phpstan-return',
        'phpstan-var',
        'property',
        'property-read',
        'property-write',
        'psalm-param',
        'psalm-property',
        'psalm-property-read',
        'psalm-property-write',
        'psalm-return',
        'psalm-var',
        // 'return',
        // 'see',
        // 'throws',
        // 'var'
    ]
],

tells the fully_qualified_strict_types rule to prefer importing namespaces except for the PHPDoc tags that have been commented out.

This means that we can have:

use App\Example; // imported namespace for class that is actually used in the file

/**
* Example
*
* @return \App\Example // FQCN in docblock for class that is not necessarily used in the file
*/
public function method(Example $example): Example // has had namespace imported so can be the short version

@stickeepaul
Copy link
Collaborator Author

this PR resulted in some incorrect changes to Nova resources:

+ use App\Models\Example; // imported but now no longer used
+
class Example extends Resource
{
/**
    * The model the resource corresponds to.
    *
    * @var string
    */
- public static string $model = ExampleModel::class;
+ public static string $model = self::class // wrong Example class

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

Successfully merging this pull request may close these issues.

None yet

1 participant