Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

BaseRequestProcess::getFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Migratio\Resource\Request;
4
5
class BaseRequestProcess
6
{
7
    /**
8
     * @var $paths
0 ignored issues
show
Documentation Bug introduced by
The doc comment $paths at position 0 could not be parsed: Unknown type name '$paths' at position 0 in $paths.
Loading history...
9
     */
10
    public static $paths;
11
12
    /**
13
     * @param $path
14
     */
15
    public static function chmod($path)
16
    {
17
        $dir = new \DirectoryIterator($path);
18
19
        foreach ($dir as $item) {
20
21
            chmod($item->getPathname(), 0777);
22
23
            if ($item->isDir() && !$item->isDot()) {
24
                self::chmod($item->getPathname());
25
            }
26
        }
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public static function getAllDirectories()
33
    {
34
        $list = [];
35
36
        $paths = self::$paths;
37
38
        foreach ($paths as $path){
39
            $globPaths = array_filter(glob($path.'/*'), 'is_dir');
0 ignored issues
show
Bug introduced by
It seems like glob($path . '/*') can also be of type false; however, parameter $input of array_filter() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            $globPaths = array_filter(/** @scrutinizer ignore-type */ glob($path.'/*'), 'is_dir');
Loading history...
40
            foreach ($globPaths as $reelPath){
41
                $list[]=$reelPath;
42
            }
43
        }
44
45
        return $list;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public static function getAllFiles()
52
    {
53
        $directories = self::getAllDirectories();
54
55
        $list = [];
56
57
        foreach ($directories as $directory){
58
59
            foreach (glob($directory."/*.php") as $file) {
60
61
                $list[self::getFileName($directory)][]=$file;
62
            }
63
        }
64
65
        return $list;
66
    }
67
68
    /**
69
     * @param $path
70
     * @return string
71
     */
72
    public static function getFileName($path)
73
    {
74
        $pathParse = explode ("/",$path);
75
76
        return end($pathParse);
77
    }
78
79
    /**
80
     * @param $tables
81
     */
82
    public static function setDirectoryForTableNames($tables)
83
    {
84
        $directories = self::getAllDirectories();
85
86
        $mainPath = self::$paths[0].'';
87
88
        $mkdirResults = [];
89
90
        foreach ($tables as $table){
91
            if(!isset($directories[$table])){
92
93
                //get path and set mkdir
94
                $path = $mainPath.'/'.ucfirst($table);
95
                if(!file_exists($path)){
96
                   $mkdirResults[] = mkdir($path, 0777);
97
                }
98
            }
99
        }
100
101
        dd(self::getAllDirectories(),$tables,$mkdirResults);
102
    }
103
}
104
105