Passed
Pull Request — master (#405)
by Kirill
08:21 queued 04:03
created

ReaderAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 7
c 3
b 0
f 1
dl 0
loc 35
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setReader() 0 5 1
A withReader() 0 3 1
A getReader() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Attributes;
13
14
/**
15
 * @mixin ReaderAwareInterface
16
 */
17
trait ReaderAwareTrait
18
{
19
    /**
20
     * @var ReaderInterface|null
21
     */
22
    private $reader;
23
24
    /**
25
     * @param ReaderInterface $reader
26
     * @return $this|ReaderAwareInterface
27
     */
28
    public function withReader(ReaderInterface $reader): ReaderAwareInterface
29
    {
30
        return (clone $this)->setReader($reader);
31
    }
32
33
    /**
34
     * @return ReaderInterface
35
     */
36
    public function getReader(): ReaderInterface
37
    {
38
        assert($this->reader !== null, 'Invariant violation');
39
40
        return $this->reader;
41
    }
42
43
    /**
44
     * @param ReaderInterface $reader
45
     * @return $this|ReaderAwareInterface
46
     */
47
    protected function setReader(ReaderInterface $reader): ReaderAwareInterface
48
    {
49
        $this->reader = $reader;
50
51
        return $this;
52
    }
53
}
54