Completed
Push — master ( 052b07...ab95ef )
by Roberto
05:41 queued 02:45
created

XsdSeeker   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 41
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C seek() 0 22 7
A getVersion() 0 6 1
1
<?php
2
3
namespace NFePHP\eSocial\Common;
4
5
class XsdSeeker
6
{
7
8
    public static $list = [
9
        'ConsultaLoteEventos' => ['version' => '', 'name' => ''],
10
        'EnvioLoteEventos' => ['version' => '', 'name' => ''],
11
        'RetornoEnvioLoteEventos' => ['version' => '', 'name' => ''],
12
        'RetornoEvento' => ['version' => '', 'name' => ''],
13
        'RetornoProcessamentoLote' => ['version' => '', 'name' => ''],
14
    ];
15
16
    public static function seek($path)
17
    {
18
        if (!is_dir($path)) {
19
            return self::$list;
20
        }
21
        $arr = scandir($path);
22
        foreach ($arr as $filename) {
23
            if ($filename == '.' || $filename == '..') {
24
                continue;
25
            }
26
            foreach (self::$list as $key => $content) {
27
                $len = strlen($key);
28
                $chave = substr($filename, 0, $len);
29
                $version = self::getVersion($filename);
30
                if ($chave == $key) {
31
                    self::$list[$key] = ['version' => $version, 'name' => $filename];
32
                    break;
33
                }
34
            }
35
        }
36
        return self::$list;
37
    }
38
39
    public static function getVersion($filename)
40
    {
41
        $p = explode('-', $filename);
42
        $v = explode('.', $p[1]);
43
        return $v[0];
44
    }
45
}
46