Repository: DamienHarper/auditor (php)

Issue:
In master, PHP8 must use PHP8-style annotations instead of old-school /** ORM\Entity */ style
| Q                    | A
| ---------------------| -----------------------
| `auditor` version    | dev-master 19d5c11
| PHP version          | 8.0.13
| Database             | MariaDB

#### Summary

When #40 introduced PHP8 annotations, it still used `$this->reader->getClassAnnotation` if there weren't any Entity attributes.
```php
        if (\PHP_VERSION_ID >= 80000 && $attributes = $reflection->getAttributes(Entity::class)) {
            $annotation = $attributes[0]->newInstance();
        } else {
            $annotation = $this->reader->getClassAnnotation($reflection, Entity::class);
        }
```

In [#72](https://github.com/DamienHarper/auditor/pull/72/files#diff-e1cb1727d66518eb076a68bc9899bdb0edb1ce5346e1f89d8b4b75a5ba5aa437), this changed so that on PHP8, it will always use the `if` block rather than the `else` block.

```php
        if (\PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes')) {
            $attributes = $reflection->getAttributes(Entity::class);
            $annotation = \count($attributes) > 0 ? $attributes[0]->newInstance() : null;
        } elseif (null !== $this->reader) {
            $annotation = $this->reader->getClassAnnotation($reflection, Entity::class);
        }
```

Same deal obviously with the other annotation checks for Auditable and Security

#### How to reproduce

```php
/**
 * @ORM\Entity(repositoryClass="App\Repository\InventoryRepository")
 * @Audit\Auditable
 */
class Inventory
{
  // ...
}
```
doesn't recognize the class as Auditable

If I add the PHP8-style attributes then it does recognize it
```php
#[
    ORM\Entity(repositoryClass: InventoryRepository::class),
    Audit\Auditable
]
```

#### Expected behavior

Even with PHP8, old-style annotations are still recognized

Pull request description:
Annotation loader fix (PHP 8.x)
Brings back PHP 8.x attributes. Fixes #76

Patch:
diff --git a/src/Provider/Doctrine/Auditing/Annotation/AnnotationLoader.php b/src/Provider/Doctrine/Auditing/Annotation/AnnotationLoader.php
index 98f0c18..bc1a188 100644
--- a/src/Provider/Doctrine/Auditing/Annotation/AnnotationLoader.php
+++ b/src/Provider/Doctrine/Auditing/Annotation/AnnotationLoader.php
@@ -45,9 +45,9 @@ class AnnotationLoader
         $reflection = $metadata->getReflectionClass();
 
         // Check that we have an Entity annotation
-        if (\PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes')) {
-            $attributes = $reflection->getAttributes(Entity::class);
-            $annotation = \count($attributes) > 0 ? $attributes[0]->newInstance() : null;
+        $attributes = \PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes') ? $reflection->getAttributes(Entity::class) : null;
+        if (\is_array($attributes) && \count($attributes) > 0) {
+            $annotation = $attributes[0]->newInstance();
         } elseif (null !== $this->reader) {
             $annotation = $this->reader->getClassAnnotation($reflection, Entity::class);
         }
@@ -57,9 +57,9 @@ class AnnotationLoader
         }
 
         // Check that we have an Auditable annotation
-        if (\PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes')) {
-            $attributes = $reflection->getAttributes(Auditable::class);
-            $auditableAnnotation = \count($attributes) > 0 ? $attributes[0]->newInstance() : null;
+        $attributes = \PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes') ? $reflection->getAttributes(Auditable::class) : null;
+        if (\is_array($attributes) && \count($attributes) > 0) {
+            $auditableAnnotation = $attributes[0]->newInstance();
         } elseif (null !== $this->reader) {
             $auditableAnnotation = $this->reader->getClassAnnotation($reflection, Auditable::class);
         }
@@ -68,10 +68,10 @@ class AnnotationLoader
             return null;
         }
 
-        // Check that we have an Security annotation
-        if (\PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes')) {
-            $attributes = $reflection->getAttributes(Security::class);
-            $securityAnnotation = \count($attributes) > 0 ? $attributes[0]->newInstance() : null;
+        // Check that we have a Security annotation
+        $attributes = \PHP_VERSION_ID >= 80000 && method_exists($reflection, 'getAttributes') ? $reflection->getAttributes(Security::class) : null;
+        if (\is_array($attributes) && \count($attributes) > 0) {
+            $securityAnnotation = $attributes[0]->newInstance();
         } elseif (null !== $this->reader) {
             $securityAnnotation = $this->reader->getClassAnnotation($reflection, Security::class);
         }
diff --git a/src/Provider/Doctrine/Auditing/Annotation/Ignore.php b/src/Provider/Doctrine/Auditing/Annotation/Ignore.php
index ec39af5..9094f1c 100644
--- a/src/Provider/Doctrine/Auditing/Annotation/Ignore.php
+++ b/src/Provider/Doctrine/Auditing/Annotation/Ignore.php
@@ -9,7 +9,6 @@ use Doctrine\Common\Annotations\Annotation;
 
 /**
  * @Annotation
- *
  * @Target("PROPERTY")
  */
 #[Attribute(Attribute::TARGET_PROPERTY)]


Test patch:
diff --git a/tests/Provider/Doctrine/Traits/EntityManagerInterfaceTrait.php b/tests/Provider/Doctrine/Traits/EntityManagerInterfaceTrait.php
index b5047fb..251614d 100644
--- a/tests/Provider/Doctrine/Traits/EntityManagerInterfaceTrait.php
+++ b/tests/Provider/Doctrine/Traits/EntityManagerInterfaceTrait.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace DH\Auditor\Tests\Provider\Doctrine\Traits;
 
+use Doctrine\Common\Annotations\Annotation;
 use Doctrine\ORM\EntityManager;
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\ORM\Tools\Setup;
@@ -28,6 +29,7 @@ trait EntityManagerInterfaceTrait
             false
         );
 
+        class_exists(Annotation::class, true);
         DoctrineExtensions::registerAnnotations();
 
         $connection = $this->getConnection($connectionName, $params);