Test Failed
Push — master ( 00a8e7...e23989 )
by NexusLink
06:11
created

ExternalLinkFilter::removeWebLinks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
1
<?php
2
3
namespace ExternalLinkPurifier\src\Services;
4
5
class ExternalLinkFilter {
6
7
    /**
8
     * 
9
     * @param string $content
10
     * @param string $domain    //Keep links of this domain remove others
11
     * 
12
     * @return string
13
     */
14
    public static function removeWebLinks($content, $domain) {
15
        if (!empty($content)) {
16
            if(!empty($domain)) {                
17
                $pattern = '#<a [^>]*\bhref=([\'"])http.?://((?!$domain)[^\'"])+\1 *>.*?</a>#i';
18
                $filteredString = preg_replace($pattern, '', $content);
19
            } else {
20
                $filteredString = preg_replace('#<a.*?>.*?</a>#i', '', $content);
21
            }
22
            
23
            return $filteredString;
24
        }        
25
    }
26
}
27