Completed
Push — master ( b59592...c78116 )
by Faiz
01:47
created

XML   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 38
ccs 21
cts 21
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 19 2
A pathToXML() 0 8 1
1
<?php
2
3
namespace FaizShukri\Quran\Supports;
4
5
class XML
6
{
7
    private $xml;
8
9 39
    public function __construct($xmlPath)
10
    {
11 39
        $this->xml = $this->pathToXML($xmlPath);
12 39
    }
13
14 39
    public function find($surah, array $ayah)
15
    {
16 39
        $xml = new \SimpleXMLElement($this->xml);
17
18 39
        $xpath = '//sura[@index=' . $surah . ']/aya[' . implode(' or ', array_map(function ($a) {
19 39
                return '@index=' . $a;
20 39
            }, $ayah)) . ']';
21
22 39
        $xpathResult = $xml->xpath($xpath);
23 39
        $result = [];
24
25 39
        while (list(, $node) = each($xpathResult)) {
26 39
            $node = (array)$node;
27 39
            $verse = current($node);
28 39
            $result[$verse['index']] = $verse['text'];
29 39
        }
30
31 39
        return $result;
32
    }
33
34 39
    public function pathToXML($xmlPath)
35
    {
36 39
        $xml = fopen($xmlPath, "r");
37 39
        $res = fread($xml, filesize($xmlPath));
38 39
        fclose($xml);
39
40 39
        return $res;
41
    }
42
}