GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f74d05...468b27 )
by Pedro
07:16 queued 04:16
created

CleanTrash::diffFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
namespace Classes;
4
use Classes\Db\Iterators\DbTables;
5
6
/**
7
 * @author Pedro Alarcao <[email protected]>
8
 * @link   https://github.com/pedro151/orm-generator
9
 */
10
class CleanTrash
11
{
12
    /**
13
     * @type CleanTrash
14
     */
15
    private static $instance;
16
17
    /**
18
     * @type int
19
     */
20
    private $countFileDeleted=0;
21
22
    final private function __construct (){ }
23
24
    /**
25
     * @return \Classes\CleanTrash
26
     */
27
    public static function getInstance ()
28
    {
29
        if ( self::$instance === null )
30
        {
31
            self::$instance = new self();
32
        }
33
34
        return self::$instance;
35
    }
36
37
    private function scanDir ( $directory )
38
    {
39
        if(!is_dir($directory)){
40
            return array();
41
        }
42
43
        $diretories = preg_grep ( '*\.ph*' , scandir ( $directory ) );
44
        if(!$diretories){
0 ignored issues
show
Bug Best Practice introduced by
The expression $diretories of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
45
            return array();
46
        }
47
48
        return array_diff ( $diretories, array (
49
            '..' , '.'
50
        ) );
51
    }
52
53
    /**
54
     * @param string                                 $path
55
     * @param \Classes\AdaptersDriver\AbsractAdapter $driver
56
     * @param int                                    $schema
57
     *
58
     * @return array
59
     */
60
    private function diffFiles ( $path , $driver , $schema = 0 )
61
    {
62
        $tables = $driver->getTables ( $schema );
63
        if(!$tables instanceof DbTables){
64
            return array();
65
        }
66
        $tablesName = $tables->toArrayFileName();
67
        return array_diff ( $this->scanDir ( $path ) , $tablesName );
68
    }
69
70
    /**
71
     * @param string                                 $path
72
     * @param \Classes\AdaptersDriver\AbsractAdapter $driver
73
     * @param int                                    $schema
74
     *
75
     * @return int
76
     */
77
    public function run ( $path , $driver , $schema = 0 )
78
    {
79
        $count = 0;
80
        foreach ( $this->diffFiles ( $path , $driver , $schema ) as $fileDel )
81
        {
82
            if ( unlink ( $path . DIRECTORY_SEPARATOR . $fileDel ) )
83
            {
84
                ++ $count;
85
            }
86
        }
87
88
        $this->countFileDeleted += $count;
89
90
        return $count;
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getNumFilesDeleted ()
97
    {
98
        return $this->countFileDeleted;
99
    }
100
101
}