Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CommentTrait | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| addComment | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getComments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasComments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| removeComment | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| removeAllComments | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Css; |
| 16 | |
| 17 | /** |
| 18 | * CSS comment trait |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Css |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 3.0.0 |
| 26 | */ |
| 27 | trait CommentTrait |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Comments |
| 32 | * @var array |
| 33 | */ |
| 34 | protected array $comments = []; |
| 35 | |
| 36 | /** |
| 37 | * Add CSS comment |
| 38 | * |
| 39 | * @param Comment|string $comment |
| 40 | * @param int $wrap |
| 41 | * @param bool $trailingNewLine |
| 42 | * @return static |
| 43 | */ |
| 44 | public function addComment(Comment|string $comment, int $wrap = 80, bool $trailingNewLine = false): static |
| 45 | { |
| 46 | if (is_string($comment)) { |
| 47 | $comment = new Comment($comment, $wrap, $trailingNewLine); |
| 48 | } |
| 49 | $this->comments[] = $comment; |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get CSS comments |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function getComments(): array |
| 59 | { |
| 60 | return $this->comments; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Has CSS comments |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function hasComments(): bool |
| 69 | { |
| 70 | return !empty($this->comments); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Remove CSS comment by index |
| 75 | * |
| 76 | * @param int $i |
| 77 | * @return static |
| 78 | */ |
| 79 | public function removeComment(int $i): static |
| 80 | { |
| 81 | if (isset($this->comments[$i])) { |
| 82 | unset($this->comments[$i]); |
| 83 | $this->comments = array_values($this->comments); |
| 84 | } |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Remove all CSS comments |
| 90 | * |
| 91 | * @return static |
| 92 | */ |
| 93 | public function removeAllComments(): static |
| 94 | { |
| 95 | $this->comments = []; |
| 96 | return $this; |
| 97 | } |
| 98 | |
| 99 | } |