Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Youtube
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 __toString
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
3
 unwrap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 json
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Value;
6
7use function Cosray\escape;
8
9class Youtube extends Value
10{
11    public function __toString(): string
12    {
13        $x = (float) ($this->meta('aspectRatioX', 16) ?: 16);
14        $y = (float) ($this->meta('aspectRatioY', 9) ?: 9);
15        $percent = number_format(($y / $x) * 100, 2, '.', '');
16        $iframeStyle = 'position: absolute; top: 0; left: 0; width: 100%; height: 100%';
17
18        return (
19            '<div class="youtube-container">'
20                . '<div style="position: relative; padding-top: '
21                . $percent
22                . '%">'
23                . '<iframe class="youtube" style="'
24                . $iframeStyle
25                . '" '
26                . 'src="https://www.youtube.com/embed/'
27                . escape((string) $this->unwrap())
28                . '" allowfullscreen></iframe>'
29                . '</div></div>'
30        );
31    }
32
33    public function unwrap(): mixed
34    {
35        return $this->value();
36    }
37
38    public function json(): mixed
39    {
40        return $this->unwrap();
41    }
42
43    public function isset(): bool
44    {
45        return is_string($this->unwrap()) && $this->unwrap() !== '';
46    }
47}