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 (https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/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?
$ php -v):7.2.7
$ php-cs-fixer -V):v2.12.2
php-cs-fixer fix
<?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)
;
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;
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;
}
no changes
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?)
Nope, importing the annotation in the traits and not in the entity class is not working. I tried that :D
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.
For future reference there is an opened issue in doctrine for this: https://github.com/doctrine/annotations/issues/81
Most helpful comment
For future reference there is an opened issue in doctrine for this: https://github.com/doctrine/annotations/issues/81