Passed
Push — master ( 62942b...a1d089 )
by Josh
02:55
created

normalizeElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2020 The s9e authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
9
10
use DOMElement;
11
12
/**
13
* Add rel="noreferrer" on links that open in a new context that would allow window.opener to be
14
* accessed.
15
*
16
* @link https://mathiasbynens.github.io/rel-noopener/
17
* @link https://wiki.whatwg.org/wiki/Links_to_Unrelated_Browsing_Contexts
18
*/
19
class SetRelNoreferrerOnTargetedLinks extends AddAttributeValueToElements
20
{
21
	/**
22
	* {@inheritdoc}
23
	*/
24 7
	public function __construct(string $query = '//a[@target] | //area[@target]', string $attrName = 'rel', string $value = 'noreferrer')
25
	{
26 7
		parent::__construct($query, $attrName, $value);
27
	}
28
29
	/**
30
	* {@inheritdoc}
31
	*/
32 6
	protected function normalizeElement(DOMElement $element): void
33
	{
34 6
		if (!preg_match('(\\bno(?:open|referr)er\\b)', $element->getAttribute('rel')))
35
		{
36 4
			parent::normalizeElement($element);
37
		}
38
	}
39
}