Completed
Push — master ( bb14d5...3c2ff8 )
by Josh
20:40 queued 08:35
created

Configurator::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\Autovideo;
9
10
use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
11
use s9e\TextFormatter\Plugins\ConfiguratorBase;
12
13
class Configurator extends ConfiguratorBase
14
{
15
	/**
16
	* @var string Name of attribute that stores the video's URL
17
	*/
18
	protected $attrName = 'src';
19
20
	/**
21
	* @var string
22
	*/
23
	protected $quickMatch = '://';
24
25
	/**
26
	* @var string
27
	*/
28
	protected $regexp = '#\\bhttps?://[-.\\w]+/[-./\\w]+\\.(?:mp4|ogg|webm)(?!\\S)#i';
29
30
	/**
31
	* @var string Name of the tag used to represent videos
32
	*/
33
	protected $tagName = 'VIDEO';
34
35
	/**
36
	* Creates the tag used by this plugin
37
	*
38
	* @return void
39
	*/
40 9
	protected function setUp()
41
	{
42 9
		if (isset($this->configurator->tags[$this->tagName]))
43 9
		{
44 1
			return;
45
		}
46
47
		// Create a tag
48 8
		$tag = $this->configurator->tags->add($this->tagName);
49
50
		// Add an attribute using the default url filter
51 8
		$filter = $this->configurator->attributeFilters['#url'];
52 8
		$tag->attributes->add($this->attrName)->filterChain->append($filter);
53
54
		// Set the default template
55 8
		$tag->template = '<video src="{@' . $this->attrName . '}"/>';
56
	}
57
}