Completed
Push — master ( d16fc8...ddcbf1 )
by Thomas
02:51
created

CommentsFormatter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 53.33%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 26
ccs 8
cts 15
cp 0.5333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B doVisitToken() 0 17 5
A isComment() 0 5 4
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