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

QueueableTrait::setReader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
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