ExternalLinkFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 21
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A removeWebLinks() 0 12 3
1
<?php
2
3
namespace ExternalLinkPurifier\src\Services;
4
5
class ExternalLinkFilter {
6
7
    /**
8
     * @param string $content
9
     * @param string $domain    //Keep links of this domain remove others
10
     * 
11
     * @return string
12
     */
13
    public static function removeWebLinks($content, $domain = '') {
14
        if (!empty($content)) {
15
            if (!empty($domain)) {
16
                $pattern = '#<a [^>]*\bhref=([\'"])http.?://((?<!'. $domain .')[^\'"])+\1 *.*?</a>#i';                
17
                $filteredString = preg_replace($pattern, '', $content);
18
            } else {
19
                $filteredString = preg_replace('#<a.*?>.*?</a>#i', '', $content);
20
            }
21
            
22
            return $filteredString;
23
        }        
24
    }
25
}
26