LinkPurifier::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the External Link Purifier Package
5
 *
6
 * (c) Nexuslink Services
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ExternalLinkPurifier;
13
14
use Symfony\Component\Yaml\Yaml;
15
use ExternalLinkPurifier\src\Services\ExternalLinkFilter;
16
17
class LinkPurifier {
18
19
    private $pathToYml;
20
21
    public function __construct($pathToYml = '') {
22
23
        if (!empty($pathToYml)) {
24
            $this->pathToYml = $pathToYml;
25
        } else {
26
            $this->pathToYml = __DIR__ . "/../Resources/config/config.yml";
27
        }
28
    }
29
30
    /**
31
     * @param string $content
32
     * @param string $domain
33
     * @param string $purify
34
     * 
35
     * @return string
36
     */
37
    public function Purify($content, $domain = null, $purify = false) {
38
        
39
        $configArray = Yaml::parse(file_get_contents($this->pathToYml));
40
        
41
        if (true === $purify || true === $configArray['external_link']['purify'])
42
        {
43
            $content = ExternalLinkFilter::removeWebLinks($content, $domain);
44
        }
45
        
46
        return $content;
47
    }
48
    
49
}
50