Completed
Push — master ( 99f10a...f4bdff )
by Thomas
01:46
created

CommentsFormatter::doVisitToken()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 11.4436

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 4
cts 11
cp 0.3636
rs 9.3888
c 0
b 0
f 0
cc 5
nc 3
nop 1
crap 11.4436
1
<?php
2
namespace gossi\formatter\formatters;
3
4
use phootwork\tokenizer\Token;
5
6
class CommentsFormatter extends SpecializedFormatter {
7
8 2
	protected function doVisitToken(Token $token) {
9
		// multiline
10 2
		if ($token->type == T_DOC_COMMENT
11 2
				|| $token->type == T_INLINE_HTML && strpos($token->contents, '/*') !== 0) {
12
13
			$lines = explode("\n", $token->contents);
14
			$firstLine = array_shift($lines);
15
			$this->writer->writeln();
16
			$this->writer->writeln($firstLine);
17
18
			foreach ($lines as $line) {
19
				$this->writer->writeln(' ' . ltrim($line));
20
			}
21
22
			$this->defaultFormatter->hideToken();
23
		}
24 2
	}
25
26 5
	public static function isComment(Token $token) {
27 5
		return $token->type == T_DOC_COMMENT
28 5
				|| ($token->type == T_INLINE_HTML && strpos($token->contents, '/*') !== 0)
29 5
				|| $token->type == T_COMMENT;
30
	}
31
}
32