Completed
Push — master ( 9b687d...89b056 )
by Josh
28:34
created

LinkAttributesSetter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setLinkAttributes() 0 17 3
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\Litedown\Parser;
9
10
use s9e\TextFormatter\Parser\Tag;
11
12
trait LinkAttributesSetter
13
{
14
	/**
15
	* Set a URL or IMG tag's attributes
16
	*
17
	* @param  Tag    $tag      URL or IMG tag
18
	* @param  string $linkInfo Link's info: an URL optionally followed by spaces and a title
19
	* @param  string $attrName Name of the URL attribute
20
	* @return void
21
	*/
22 24
	protected function setLinkAttributes(Tag $tag, $linkInfo, $attrName)
23
	{
24 24
		$url   = trim($linkInfo);
25 24
		$title = '';
26 24
		$pos   = strpos($url, ' ');
27 24
		if ($pos !== false)
28 24
		{
29 10
			$title = substr(trim(substr($url, $pos)), 1, -1);
30 10
			$url   = substr($url, 0, $pos);
31 10
		}
32
33 24
		$tag->setAttribute($attrName, $this->text->decode($url));
34 24
		if ($title > '')
35 24
		{
36 10
			$tag->setAttribute('title', $this->text->decode($title));
37 10
		}
38
	}
39
}