1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Plantuml\TokenReflection; |
4
|
|
|
|
5
|
|
|
use TokenReflection\IReflectionClass; |
6
|
|
|
|
7
|
|
|
abstract class WriterAbstract |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param Flagbit\Plantuml\TokenReflection\WriterOptions $writerOptions |
12
|
|
|
*/ |
13
|
13 |
|
public function __construct(WriterOptions $writerOptions=null) |
14
|
|
|
{ |
15
|
13 |
|
if (!is_null($writerOptions)) { |
16
|
13 |
|
$this->writerOptions = $writerOptions; |
|
|
|
|
17
|
13 |
|
} else { |
18
|
13 |
|
$this->writerOptions = new WriterOptions(); |
|
|
|
|
19
|
|
|
} |
20
|
13 |
|
} |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $indent = ' '; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $linebreak = "\n"; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Flagbit\Plantuml\TokenReflection\WriterOptions |
33
|
|
|
*/ |
34
|
|
|
protected $writerOptions = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $indent |
38
|
|
|
*/ |
39
|
13 |
|
protected function setIndent($indent = ' ') |
40
|
|
|
{ |
41
|
13 |
|
$this->indent = (string) $indent; |
42
|
13 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $string |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
13 |
|
public function formatLine($string) |
49
|
|
|
{ |
50
|
13 |
|
return $this->indent . $string . $this->linebreak; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param \TokenReflection\IReflectionClass $declaringClass The class using the namespace aliases |
55
|
|
|
* @param string $aliasedClassName The class name used in the declaring class |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
6 |
|
protected function expandNamespaceAlias(IReflectionClass $declaringClass, $aliasedClassName) |
59
|
|
|
{ |
60
|
6 |
|
$aliasedClassName = trim($aliasedClassName); |
61
|
6 |
|
foreach ($declaringClass->getNamespaceAliases() as $namespaceAlias) { |
62
|
|
|
if (1 === preg_match('/\\\\' . preg_quote($aliasedClassName) . '$/', $namespaceAlias)) { |
63
|
|
|
$aliasedClassName = $namespaceAlias; |
64
|
|
|
break; |
65
|
|
|
} |
66
|
6 |
|
} |
67
|
6 |
|
return $aliasedClassName; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $className |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
13 |
|
protected function formatClassName($className) |
75
|
|
|
{ |
76
|
13 |
|
$className = str_replace('\\', '.', trim($className)); |
77
|
13 |
|
if ('.' === $className[0]) { |
78
|
|
|
$className = substr($className, 1); |
79
|
|
|
} |
80
|
13 |
|
return $className; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param mixed $value |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
6 |
|
protected function formatValue($value) |
88
|
|
|
{ |
89
|
6 |
|
if (is_null($value)) { |
90
|
|
|
$value = 'null'; |
91
|
|
|
} |
92
|
6 |
|
else if (is_array($value)) { |
93
|
1 |
|
$formattedValues = array(); |
94
|
1 |
|
foreach ($value as $currentValue) { |
95
|
1 |
|
$formattedValues[] = $this->formatValue($currentValue); |
96
|
1 |
|
} |
97
|
1 |
|
$value = '[' .implode(', ', $formattedValues) . ']'; |
98
|
1 |
|
} |
99
|
6 |
|
else if (is_numeric($value)) { |
100
|
|
|
// nothing to do here |
101
|
4 |
|
} |
102
|
6 |
|
else if (is_bool($value)) { |
103
|
4 |
|
$value = $value ? 'true' : 'false'; |
104
|
4 |
|
} |
105
|
|
|
else { |
106
|
|
|
// make sure we receive two backslashes in the output as |
107
|
|
|
// plantuml needs them escaped as well |
108
|
5 |
|
$value = strtr($value, array( |
|
|
|
|
109
|
5 |
|
"\n" => '\\\\n', |
110
|
5 |
|
"\r" => '\\\\r', |
111
|
5 |
|
"\t" => '\\\\t', |
112
|
5 |
|
)); |
113
|
5 |
|
$value = '"' . $value . '"'; |
114
|
|
|
} |
115
|
6 |
|
return $value; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..