Total Complexity | 10 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | class GitignoreHandler extends BaseHandler |
||
17 | { |
||
18 | public $type = 'gitignore'; |
||
19 | |||
20 | public function parsePath($path, $minimal = null) |
||
21 | { |
||
22 | $items = []; |
||
23 | $lines = is_file($path) ? $this->readArray($path) : []; |
||
24 | $comment = ''; |
||
25 | foreach ($lines as $str) { |
||
26 | $str = trim($str); |
||
27 | if (!$str) { |
||
28 | continue; |
||
29 | } |
||
30 | if ($str[0] === '#') { |
||
31 | $comment = trim(substr($str, 1)); |
||
32 | } else { |
||
33 | $items[$str] = $comment; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return $items; |
||
38 | } |
||
39 | |||
40 | public function render($items) |
||
41 | { |
||
42 | $comments = []; |
||
43 | foreach ($items as $item => $comment) { |
||
44 | $comments[$comment][$item] = $item; |
||
45 | } |
||
46 | |||
47 | $res = ''; |
||
48 | foreach ($comments as $comment => $items) { |
||
|
|||
49 | ksort($items); |
||
50 | $res .= static::renderComment($comment) . implode("\n", $items) . "\n"; |
||
51 | } |
||
52 | |||
53 | return ltrim($res); |
||
54 | } |
||
55 | |||
56 | public static function renderComment($comment) |
||
59 | } |
||
60 | } |
||
61 |