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

ReaderAwareTrait::withReader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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