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
7class Youtube extends Value
8{
9    public function __toString(): string
10    {
11        $x = (float) ($this->meta('aspectRatioX', 16) ?: 16);
12        $y = (float) ($this->meta('aspectRatioY', 9) ?: 9);
13        $percent = number_format(($y / $x) * 100, 2, '.', '');
14        $iframeStyle = 'position: absolute; top: 0; left: 0; width: 100%; height: 100%';
15
16        return (
17            '<div class="youtube-container">'
18            . '<div style="position: relative; padding-top: '
19            . $percent
20            . '%">'
21            . '<iframe class="youtube" style="'
22            . $iframeStyle
23            . '" '
24            . 'src="https://www.youtube.com/embed/'
25            . $this->unwrap()
26            . '" allowfullscreen></iframe>'
27            . '</div></div>'
28        );
29    }
30
31    public function unwrap(): mixed
32    {
33        return $this->value();
34    }
35
36    public function json(): mixed
37    {
38        return $this->unwrap();
39    }
40
41    public function isset(): bool
42    {
43        return is_string($this->unwrap()) && $this->unwrap() !== '';
44    }
45}