IO   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 17.65%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 62
ccs 3
cts 17
cp 0.1765
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullPath() 0 7 2
A glob() 0 9 2
A getCount() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Packagist Mirror.
7
 *
8
 * For the full license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webs\Mirror;
13
14
use FilesystemIterator;
15
16
/**
17
 * Trait to FlyFilesystem wraper operations.
18
 *
19
 * @author Webysther Nunes <[email protected]>
20
 */
21
trait IO
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $directory;
27
28
    /**
29
     * Glob without file sort.
30
     *
31
     * @param string $pattern
32
     *
33
     * @return array
34
     */
35
    public function glob(string $pattern):array
36
    {
37
        $return = glob($this->getFullPath($pattern), GLOB_NOSORT);
38
39
        if ($return === false) {
40
            return [];
41
        }
42
43
        return $return;
44
    }
45
46
    /**
47
     * Count files inside folder, if is a file, return 0.
48
     *
49
     * @param string $folder
50
     *
51
     * @return int
52
     */
53
    public function getCount(string $folder):int
54
    {
55
        $path = $this->getFullPath($folder);
56
57
        if (!is_dir($path)) {
58
            $path = dirname($path);
59
        }
60
61
        $iterator = new FilesystemIterator(
62
            $path,
63
            FilesystemIterator::SKIP_DOTS
64
        );
65
66
        return iterator_count($iterator);
67
    }
68
69
    /**
70
     * Get full path.
71
     *
72
     * @param string $path
73
     *
74
     * @return string
75
     */
76 1
    public function getFullPath(string $path):string
77
    {
78 1
        if (strpos($path, $this->directory) !== false) {
79
            return $path;
80
        }
81
82 1
        return $this->directory.$path;
83
    }
84
}
85