|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PhpGenerator\Element; |
|
6
|
|
|
|
|
7
|
|
|
class PhpAnnotation extends AbstractElement |
|
8
|
|
|
{ |
|
9
|
|
|
public const NO_NAME = '__NO_NAME__'; |
|
10
|
|
|
|
|
11
|
|
|
public const MAX_LENGTH = 80; |
|
12
|
|
|
|
|
13
|
|
|
protected string $content; |
|
14
|
|
|
|
|
15
|
|
|
protected int $maxLength; |
|
16
|
|
|
|
|
17
|
66 |
|
public function __construct(string $name, string $content, int $maxLength = self::MAX_LENGTH) |
|
18
|
|
|
{ |
|
19
|
66 |
|
parent::__construct($name); |
|
20
|
|
|
$this |
|
21
|
66 |
|
->setContent($content) |
|
22
|
66 |
|
->setMaxLength($maxLength) |
|
23
|
|
|
; |
|
24
|
66 |
|
} |
|
25
|
|
|
|
|
26
|
66 |
|
public function setContent(string $content): self |
|
27
|
|
|
{ |
|
28
|
66 |
|
$this->content = trim($content); |
|
29
|
|
|
|
|
30
|
66 |
|
return $this; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
50 |
|
public function getContent(): string |
|
34
|
|
|
{ |
|
35
|
50 |
|
return $this->content; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
public function hasContent(): bool |
|
39
|
|
|
{ |
|
40
|
2 |
|
return !empty($this->content); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
50 |
|
public function getPhpName(): string |
|
44
|
|
|
{ |
|
45
|
50 |
|
return (!empty($this->name) && $this->getName() !== static::NO_NAME) ? sprintf(' @%s', parent::getPhpName()) : ''; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
50 |
|
public function getPhpDeclaration(): string |
|
49
|
|
|
{ |
|
50
|
50 |
|
return sprintf(' *%s', implode(sprintf('%s *', parent::BREAK_LINE_CHAR), $this->getPhpContent())); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
public function getChildrenTypes(): array |
|
54
|
|
|
{ |
|
55
|
2 |
|
return []; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
66 |
|
public function setMaxLength(int $maxlength): self |
|
59
|
|
|
{ |
|
60
|
66 |
|
$this->maxLength = $maxlength; |
|
61
|
|
|
|
|
62
|
66 |
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
36 |
|
public function getMaxLength(): int |
|
66
|
|
|
{ |
|
67
|
36 |
|
return $this->maxLength; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
50 |
|
protected function getPhpContent(): array |
|
71
|
|
|
{ |
|
72
|
50 |
|
$fullContent = trim(sprintf('%s %s', $this->getPhpName(), $this->getContent())); |
|
73
|
25 |
|
$content = [ |
|
74
|
50 |
|
$fullContent, |
|
75
|
|
|
]; |
|
76
|
50 |
|
if ('' === $this->getPhpName() && strlen($fullContent) > $this->getMaxLength()) { |
|
77
|
10 |
|
$content = explode(self::BREAK_LINE_CHAR, wordwrap($fullContent, $this->getMaxLength(), self::BREAK_LINE_CHAR, true)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
50 |
|
return array_map(function ($element) { |
|
81
|
50 |
|
return sprintf(' %s', $element); |
|
82
|
50 |
|
}, $content); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|