@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param array $attributes Additional attributes |
| 66 | 66 | * @return string |
| 67 | 67 | */ |
| 68 | - public static function img(string $src, string $alt='', $attributes = []) |
|
| 68 | + public static function img(string $src, string $alt = '', $attributes = []) |
|
| 69 | 69 | { |
| 70 | 70 | $attributes['src'] = $src; |
| 71 | 71 | $attributes['alt'] = $alt; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | $content .= parent::figcaption($caption); |
| 90 | 90 | $attributes['role'] = 'figure'; |
| 91 | - return parent::figure($content, $attributes, function ($value) { |
|
| 91 | + return parent::figure($content, $attributes, function($value) { |
|
| 92 | 92 | return $value; |
| 93 | 93 | }); |
| 94 | 94 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public static function audio(string $src, $attributes = []) |
| 120 | 120 | { |
| 121 | - if(empty($src)) { |
|
| 121 | + if (empty($src)) { |
|
| 122 | 122 | throw new \InvalidArgumentException("Source attribute is required"); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public static function iframe(string $src, string $title, $attributes = []) |
| 152 | 152 | { |
| 153 | - if(empty($title)) { |
|
| 153 | + if (empty($title)) { |
|
| 154 | 154 | throw new \InvalidArgumentException("Iframe title is required"); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public static function a(string $href, string $content, $attributes = []) |
| 168 | 168 | { |
| 169 | - if(empty($href)) { |
|
| 169 | + if (empty($href)) { |
|
| 170 | 170 | throw new \InvalidArgumentException("Anchor href is required"); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public static function area(string $alt, $attributes = []) |
| 183 | 183 | { |
| 184 | - if(empty($alt)) { |
|
| 184 | + if (empty($alt)) { |
|
| 185 | 185 | throw new \InvalidArgumentException("Area alt is required"); |
| 186 | 186 | } |
| 187 | 187 | $attributes['alt'] = $alt; |
@@ -195,18 +195,18 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public static function input(string $type, string $name, $attributes = []) |
| 197 | 197 | { |
| 198 | - if(empty($type)) { |
|
| 198 | + if (empty($type)) { |
|
| 199 | 199 | throw new \InvalidArgumentException("Input type is required"); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if(empty($name)) { |
|
| 202 | + if (empty($name)) { |
|
| 203 | 203 | throw new \InvalidArgumentException("Input name is required"); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | $attributes['name'] = $name; |
| 207 | 207 | $attributes['type'] = $type; |
| 208 | 208 | |
| 209 | - if(self::inputIsRequired($attributes)) { |
|
| 209 | + if (self::inputIsRequired($attributes)) { |
|
| 210 | 210 | $attributes['aria-required'] = 'true'; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | $attributes['name'] = $name; |
| 232 | 232 | $string_options = ''; |
| 233 | - foreach($options as $value => $label) { |
|
| 234 | - $string_options.= parent::option($label, ['value' => $value]); |
|
| 233 | + foreach ($options as $value => $label) { |
|
| 234 | + $string_options .= parent::option($label, ['value' => $value]); |
|
| 235 | 235 | } |
| 236 | - return parent::select($string_options, $attributes, function ($value) { |
|
| 236 | + return parent::select($string_options, $attributes, function($value) { |
|
| 237 | 237 | return $value; |
| 238 | 238 | }); |
| 239 | 239 | } |
@@ -271,11 +271,11 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | public static function html(string $content, $attributes = []) |
| 273 | 273 | { |
| 274 | - if(empty($content)) { |
|
| 274 | + if (empty($content)) { |
|
| 275 | 275 | throw new \InvalidArgumentException("HTML content is required"); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if(empty($attributes['lang'])) { |
|
| 278 | + if (empty($attributes['lang'])) { |
|
| 279 | 279 | throw new \InvalidArgumentException("Language attribute is required"); |
| 280 | 280 | } |
| 281 | 281 | return parent::html($content, $attributes); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public static function th(string $scope, string $content, $attributes = []) |
| 290 | 290 | { |
| 291 | - if(empty($scope)) { |
|
| 291 | + if (empty($scope)) { |
|
| 292 | 292 | throw new \InvalidArgumentException("Scope attribute is required"); |
| 293 | 293 | } |
| 294 | 294 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | foreach ($list as $value => $label) { |
| 108 | 108 | $option_attributes = ['value' => $value]; |
| 109 | 109 | if ($selected == $value) { |
| 110 | - $option_attributes['selected'] = 'selected'; |
|
| 110 | + $option_attributes['selected'] = 'selected'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $options .= new Element('option', "$label", $option_attributes); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public static function legend(string $label, array $attributes = []): string |
| 127 | 127 | { |
| 128 | - return '' . (new Element('legend', $label, $attributes)); |
|
| 128 | + return ''.(new Element('legend', $label, $attributes)); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | public static function button(string $label, array $attributes = []): string |
| 148 | 148 | { |
| 149 | - return '' . (new Element('button', $label, $attributes)); |
|
| 149 | + return ''.(new Element('button', $label, $attributes)); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | unset($attributes['label']); |
| 201 | 201 | $input = new Element($tag, $content, $attributes); |
| 202 | 202 | |
| 203 | - if($label_text){ |
|
| 203 | + if ($label_text) { |
|
| 204 | 204 | if (!empty($attributes['label-wrap'])) |
| 205 | 205 | $ret = self::label(null, $label_text.$input); |
| 206 | 206 | else |
@@ -201,13 +201,14 @@ |
||
| 201 | 201 | $input = new Element($tag, $content, $attributes); |
| 202 | 202 | |
| 203 | 203 | if($label_text){ |
| 204 | - if (!empty($attributes['label-wrap'])) |
|
| 205 | - $ret = self::label(null, $label_text.$input); |
|
| 206 | - else |
|
| 207 | - $ret = self::label($attributes['id'], $label_text).$input; |
|
| 204 | + if (!empty($attributes['label-wrap'])) { |
|
| 205 | + $ret = self::label(null, $label_text.$input); |
|
| 206 | + } else { |
|
| 207 | + $ret = self::label($attributes['id'], $label_text).$input; |
|
| 208 | + } |
|
| 209 | + } else { |
|
| 210 | + $ret = $input; |
|
| 208 | 211 | } |
| 209 | - else |
|
| 210 | - $ret = $input; |
|
| 211 | 212 | |
| 212 | 213 | return (string)$ret; |
| 213 | 214 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | |
| 79 | 79 | foreach ($this->attributes as $name => $value) { |
| 80 | 80 | $name = ($this->formatter)($name); |
| 81 | - $attributes .= ' ' . ($value === true ? $name : sprintf('%s="%s"', $name, ($this->formatter)((string)$value))); |
|
| 81 | + $attributes .= ' '.($value === true ? $name : sprintf('%s="%s"', $name, ($this->formatter)((string)$value))); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | return $this->inner === null |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $element = new Element('div', $content, ['class' => ['foo', 'bar'], 'id' => 'test'], false); |
| 141 | 141 | |
| 142 | 142 | $this->assertEquals( |
| 143 | - '<div class="foo bar" id="test">' . $content . '</div>', |
|
| 143 | + '<div class="foo bar" id="test">'.$content.'</div>', |
|
| 144 | 144 | $element->__toString() |
| 145 | 145 | ); |
| 146 | 146 | $content = 'Hello, World! & < > " \' '; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ], 'id' => 'test', 'data-attr' => $content], false); |
| 151 | 151 | |
| 152 | 152 | $this->assertEquals( |
| 153 | - '<div class="foo bar" id="test" data-attr="' . $content . '">' . $content . '</div>', |
|
| 153 | + '<div class="foo bar" id="test" data-attr="'.$content.'">'.$content.'</div>', |
|
| 154 | 154 | $element->__toString() |
| 155 | 155 | ); |
| 156 | 156 | |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | $element = new Element('div', $content, ['class' => ['foo', 'bar'], 'id' => 'test', 'data-attr' => $content, 'data-attr2' => $content], false); |
| 160 | 160 | |
| 161 | 161 | $this->assertEquals( |
| 162 | - '<div class="foo bar" id="test" data-attr="' . $content . '" data-attr2="' . $content . |
|
| 163 | - '">' . $content . '</div>', |
|
| 162 | + '<div class="foo bar" id="test" data-attr="'.$content.'" data-attr2="'.$content. |
|
| 163 | + '">'.$content.'</div>', |
|
| 164 | 164 | $element->__toString() |
| 165 | 165 | ); |
| 166 | 166 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * HTML generator |
|
| 5 | - * Marker, hommage to Christian François Bouche-Villeneuve aka Chris Marker |
|
| 6 | - */ |
|
| 4 | + * HTML generator |
|
| 5 | + * Marker, hommage to Christian François Bouche-Villeneuve aka Chris Marker |
|
| 6 | + */ |
|
| 7 | 7 | |
| 8 | 8 | declare(strict_types=1); |
| 9 | 9 | |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | class Marker extends Element |
| 13 | 13 | { |
| 14 | 14 | /** |
| 15 | - * ? smoother write |
|
| 16 | - * Marker::img('path/to/img.jpg', 'An alternative text', ['width' => 34, 'height' => 34]) |
|
| 17 | - * than |
|
| 18 | - * Element::img(null, ['src' => 'path/to/img.jpg', 'alt' => 'An alternative text', 'width' => 34, 'height' => 34]) |
|
| 19 | - */ |
|
| 15 | + * ? smoother write |
|
| 16 | + * Marker::img('path/to/img.jpg', 'An alternative text', ['width' => 34, 'height' => 34]) |
|
| 17 | + * than |
|
| 18 | + * Element::img(null, ['src' => 'path/to/img.jpg', 'alt' => 'An alternative text', 'width' => 34, 'height' => 34]) |
|
| 19 | + */ |
|
| 20 | 20 | public static function img(string $src, string $alt, array $attributes = [], $formatter=null): Element |
| 21 | 21 | { |
| 22 | 22 | $attributes['src'] ??= $src; |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * ? makes more sense to write |
|
| 31 | - * Marker::a('controller/task/id', 'Click here', ['class' => 'nav']) |
|
| 32 | - * than |
|
| 33 | - * Marker::a('Click here', ['href' => controller/task/id', 'class' => 'nav']) |
|
| 34 | - */ |
|
| 30 | + * ? makes more sense to write |
|
| 31 | + * Marker::a('controller/task/id', 'Click here', ['class' => 'nav']) |
|
| 32 | + * than |
|
| 33 | + * Marker::a('Click here', ['href' => controller/task/id', 'class' => 'nav']) |
|
| 34 | + */ |
|
| 35 | 35 | public static function a(string $href, string $label, array $attributes = [], $formatter = null): Element |
| 36 | 36 | { |
| 37 | 37 | $attributes['href'] = $href; |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | * than |
| 18 | 18 | * Element::img(null, ['src' => 'path/to/img.jpg', 'alt' => 'An alternative text', 'width' => 34, 'height' => 34]) |
| 19 | 19 | */ |
| 20 | - public static function img(string $src, string $alt, array $attributes = [], $formatter=null): Element |
|
| 20 | + public static function img(string $src, string $alt, array $attributes = [], $formatter = null): Element |
|
| 21 | 21 | { |
| 22 | 22 | $attributes['src'] ??= $src; |
| 23 | 23 | $attributes['alt'] ??= $alt; |
| 24 | 24 | $attributes['title'] ??= $alt; |
| 25 | 25 | |
| 26 | - return new Element('img', null,$attributes, $formatter); |
|
| 26 | + return new Element('img', null, $attributes, $formatter); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -36,6 +36,6 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | $attributes['href'] = $href; |
| 38 | 38 | |
| 39 | - return new Element('a', $label,$attributes, $formatter); |
|
| 39 | + return new Element('a', $label, $attributes, $formatter); |
|
| 40 | 40 | } |
| 41 | 41 | } |