|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TemplesOfCode\CodeSanity\Output; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use TemplesOfCode\CodeSanity\DiffItem; |
|
7
|
|
|
use TemplesOfCode\CodeSanity\Output; |
|
8
|
|
|
use TemplesOfCode\CodeSanity\RosterItem; |
|
9
|
|
|
|
|
10
|
|
|
class PrettyOutput extends Output |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected static $maskTemplate = '| %%-%d.%ds | %%-%d.%ds | %%-%d.%ds | %%-%d.%ds |'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $fileNameSpaceLength = 30; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $hashSpaceLength = 40; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $border; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function init() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setBorder(); |
|
38
|
|
|
$this->setMask(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function setBorder() |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* Initial constant lengths |
|
48
|
|
|
* @var int $borderLength |
|
49
|
|
|
*/ |
|
50
|
|
|
$borderLength = 13; |
|
51
|
|
|
$borderLength = $borderLength |
|
52
|
|
|
+ ($this->fileNameSpaceLength * 2) |
|
53
|
|
|
+ ($this->hashSpaceLength * 2) |
|
54
|
|
|
; |
|
55
|
|
|
|
|
56
|
|
|
$this->border = str_repeat('-', $borderLength); |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function setMask() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->mask = sprintf( |
|
66
|
|
|
static::$maskTemplate, |
|
67
|
|
|
$this->getFileNameSpaceLength(), |
|
68
|
|
|
$this->getFileNameSpaceLength(), |
|
69
|
|
|
$this->getHashSpaceLength(), |
|
70
|
|
|
$this->getHashSpaceLength(), |
|
71
|
|
|
$this->getFileNameSpaceLength(), |
|
72
|
|
|
$this->getFileNameSpaceLength(), |
|
73
|
|
|
$this->getHashSpaceLength(), |
|
74
|
|
|
$this->getHashSpaceLength() |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return int |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getFileNameSpaceLength() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->fileNameSpaceLength; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param int $fileNameSpaceLength |
|
88
|
|
|
* @return PrettyOutput |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setFileNameSpaceLength($fileNameSpaceLength) |
|
91
|
|
|
{ |
|
92
|
|
|
if ($fileNameSpaceLength == $this->fileNameSpaceLength) { |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->fileNameSpaceLength = $fileNameSpaceLength; |
|
97
|
|
|
|
|
98
|
|
|
$this->setBorder(); |
|
99
|
|
|
$this->setMask(); |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return int |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getHashSpaceLength() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->hashSpaceLength; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param int $hashSpaceLength |
|
114
|
|
|
* @return PrettyOutput |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setHashSpaceLength($hashSpaceLength) |
|
117
|
|
|
{ |
|
118
|
|
|
if ($hashSpaceLength == $this->hashSpaceLength) { |
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$this->hashSpaceLength = $hashSpaceLength; |
|
123
|
|
|
|
|
124
|
|
|
$this->setBorder(); |
|
125
|
|
|
$this->setMask(); |
|
126
|
|
|
|
|
127
|
|
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* |
|
132
|
|
|
*/ |
|
133
|
|
|
public function write() |
|
134
|
|
|
{ |
|
135
|
|
|
if ($this->headerEnabled) { |
|
136
|
|
|
$this->writeHeader(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$this->output->writeln($this->border); |
|
140
|
|
|
|
|
141
|
|
|
foreach ($this->differences as $differenceSet) { |
|
142
|
|
|
/** |
|
143
|
|
|
* @var ArrayCollection<DiffItem> $differenceSet |
|
|
|
|
|
|
144
|
|
|
*/ |
|
145
|
|
|
$this->writeDifferenceSet($differenceSet); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$this->output->writeln($this->border); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param ArrayCollection $differenceSet |
|
153
|
|
|
*/ |
|
154
|
|
|
private function writeDifferenceSet(ArrayCollection $differenceSet) |
|
155
|
|
|
{ |
|
156
|
|
|
foreach ($differenceSet as $diffItem) { |
|
157
|
|
|
/** |
|
158
|
|
|
* @var DiffItem $diffItem |
|
159
|
|
|
*/ |
|
160
|
|
|
$this->writeDiffItem($diffItem); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* |
|
166
|
|
|
*/ |
|
167
|
|
|
private function writeHeader() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->output->writeln($this->border); |
|
170
|
|
|
$this->output->writeln(sprintf( |
|
171
|
|
|
$this->getMask(), |
|
172
|
|
|
static::$header[0], |
|
173
|
|
|
static::$header[1], |
|
174
|
|
|
static::$header[2], |
|
175
|
|
|
static::$header[3] |
|
176
|
|
|
)); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.