Total Complexity | 6 |
Total Lines | 79 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class MediaBlock implements Extractable |
||
10 | { |
||
11 | public const TOKEN_MEDIA = '@media'; |
||
12 | public const TOKEN_OPENING_BRACKET = '{'; |
||
13 | public const TOKEN_CLOSING_BRACKET = '}'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $mediaQuery; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $styles; |
||
24 | |||
25 | /** |
||
26 | * @var string block exactly how it appeared in the source |
||
27 | */ |
||
28 | private $raw; |
||
29 | |||
30 | /** |
||
31 | * MediaBlock constructor. |
||
32 | * |
||
33 | * @param string $mediaQuery |
||
34 | * @param string $styles |
||
35 | * @param string $raw |
||
36 | */ |
||
37 | private function __construct(string $mediaQuery, string $styles, string $raw) |
||
38 | { |
||
39 | $this->mediaQuery = $mediaQuery; |
||
40 | $this->styles = $styles; |
||
41 | $this->raw = $raw; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | public function __toString(): string |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $block |
||
54 | * |
||
55 | * @throws InvalidArgument |
||
56 | * |
||
57 | * @return self |
||
58 | */ |
||
59 | public static function createFromString(string $block): self |
||
60 | { |
||
61 | if (empty($block)) { |
||
62 | throw new InvalidArgument('Cannot build media block from empty string.'); |
||
63 | } |
||
64 | |||
65 | list($mediaQuery, $stylesWithTrailingBracket) = array_map( |
||
66 | 'trim', |
||
67 | explode(MediaBlock::TOKEN_OPENING_BRACKET, $block, 2) |
||
68 | ); |
||
69 | $styles = trim(substr($stylesWithTrailingBracket, 0, -1)); |
||
70 | |||
71 | return new self($mediaQuery, $styles, $block); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getMediaQuery(): string |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getStyles(): string |
||
90 |