Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| Style | |
100.00% |
24 / 24 |
|
100.00% |
14 / 14 |
17 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setFont | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFont | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasFont | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setColor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasColor | |
100.00% |
1 / 1 |
|
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\Pdf\Document; |
| 16 | |
| 17 | use Pop\Color\Color\ColorInterface; |
| 18 | |
| 19 | /** |
| 20 | * Pdf style class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Pdf |
| 24 | * @author Nick Sagona, III <nick@popphp.org> |
| 25 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 6.2.0 |
| 28 | */ |
| 29 | class Style |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * Style name |
| 34 | * @var ?string |
| 35 | */ |
| 36 | protected ?string $name = null; |
| 37 | |
| 38 | /** |
| 39 | * Style font |
| 40 | * @var ?string |
| 41 | */ |
| 42 | protected ?string $font = null; |
| 43 | |
| 44 | /** |
| 45 | * Style size |
| 46 | * @var int|float|null |
| 47 | */ |
| 48 | protected int|float|null $size = null; |
| 49 | |
| 50 | /** |
| 51 | * Style color |
| 52 | * @var ?ColorInterface |
| 53 | */ |
| 54 | protected ?ColorInterface $color = null; |
| 55 | |
| 56 | /** |
| 57 | * Constructor |
| 58 | * |
| 59 | * Instantiate a PDF style. |
| 60 | * |
| 61 | * @param string $name |
| 62 | * @param ?string $font |
| 63 | * @param int|float|null $size |
| 64 | * @param ?ColorInterface $color |
| 65 | */ |
| 66 | public function __construct( |
| 67 | string $name, ?string $font = null, int|float|null $size = null, ?ColorInterface $color = null |
| 68 | ) |
| 69 | { |
| 70 | $this->setName($name); |
| 71 | if ($font !== null) { |
| 72 | $this->setFont($font); |
| 73 | } |
| 74 | if ($size !== null) { |
| 75 | $this->setSize($size); |
| 76 | } |
| 77 | if ($color !== null) { |
| 78 | $this->setColor($color); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Create style object |
| 84 | * |
| 85 | * @param string $name |
| 86 | * @param ?string $font |
| 87 | * @param int|float|null $size |
| 88 | * @param ?ColorInterface $color |
| 89 | * @return Style |
| 90 | */ |
| 91 | public static function create( |
| 92 | string $name, ?string $font = null, int|float|null $size = null, ?ColorInterface $color = null |
| 93 | ): Style |
| 94 | { |
| 95 | return new self($name, $font, $size, $color); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Set name |
| 100 | * |
| 101 | * @param string $name |
| 102 | * @return Style |
| 103 | */ |
| 104 | public function setName(string $name): Style |
| 105 | { |
| 106 | $this->name = $name; |
| 107 | return $this; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get name |
| 112 | * |
| 113 | * @return ?string |
| 114 | */ |
| 115 | public function getName(): ?string |
| 116 | { |
| 117 | return $this->name; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Has name |
| 122 | * |
| 123 | * @return bool |
| 124 | */ |
| 125 | public function hasName(): bool |
| 126 | { |
| 127 | return ($this->name !== null); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Set font |
| 132 | * |
| 133 | * @param string $font |
| 134 | * @return Style |
| 135 | */ |
| 136 | public function setFont(string $font): Style |
| 137 | { |
| 138 | $this->font = $font; |
| 139 | return $this; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Get font |
| 144 | * |
| 145 | * @return ?string |
| 146 | */ |
| 147 | public function getFont(): ?string |
| 148 | { |
| 149 | return $this->font; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Has font |
| 154 | * |
| 155 | * @return bool |
| 156 | */ |
| 157 | public function hasFont(): bool |
| 158 | { |
| 159 | return ($this->font !== null); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Set size |
| 164 | * |
| 165 | * @param int|float $size |
| 166 | * @return Style |
| 167 | */ |
| 168 | public function setSize(int|float $size): Style |
| 169 | { |
| 170 | $this->size = $size; |
| 171 | return $this; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get size |
| 176 | * |
| 177 | * @return int|float|null |
| 178 | */ |
| 179 | public function getSize(): int|float|null |
| 180 | { |
| 181 | return $this->size; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Has size |
| 186 | * |
| 187 | * @return bool |
| 188 | */ |
| 189 | public function hasSize(): bool |
| 190 | { |
| 191 | return ($this->size !== null); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Set color |
| 196 | * |
| 197 | * @param ColorInterface $color |
| 198 | * @return Style |
| 199 | */ |
| 200 | public function setColor(ColorInterface $color): Style |
| 201 | { |
| 202 | $this->color = $color; |
| 203 | return $this; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Get color |
| 208 | * |
| 209 | * @return ?ColorInterface |
| 210 | */ |
| 211 | public function getColor(): ?ColorInterface |
| 212 | { |
| 213 | return $this->color; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Has color |
| 218 | * |
| 219 | * @return bool |
| 220 | */ |
| 221 | public function hasColor(): bool |
| 222 | { |
| 223 | return ($this->color !== null); |
| 224 | } |
| 225 | |
| 226 | } |