Completed
Push — master ( 9086d9...713b15 )
by Thomas
07:07
created

PhpConstant::generateDocblock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
namespace gossi\codegen\model;
3
4
use gossi\codegen\model\parts\DocblockPart;
5
use gossi\codegen\model\parts\LongDescriptionPart;
6
use gossi\codegen\model\parts\NamePart;
7
use gossi\codegen\model\parts\TypeDocblockGeneratorPart;
8
use gossi\codegen\model\parts\TypePart;
9
use gossi\codegen\model\parts\ValuePart;
10
use gossi\docblock\Docblock;
11
use gossi\docblock\tags\VarTag;
12
13
/**
14
 * Represents a PHP constant.
15
 *
16
 * @author Thomas Gossmann
17
 */
18
class PhpConstant extends AbstractModel implements GenerateableInterface, DocblockInterface {
19
20
	use DocblockPart;
21
	use LongDescriptionPart;
22
	use NamePart;
23
	use TypeDocblockGeneratorPart;
24
	use TypePart;
25
	use ValuePart;
26
27
	/**
28
	 * Creates a new PHP constant
29
	 *
30
	 * @param string $name
31
	 * @param mixed $value
32
	 * @return static
33
	 */
34 5
	public static function create($name = null, $value = null) {
35 5
		$constant = new static();
36 5
		$constant->setName($name);
37
38 5
		if (is_string($value)) {
39 1
			$constant->setValue($value);
40 1
		} else {
41 4
			$constant->setExpression($value);
42
		}
43
44 5
		return $constant;
45
	}
46
47
	/**
48
	 * Creates a new PHP constant
49
	 *
50
	 * @param string $name
51
	 * @param mixed $value
52
	 */
53 13
	public function __construct($name = null, $value = null) {
54 13
		$this->setName($name);
55
56 13
		if (is_string($value)) {
57 1
			$this->setValue($value);
58 1
		} else {
59 13
			$this->setExpression($value);
60
		}
61 13
		$this->docblock = new Docblock();
62 13
	}
63
64
	/**
65
	 * @inheritDoc
66
	 */
67 6
	public function generateDocblock() {
68 6
		$docblock = $this->getDocblock();
69 6
		$docblock->setShortDescription($this->getDescription());
70 6
		$docblock->setLongDescription($this->getLongDescription());
71
72
		// var tag
73 6
		$this->generateTypeTag(new VarTag());
74 6
	}
75
}
76