PHPStorm and simplified annotations
By default when using Doctrine in a project, in particular entities, you may have to use annotations a lot, example:
/**
* @Entity
* @Table(name="user_accounts")
*/
class Account
{
/**
* @var int
* @Id
* @GeneratedValue(strategy="AUTO")
* @Column(name="user_id", type="integer")
*/
protected $id;
The issue however is that when using PHPStorm to add these, it will default to grouping them all under one namespace as such:
use Doctrine\\ORM\\Mapping as ORM;
/**
* @ORM\\Entity()
* @ORM\\Table(name="user_accounts")
*/
class Account
Which won't necessarily work out of the box. The reason for this is that when creating the annotations driver
$ormConfig->newDefaultAnnotationDriver([__DIR__.'/../src'])
there is actually a second argument set to true by default:
/**
* Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader
* is true, the notation `@Entity` will work, otherwise, the notation `@ORM\\Entity` will be supported.
*
* @param array $paths
* @param bool $useSimpleAnnotationReader
*
* @return AnnotationDriver
*/
public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true)
Setting this second flag to false when creating the driver should fix the issue:
$ormConfig->newDefaultAnnotationDriver([__DIR__.'/../src'], false)