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

[Bug] Unused use and doctrine annotation #3941

Closed
tristanbes opened this issue Jul 23, 2018 · 5 comments
Closed

[Bug] Unused use and doctrine annotation #3941

tristanbes opened this issue Jul 23, 2018 · 5 comments
Assignees
Labels
topic/phpdoc PHPDoc tags, Doctrine Annotations etc.

Comments

@tristanbes
Copy link

tristanbes commented Jul 23, 2018

When having a class A using a trait B, in this trait, it's using another trait C relying on @Gedmo annotation.

The use is detected as "not used" and thus, removed causing the application to crash.

PS: doctrine/annotations is v1.6.0 and tried 1.6.x-dev because read that old version of doctrine/annotations can cause this (#729)

After:

(1/1) AnnotationException
[Semantical Error] The annotation "@Gedmo\Timestampable" in property Yprox\Model\Site::$createdAt was never imported. Did you maybe forget to add a "use" statement for this annotation?

The PHP version you are using ($ php -v):

7.2.7

PHP CS Fixer version you are using ($ php-cs-fixer -V):

v2.12.2

The command you use to run PHP CS Fixer:

php-cs-fixer fix

The configuration file you are using, if any:

<?php

$finder = PhpCsFixer\Finder::create()
    ->in([__DIR__.'/src'])
    ->exclude(['Tests'])
;

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules([
        '@Symfony' => true,
        'no_unused_imports' => true,
        'array_syntax' => [
            'syntax' => 'short',
        ],
        'binary_operator_spaces' => [
            'align_double_arrow' => true,
            'align_equals' => true
        ],
        'no_unreachable_default_argument_value' => false,
        'braces' => [
            'allow_single_line_closure' => true,
        ],
        'heredoc_to_nowdoc' => false,
        'phpdoc_summary' => false,
        'yoda_style' => false,
        'native_constant_invocation' => true,
        'native_function_invocation' => [
            'include' => ['@compiler_optimized'],
            'scope'   => 'namespaced',
        ],
        'no_superfluous_phpdoc_tags' => true,
    ])
    ->setFinder($finder)
;

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
namespace Yprox\Model;

use Gedmo\Mapping\Annotation as Gedmo;
...

/**
 * @ORM\Entity(repositoryClass=SiteRepository::class)
 * @ORM\Table(name="site", indexes={@ORM\Index(name="host_idx", columns={"host"})})
 * @UniqueEntity("host")
 * @UniqueEntity("zohoPlanCode")
 */
class Site implements ThemeOwnerInterface, LockableInterface
{
    use Translatable;
    use InheritableEntity;
} 
namespace Yprox\Model\Site\Ancestor;

use Doctrine\ORM\Mapping as ORM;
use Yprox\Traits\TimestampableEntity;

trait InheritableEntity
{
    use TimestampableEntity;
} 
namespace Yprox\Traits;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

trait TimestampableEntity
{
    /**
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime", name="created_at")
     */
    protected $createdAt;

    /**
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(type="datetime", name="updated_at")
     */
    protected $updatedAt;
  • with unexpected changes applied when running PHP CS Fixer:
namespace Yprox\Model;

/**
 * @ORM\Entity(repositoryClass=SiteRepository::class)
 * @ORM\Table(name="site", indexes={@ORM\Index(name="host_idx", columns={"host"})})
 * @UniqueEntity("host")
 * @UniqueEntity("zohoPlanCode")
 */
class Site implements ThemeOwnerInterface, LockableInterface
{
    use Translatable;
    use InheritableEntity;
}
  • with the changes you expected instead:
no changes
@tristanbes tristanbes changed the title False positive : Unused use and doctrine annotation [Bug] Unused use and doctrine annotation Jul 25, 2018
@SpacePossum SpacePossum added the topic/phpdoc PHPDoc tags, Doctrine Annotations etc. label Jul 30, 2018
@SpacePossum
Copy link
Contributor

Hi and thanks for reporting @tristanbes ,

I'm not 100% sure we can fix this in a easy way, but I like to hear @julienfalque on this topic :)
(maybe importing the annotation in the traits and not in the entity class would work?)

@tristanbes
Copy link
Author

Nope, importing the annotation in the traits and not in the entity class is not working. I tried that :D

@julienfalque
Copy link
Member

IMO PHP CS Fixer is right about removing the use statement. In #729 the discussion mentions that not handling the one in the trait itself was a bug in doctrine/annotation that should have been fixed. If not, I'd suggest opening a new issue on the related repository.

@PowerKiKi
Copy link

For future reference there is an opened issue in doctrine for this: doctrine/annotations#81

@Wirone Wirone added the status/to verify issue needs to be confirmed or analysed to continue label May 16, 2023
@Wirone
Copy link
Member

Wirone commented Jun 22, 2023

I am going to close this, since it is (was?) a bug in upstream package and Fixer's behavior was (is?) correct, as @julienfalque stated above.

@Wirone Wirone closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2023
@Wirone Wirone removed the status/to verify issue needs to be confirmed or analysed to continue label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/phpdoc PHPDoc tags, Doctrine Annotations etc.
Projects
None yet
Development

No branches or pull requests

5 participants