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

CommentTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initComment() 0 8 2
A setComment() 0 12 4
A getComment() 0 4 1
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
}