Passed
Push — master ( ea4658...dc61d8 )
by Josh
02:44
created

Slugger::setTagSlug()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 1
cc 2
nc 2
nop 2
crap 2
1
<?php declare(strict_types=1);
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\Plugins\Litedown\Parser;
9
10
use s9e\TextFormatter\Parser\Tag;
11
12
class Slugger
13
{
14 4
	public static function getJS(): string
15
	{
16 4
		return file_get_contents(__DIR__ . '/Slugger.js');
17
	}
18
19 4
	public static function setTagSlug(Tag $tag, string $innerText): void
20
	{
21 4
		$slug = strtolower($innerText);
22 4
		$slug = preg_replace('/[^a-z0-9]+/', '-', $slug);
23 4
		$slug = trim($slug, '-');
24 4
		if ($slug !== '')
25
		{
26 4
			$tag->setAttribute('slug', $slug);
27
		}
28
	}
29
}