AlphaPimHelper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A xmlAttribute() 0 4 2
A clearFromPIMTags() 0 9 2
A xmlNodeByQuery() 0 3 1
A getCountries() 0 7 2
1
<?php
2
3
namespace App\Backend\Import;
4
5
use SimpleXMLElement;
6
7
class AlphaPimHelper
8
{
9
    /**
10
     * @param SimpleXMLElement $oXml
11
     * @return array Countries
12
     */
13
    public static function getCountries(SimpleXMLElement $oXml)
14
    {
15
        if ($sCountries = static::xmlAttribute($oXml, 'fuer_Land')) {
16
            $aCountries = explode(',', $sCountries);
17
            $aCountries = array_map('trim', $aCountries);
18
        }
19
        return $aCountries;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $aCountries does not seem to be defined for all execution paths leading up to this point.
Loading history...
20
    }
21
22
    /**
23
     * @param $oXml SimpleXMLElement
24
     * @param $sAttribite string
25
     * @return string
26
     */
27
    public static function xmlAttribute($oXml, $sAttribite)
28
    {
29
        if (isset($oXml[$sAttribite])) {
30
            return (string)$oXml[$sAttribite];
31
        }
32
    }
33
34
    /**
35
     * @param SimpleXMLElement $oXml
36
     * @param $sQuery
37
     * @return SimpleXMLElement[]
38
     */
39
    public static function xmlNodeByQuery(SimpleXMLElement $oXml, $sQuery)
40
    {
41
        return $oXml->xpath($sQuery);
42
    }
43
44
45
    public static function clearFromPIMTags($sValue, $allowable_tags = '<p><ul><li><strong><br/><br><br /><b>', $htmlDecode = true)
46
    {
47
        $allowable_tags .= strtoupper($allowable_tags);
48
        $stripped = strip_tags($sValue, $allowable_tags);
49
        if ($htmlDecode) {
50
            $stripped = html_entity_decode($stripped, null);
51
        } // if
52
        $value = preg_replace("/<([a-zA-Z][a-z0-9]*)[^>]*?(\/?)>/i", '<$1$2>', $stripped);
53
        return $value;
54
    }
55
}
56