Requester   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 69
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFiles() 0 11 3
A path() 0 3 1
A exists() 0 3 1
A setBasePath() 0 8 2
A make() 0 3 1
1
<?php
2
3
namespace TwoDojo\ModuleManager\Support;
4
5
class Requester
6
{
7
    protected $basePath;
8
9
    /**
10
     * Create a new instance
11
     *
12
     * @return self
13
     */
14
    public static function make()
15
    {
16
        return new static();
17
    }
18
19
    /**
20
     * Set the base path
21
     *
22
     * @param $path
23
     * @return $this
24
     */
25
    public function setBasePath($path)
26
    {
27
        $this->basePath = $path;
28
        if (!ends_with($this->basePath, DIRECTORY_SEPARATOR)) {
29
            $this->basePath .= DIRECTORY_SEPARATOR;
30
        }
31
32
        return $this;
33
    }
34
35
    /**
36
     * Determine if the given file is exists
37
     *
38
     * @param string $file
39
     * @return boolean
40
     */
41
    public function exists(string $file) : bool
42
    {
43
        return file_exists($this->path($file));
44
    }
45
46
    /**
47
     * Get the path for the given file
48
     *
49
     * @param string $file
50
     * @return string
51
     */
52
    public function path(string $file)
53
    {
54
        return $this->basePath.$file;
55
    }
56
57
    /**
58
     * Get all files in the specified directory
59
     *
60
     * @param $path
61
     * @return array
62
     */
63
    public function getFiles($path)
64
    {
65
        $files = [];
66
67
        foreach (new \DirectoryIterator($this->path($path)) as $file) {
68
            if ($file->isFile()) {
69
                $files[] = $file->getFileInfo();
70
            }
71
        }
72
73
        return $files;
74
    }
75
}
76