Completed
Push — master ( 9d41cf...4c6a1a )
by Josh
29:31
created

LinkAttributesSetter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 28
ccs 0
cts 15
cp 0
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
	protected function setLinkAttributes(Tag $tag, $linkInfo, $attrName)
23
	{
24
		$url   = trim($linkInfo);
25
		$title = '';
26
		$pos   = strpos($url, ' ');
27
		if ($pos !== false)
28
		{
29
			$title = substr(trim(substr($url, $pos)), 1, -1);
30
			$url   = substr($url, 0, $pos);
31
		}
32
33
		$tag->setAttribute($attrName, $this->text->decode($url));
34
		if ($title > '')
35
		{
36
			$tag->setAttribute('title', $this->text->decode($title));
37
		}
38
	}
39
}