Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
RemovableClassesTransform | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
apply | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Transforms; |
4 | |
5 | use DOMElement; |
6 | use Wikimedia\Parsoid\Utils\DOMCompat; |
7 | |
8 | class RemovableClassesTransform implements IMobileTransform { |
9 | |
10 | /** @var string[] */ |
11 | private $removableClasses; |
12 | |
13 | /** |
14 | * @param string[] $removableClasses List of slectors denoting elements to be removed |
15 | */ |
16 | public function __construct( array $removableClasses ) { |
17 | $this->removableClasses = $removableClasses; |
18 | } |
19 | |
20 | /** |
21 | * @param DOMElement $node to be transformed |
22 | */ |
23 | public function apply( DOMElement $node ) { |
24 | foreach ( $this->removableClasses as $selector ) { |
25 | foreach ( DOMCompat::querySelectorAll( $node, $selector ) as $element ) { |
26 | $element->parentNode->removeChild( $element ); |
27 | } |
28 | } |
29 | } |
30 | } |