Skip to content

Commit 00855cd

Browse files
authored
Merge pull request #389 from lloc/raise-coverage
Allowed HTML in Component class
2 parents f61e8a6 + 862660a commit 00855cd

21 files changed

+116
-74
lines changed

includes/Component/Component.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare( strict_types = 1 );
2+
3+
namespace lloc\Msls\Component;
4+
5+
/**
6+
* Abstract class Input
7+
*
8+
* @package lloc\Msls\Component
9+
*/
10+
abstract class Component {
11+
12+
const INPUT_PREFIX = 'msls_input_';
13+
14+
const ALLOWED_HTML = array(
15+
'label' => array(
16+
'for' => array(),
17+
),
18+
'option' => array(
19+
'value' => array(),
20+
'selected' => array(),
21+
),
22+
'select' => array(
23+
'id' => array(),
24+
'name' => array(),
25+
),
26+
'input' => array(
27+
'type' => array(),
28+
'class' => array(),
29+
'id' => array(),
30+
'name' => array(),
31+
'value' => array(),
32+
'size' => array(),
33+
'readonly' => array(),
34+
),
35+
);
36+
37+
/**
38+
* @return string
39+
*/
40+
abstract public function render(): string;
41+
42+
/**
43+
* Adds our input elements to the allowed HTML elements of a post
44+
*/
45+
public static function get_allowed_html(): array {
46+
$my_allowed = wp_kses_allowed_html( 'post' );
47+
48+
return array_merge( $my_allowed, self::ALLOWED_HTML );
49+
}
50+
}

includes/Component/Icon.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component;
44

55
/**
66
* Class Icon
7+
*
78
* @package lloc\Msls\Component
89
*/
910
abstract class Icon {
@@ -48,5 +49,4 @@ abstract protected function get_include(): string;
4849
* @return string
4950
*/
5051
abstract public function get( string $language ): string;
51-
52-
}
52+
}

includes/Component/Icon/IconLabel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Icon;
44

@@ -10,7 +10,7 @@
1010
*
1111
* @package lloc\Msls\Component
1212
*/
13-
class IconLabel extends Icon {
13+
final class IconLabel extends Icon {
1414

1515
/**
1616
* @return string

includes/Component/Icon/IconPng.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Icon;
44

@@ -7,9 +7,10 @@
77

88
/**
99
* Class IconPng
10+
*
1011
* @package lloc\Msls\Component
1112
*/
12-
class IconPng extends Icon {
13+
final class IconPng extends Icon {
1314

1415
const FLAGS_FILE = 'flags/flags.php';
1516

@@ -28,5 +29,4 @@ protected function get_include(): string {
2829
public function get( string $language ): string {
2930
return $this->map[ $language ] ?? $this->maybe( $language, '', '.png' );
3031
}
31-
32-
}
32+
}

includes/Component/Icon/IconSvg.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Icon;
44

@@ -7,9 +7,10 @@
77

88
/**
99
* Class IconSvg
10+
*
1011
* @package lloc\Msls\Component
1112
*/
12-
class IconSvg extends Icon {
13+
final class IconSvg extends Icon {
1314

1415
const FLAGS_FILE = 'css-flags/flags.php';
1516

@@ -28,5 +29,4 @@ protected function get_include(): string {
2829
public function get( string $language ): string {
2930
return $this->map[ $language ] ?? $this->maybe( $language, 'flag-icon-' );
3031
}
31-
32-
}
32+
}

includes/Component/Input/Checkbox.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Input;
44

5-
use lloc\Msls\Component\InputInterface;
5+
use lloc\Msls\Component\Component;
66

77
/**
88
* Class Checkbox
99
*
1010
* @package lloc\Msls\Component\Input
1111
*/
12-
class Checkbox implements InputInterface {
12+
final class Checkbox extends Component {
1313

1414
/**
1515
* @var string

includes/Component/Input/Group.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<?php
2-
1+
<?php declare( strict_types = 1 );
32

43
namespace lloc\Msls\Component\Input;
54

6-
use lloc\Msls\Component\InputInterface;
5+
use lloc\Msls\Component\Component;
76

87
/**
98
* Class Options
109
*
1110
* @package lloc\Msls\Component\Input
1211
*/
13-
class Group implements InputInterface {
12+
final class Group extends Component {
1413

1514
/**
16-
* @var InputInterface[]
15+
* @var Component[]
1716
*/
1817
protected $arr = array();
1918

@@ -32,11 +31,11 @@ public function __construct( string $glue = ' ' ) {
3231
}
3332

3433
/**
35-
* @param InputInterface $input
34+
* @param Component $input
3635
*
3736
* @return self
3837
*/
39-
public function add( InputInterface $input ): self {
38+
public function add( Component $input ): self {
4039
$this->arr[] = $input;
4140

4241
return $this;
@@ -47,7 +46,7 @@ public function add( InputInterface $input ): self {
4746
*/
4847
public function render(): string {
4948
$items = array_map(
50-
function ( InputInterface $input ) {
49+
function ( Component $input ) {
5150
return $input->render(); // phpcs:ignore WordPress.Security.EscapeOutput
5251
},
5352
$this->arr

includes/Component/Input/Label.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Input;
44

5-
use lloc\Msls\Component\InputInterface;
5+
use lloc\Msls\Component\Component;
66

77
/**
88
* Class Label
99
*
1010
* @package lloc\Msls\Component\Input
1111
*/
12-
class Label implements InputInterface {
12+
final class Label extends Component {
1313

1414
/**
1515
* @var string

includes/Component/Input/Option.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Input;
44

5-
use lloc\Msls\Component\InputInterface;
5+
use lloc\Msls\Component\Component;
66

77
/**
88
* Class Option
99
*
1010
* @package lloc\Msls\Component\Input
1111
*/
12-
class Option implements InputInterface {
12+
final class Option extends Component {
1313

1414
/**
1515
* @var string

includes/Component/Input/Select.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<?php
1+
<?php declare( strict_types = 1 );
22

33
namespace lloc\Msls\Component\Input;
44

5-
use lloc\Msls\Component\InputInterface;
5+
use lloc\Msls\Component\Component;
66

7-
class Select implements InputInterface {
7+
final class Select extends Component {
88

99
const RENDER_FILTER = 'msls_input_select_name';
1010

@@ -28,7 +28,7 @@ public function __construct( string $key, array $arr, ?string $selected = null )
2828

2929
$this->options = new Group( '' );
3030
foreach ( $arr as $key => $value ) {
31-
$this->options->add( new Option( $key, strval( $value ), $selected ) );
31+
$this->options->add( new Option( strval( $key ), strval( $value ), $selected ) );
3232
}
3333
}
3434

0 commit comments

Comments
 (0)