PHP-CS-Fixer / PHP-CS-Fixer

A tool to automatically fix PHP Coding Standards issues
https://cs.symfony.com
MIT License
12.71k stars 1.57k forks source link

Apply `fully_qualified_strict_types` in annotations #3655

Open ostrolucky opened 6 years ago

ostrolucky commented 6 years ago

I would like to apply this fixer across annotations as well. Here's what I expect to fix

<?php

class SomeClass
{
    /** @Foo\Bar */
    private $foo;
}

into

<?php

use Foo\Bar;

class SomeClass
{
    /** @Bar */
    private $foo;
}

How do you think solution should look like? As far as I see, so far no fixer outside DoctrineAnnotation fixes annotations

julienfalque commented 6 years ago

:+1: though I think I would be better to have a dedicated fixer in the DoctrineAnnotation namespace.

Slamdunk commented 6 years ago

Already discussed in #3644

ostrolucky commented 6 years ago

Ah thanks for a link. Indeed, it would make sense to fix both cases (phpdoc param/return types and doctrine style classes prefixed with @).

ostrolucky commented 6 years ago

After looking at it some more, I have realized FullyQualifiedStrictTypesFixer does not do what I want anyway. It changes FCQNs to short versions only if class has been imported. My goal is to import the class if it hasn't been imported.

ostrolucky commented 6 years ago

For all of those who are looking for importing fcqn classes which were not imported, there are

SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff which does this For PHP-CS-Fixer, there is Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer

github-actions[bot] commented 8 months ago

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

mvorisek commented 6 months ago

I belive this was fixed by https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/5620

Wirone commented 6 months ago

@mvorisek no, #5620 was about phpDoc tags only (@tag \F\Q\C\N), not annotations (@F\Q\C\N).

keradus commented 6 months ago

btw, what is this /** @MyClass */ annotation usage?

mvorisek commented 6 months ago

"attributes defined in phpdoc"

/* @ORM\Column */ for example

https://packagist.org/packages/doctrine/annotations

keradus commented 6 months ago

I think Doctrine moved to attributes by now, if it's the only use case, maybe there is no big value of creating support for it.

Wirone commented 6 months ago

From doctrine/annotations:

⚠️ PHP 8 introduced attributes, which are a native replacement for annotations. As such, this library is considered feature complete, and should receive exclusively bugfixes and security fixes.

So it has limited support, but is not strictly deprecated. From our perspective it shouldn't be a priority IMHO, but if anyone is willing to contribute, then we can consider merging 😉.

mvorisek commented 6 months ago

with #7679 this can be easily implemented

github-actions[bot] commented 3 months ago

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

github-actions[bot] commented 1 week ago

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.