Passed
Pull Request — master (#662)
by Maxim
07:27
created

QueueableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 25
ccs 5
cts 9
cp 0.5556
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setReader() 0 5 1
A findQueueable() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Queue\Attribute;
6
7
use Spiral\Attributes\Factory;
8
use Spiral\Attributes\ReaderInterface;
9
10
trait QueueableTrait
11
{
12
    private ReaderInterface $reader;
13
14
    public function setReader(ReaderInterface $reader): self
15
    {
16
        $this->reader = $reader;
17
18
        return $this;
19
    }
20
21
    /**
22
     * @psalm-param class-string $class
23
     */
24 3
    public function findQueueable(string $class): ?Queueable
25
    {
26 3
        $this->reader ??= (new Factory())->create();
27
28 3
        $reflection = new \ReflectionClass($class);
29
30 3
        if ($reflection->isInterface()) {
31
            return null;
32
        }
33
34 3
        return $this->reader->firstClassMetadata($reflection, Queueable::class);
35
    }
36
}
37