Completed
Branch wip/litedown (e234a3)
by Josh
31:46 queued 18:30
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 69
	protected function setLinkAttributes(Tag $tag, $linkInfo, $attrName)
23
	{
24 69
		$url   = trim($linkInfo);
25 69
		$title = '';
26 69
		$pos   = strpos($url, ' ');
27 69
		if ($pos !== false)
28 69
		{
29 30
			$title = substr(trim(substr($url, $pos)), 1, -1);
30 30
			$url   = substr($url, 0, $pos);
31 30
		}
32
33 69
		$tag->setAttribute($attrName, $this->text->decode($url));
1 ignored issue
show
Bug introduced by
The property text does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34 69
		if ($title > '')
35 69
		{
36 29
			$tag->setAttribute('title', $this->text->decode($title));
37 29
		}
38
	}
39
}