Completed
Branch feature/pre-split (a521a3)
by Anton
03:28
created

CommentTrait::getComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Reactor\Traits;
9
10
use Spiral\Reactor\Body\DocComment;
11
12
/**
13
 * Element can have doc comment.
14
 */
15
trait CommentTrait
16
{
17
    /**
18
     * @var DocComment
19
     */
20
    private $docComment = null;
21
22
    /**
23
     * Get associated file comment.
24
     *
25
     * @return DocComment
26
     */
27
    public function getComment(): DocComment
28
    {
29
        return $this->docComment;
30
    }
31
32
    /**
33
     * Set comment value.
34
     *
35
     * @param string|array $comment
36
     *
37
     * @return $this
38
     */
39
    public function setComment($comment)
40
    {
41
        if (!empty($comment)) {
42
            if (is_array($comment)) {
43
                $this->docComment->setLines($comment);
44
            } elseif (is_string($comment)) {
45
                $this->docComment->setString($comment);
46
            }
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * Init comment value.
54
     *
55
     * @param string|array $comment
56
     */
57
    private function initComment($comment)
58
    {
59
        if (empty($this->docComment)) {
60
            $this->docComment = new DocComment();
61
        }
62
63
        $this->setComment($comment);
64
    }
65
}