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