Passed
Push — master ( 5545f1...83deac )
by Kirill
03:22
created

CommentTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initComment() 0 7 2
A getComment() 0 3 1
A setComment() 0 11 4
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Reactor\Traits;
13
14
use Spiral\Reactor\Partial\Comment;
15
16
/**
17
 * Element can have doc comment.
18
 */
19
trait CommentTrait
20
{
21
    /**
22
     * @var Comment
23
     */
24
    private $docComment;
25
26
    /**
27
     * Get associated file comment.
28
     *
29
     * @return Comment
30
     */
31
    public function getComment(): Comment
32
    {
33
        return $this->docComment;
34
    }
35
36
    /**
37
     * Set comment value.
38
     *
39
     * @param string|array $comment
40
     *
41
     * @return $this
42
     */
43
    public function setComment($comment): self
44
    {
45
        if (!empty($comment)) {
46
            if (is_array($comment)) {
47
                $this->docComment->setLines($comment);
48
            } elseif (is_string($comment)) {
0 ignored issues
show
introduced by
The condition is_string($comment) is always true.
Loading history...
49
                $this->docComment->setString($comment);
50
            }
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * Init comment value.
58
     *
59
     * @param string|array $comment
60
     */
61
    private function initComment($comment): void
62
    {
63
        if (empty($this->docComment)) {
64
            $this->docComment = new Comment();
65
        }
66
67
        $this->setComment($comment);
68
    }
69
}
70