Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
6 / 10 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Images | |
60.00% |
6 / 10 |
|
83.33% |
5 / 6 |
16.40 | |
0.00% |
0 / 1 |
| __toString | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| current | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| first | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ratio | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
4 | |||
| crop | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Value; |
| 6 | |
| 7 | use Override; |
| 8 | |
| 9 | class Images extends Files |
| 10 | { |
| 11 | #[Override] |
| 12 | public function __toString(): string |
| 13 | { |
| 14 | $out = ''; |
| 15 | |
| 16 | for ($i = 0; $i < count($this->files()); $i++) { |
| 17 | $out .= (string) $this->get($i); |
| 18 | } |
| 19 | |
| 20 | return $out; |
| 21 | } |
| 22 | |
| 23 | #[Override] |
| 24 | public function current(): Image |
| 25 | { |
| 26 | return $this->get($this->pointer); |
| 27 | } |
| 28 | |
| 29 | #[Override] |
| 30 | public function get(int $index): Image |
| 31 | { |
| 32 | return new Image($this->owner, $this->field, $this->context, $index); |
| 33 | } |
| 34 | |
| 35 | #[Override] |
| 36 | public function first(): Image |
| 37 | { |
| 38 | return new Image($this->owner, $this->field, $this->context, 0); |
| 39 | } |
| 40 | |
| 41 | /** The gallery tiles' aspect ratio, such as `4/3`; `null` keeps each image's own. */ |
| 42 | public function ratio(): ?string |
| 43 | { |
| 44 | $ratio = $this->meta('ratio'); |
| 45 | |
| 46 | return is_string($ratio) && $ratio !== '' && $ratio !== 'auto' ? $ratio : null; |
| 47 | } |
| 48 | |
| 49 | /** Whether the gallery tiles crop to their ratio instead of fitting into it. */ |
| 50 | public function crop(): bool |
| 51 | { |
| 52 | return (bool) $this->meta('crop', false); |
| 53 | } |
| 54 | } |