Directory   B
last analyzed

Complexity

Total Complexity 53

Size/Duplication

Total Lines 289
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 289
rs 7.4757
c 0
b 0
f 0
wmc 53
lcom 1
cbo 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A setFilter() 0 6 1
A setDirectory() 0 15 2
A filePath() 0 10 2
A getDirectory() 0 13 3
B getFiles() 0 38 4
B size() 0 30 6
C dirCopy() 0 55 19
A deleteDir() 0 17 4
D chmod() 0 41 10

How to fix   Complexity   

Complex Class

Complex classes like Directory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Directory, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Koch Framework
5
 * Jens-André Koch © 2005 - onwards.
6
 *
7
 * This file is part of "Koch Framework".
8
 *
9
 * License: GNU/GPL v2 or any later version, see LICENSE file.
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace Koch\Files;
26
27
class Directory
28
{
29
    private $filtername = 'ImagesOnly';
30
    private $directory  = '';
31
32
    public function __construct($directory = null)
33
    {
34
        if ($directory !== null) {
35
            $this->setDirectory($directory);
36
        }
37
38
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
39
    }
40
41
    /**
42
     * Available Filter types: image.
43
     */
44
    public function setFilter($filtername)
45
    {
46
        $this->filtername = $filtername;
47
48
        return $this;
49
    }
50
51
    public function setDirectory($directory)
52
    {
53
        // slash fix
54
        $directory = str_replace('/', DIRECTORY_SEPARATOR, $directory);
55
        $directory = str_replace('\\', DIRECTORY_SEPARATOR, $directory);
56
57
        // prefix directory with ROOT for security purposes
58
        if (stristr($directory, ROOT) === false) {
59
            $directory = APPLICATION_PATH . $directory;
60
        }
61
62
        $this->directory = $directory;
63
64
        return $this;
65
    }
66
67
    public function getDirectory($directory = '')
68
    {
69
        if ($directory !== '') {
70
            $this->directory = $directory;
71
        }
72
73
        if (empty($this->directory) === false) {
74
            return $this->directory;
75
        } else { // default path
76
77
            return APPLICATION_PATH . 'uploads/images/gallery';
78
        }
79
    }
80
81
    public function getFiles($return_as_array = false)
0 ignored issues
show
Coding Style introduced by
$return_as_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
82
    {
83
        // compose the full name of the filter class
84
        $classname = 'Koch_' . $this->filtername . 'FilterIterator';
85
86
        // wrap the iterator in a filter class, when looking for a specific file type, like imagesOnly
87
        $iterator = new $classname(new \DirectoryIterator($this->getDirectory()));
88
89
        // return objects
90
        if ($return_as_array === false) {
0 ignored issues
show
Coding Style introduced by
$return_as_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
91
            // create new array to take the SPL FileInfo Objects
92
            $data = new \ArrayObject();
93
94
            // while iterating
95
            foreach ($iterator as $file) {
96
                /*
97
                 * push the SPL FileInfo Objects into the array
98
                 * @see http://www.php.net/~helly/php/ext/spl/classSplFileInfo.html
99
                 */
100
                $data[$file->getFilename()] = $file->getFileInfo();
101
            }
102
103
            $data->ksort();
104
        } else { // return array
105
            // create array
106
            $data = [];
107
108
            // while iterating
109
            foreach ($iterator as $file) {
110
                $wwwpath        = WWW_ROOT . '/' . $this->getDirectory() . '/' . $file->getFilename();
111
                $wwwpath        = str_replace('//', '/', $wwwpath);
112
                $data[$wwwpath] = $file->getFilename();
113
            }
114
        }
115
116
        // return the array with SPL FileInfo Objects
117
        return $data;
118
    }
119
120
    /**
121
     * Returns the filePath with filename.
122
     *
123
     * @return array pathinfo
124
     */
125
    public function filePath($filePath)
126
    {
127
        $fileParts = pathinfo($filePath);
128
129
        if (!isset($fileParts['filename'])) {
130
            $fileParts['filename'] = mb_substr($fileParts['basename'], 0, mb_strrpos($fileParts['basename'], '.'));
131
        }
132
133
        return $fileParts;
134
    }
135
136
    /**
137
     * Calculates the size of a directory (recursiv).
138
     *
139
     * @param $dir Directory Path
140
     *
141
     * @return $size size of directory in bytes
0 ignored issues
show
Documentation introduced by
The doc-type $size could not be parsed: Unknown type name "$size" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
142
     */
143
    public static function size($dir)
144
    {
145
        if (is_dir($dir) === false) {
146
            return false;
147
        }
148
149
        $size = 0;
150
        $dh   = opendir($dir);
151
        while (($entry = readdir($dh)) !== false) {
152
            // exclude ./..
153
            if ($entry === '.' or $entry === '..') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
154
                continue;
155
            }
156
157
            $direntry = $dir . '/' . $entry;
158
159
            if (is_dir($direntry) === false) {
160
                // recursion
161
                $size += self::size($direntry);
162
            } else {
163
                $size += filesize($direntry);
164
            }
165
166
            unset($direntry);
167
        }
168
169
        closedir($dh);
170
171
        return $size;
172
    }
173
174
    /**
175
     * Copy a directory recursively.
176
     *
177
     * @param $source
178
     * @param $destination
179
     * @param $overwrite boolean
180
     */
181
    public function dirCopy($source, $destination, $overwrite = true)
182
    {
183
        $folder_path = '';
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
$folder_path is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
184
185
        $handle = opendir($source);
186
187
        if ($handle) {
188
            while (false !== ($file = readdir($handle))) {
189
                if (mb_substr($file, 0, 1) !== '.') {
190
                    $source_path = $source . $file;
0 ignored issues
show
Coding Style introduced by
$source_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
191
                    $target_path = $destination . $file;
0 ignored issues
show
Coding Style introduced by
$target_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
192
193
                    if (is_file($target_path) === false or $overwrite) {
0 ignored issues
show
Coding Style introduced by
$target_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
194
                        if ([mb_strstr($target_path, '.') === true]) {
0 ignored issues
show
Coding Style introduced by
$target_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
195
                            $folder_path = dirname($target_path);
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
196
                        } else {
197
                            $folder_path = $target_path;
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
198
                        }
199
200
                        while (is_dir(dirname(end($folder_path)))
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
201
                        and dirname(end($folder_path)) !== '/'
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
202
                        and dirname(end($folder_path)) !== '.'
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
203
                        and dirname(end($folder_path)) !== ''
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
204
                        and !preg_match('#^[A-Za-z]+\:\\\$#', dirname(end($folder_path)))) {
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
205
                            array_push($folder_path, dirname(end($folder_path)));
0 ignored issues
show
Coding Style introduced by
$folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
206
                        }
207
208
                        while ($parent_folder_path = array_pop($folder_path)) {
0 ignored issues
show
Coding Style introduced by
$parent_folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
209
                            if (false === is_dir($parent_folder_path) and
0 ignored issues
show
Coding Style introduced by
$parent_folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
210
                                false === @mkdir($parent_folder_path, fileperms($parent_folder_path))) {
0 ignored issues
show
Coding Style introduced by
$parent_folder_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
211
                                throw new \Exception(
212
                                    _('Could not create the directory that should be copied (destination).' .
213
                                      'Probably a permission problem.')
214
                                );
215
                            }
216
                        }
217
218
                        $old = ini_set('error_reporting', 0);
219
                        if (copy($source_path, $target_path) === false) {
0 ignored issues
show
Coding Style introduced by
$source_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
220
                            throw new \Exception('Could not copy the directory. Probably a permission problem.');
221
                        }
222
                        ini_set('error_reporting', $old);
223
                    } elseif (is_dir($source_path)) {
0 ignored issues
show
Coding Style introduced by
$source_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
224
                        if (is_dir($target_path) === false) {
0 ignored issues
show
Coding Style introduced by
$target_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
225
                            if (@mkdir($target_path, fileperms($source_path)) === false) {
0 ignored issues
show
Coding Style introduced by
$target_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
226
                                // nope, not an empty if statement :)
227
                            }
228
                        }
229
                        $this->dir_copy($source_path, $target_path, $overwrite);
0 ignored issues
show
Coding Style introduced by
$source_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method dir_copy() does not seem to exist on object<Koch\Files\Directory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
230
                    }
231
                }
232
            }
233
            closedir($handle);
234
        }
235
    }
236
237
    /**
238
     * Recursively delete directory using PHP iterators.
239
     *
240
     * Uses a CHILD_FIRST RecursiveIteratorIterator to sort files
241
     * before directories, creating a single non-recursive loop
242
     * to delete files/directories in the correct order.
243
     *
244
     * @param string $directory
245
     * @param bool   $delete_dir_itself
246
     *
247
     * @return bool|null
248
     */
249
    public function deleteDir($directory, $delete_dir_itself = false)
0 ignored issues
show
Coding Style introduced by
$delete_dir_itself does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
250
    {
251
        $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
252
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
253
254
        foreach ($ri as $file) {
255
            if ($file->isDir()) {
256
                rmdir($file->getPathname());
257
            } else {
258
                unlink($file->getPathname());
259
            }
260
        }
261
262
        if ($delete_dir_itself === true) {
0 ignored issues
show
Coding Style introduced by
$delete_dir_itself does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
263
            return rmdir($directory);
264
        }
265
    }
266
267
    /**
268
     * Performs a chmod operation.
269
     *
270
     * @param $path
271
     * @param $chmod
272
     * @param $recursive
273
     */
274
    public function chmod($path = '', $chmod = '755', $recursive = false)
0 ignored issues
show
Coding Style introduced by
function chmod() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
275
    {
276
        if (is_dir($path) === false) {
277
            $file_mode = '0' . $chmod;
0 ignored issues
show
Coding Style introduced by
$file_mode does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
278
            $file_mode = octdec($file_mode);
0 ignored issues
show
Coding Style introduced by
$file_mode does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
279
280
            if (chmod($path, $file_mode) === false) {
0 ignored issues
show
Coding Style introduced by
$file_mode does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
281
                return false;
282
            }
283
        } else {
284
            $dir_mode_r = '0' . $chmod;
0 ignored issues
show
Coding Style introduced by
$dir_mode_r does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
285
            $dir_mode_r = octdec($dir_mode_r);
0 ignored issues
show
Coding Style introduced by
$dir_mode_r does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
286
287
            if (chmod($path, $dir_mode_r) === false) {
0 ignored issues
show
Coding Style introduced by
$dir_mode_r does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
288
                return false;
289
            }
290
291
            if ($recursive === false) {
292
                $dh = opendir($path);
293
                while ($file = readdir($dh)) {
294
                    if (mb_substr($file, 0, 1) !== '.') {
295
                        $fullpath = $path . '/' . $file;
296
                        if (!is_dir($fullpath)) {
297
                            $mode = '0' . $chmod;
298
                            $mode = octdec($mode);
299
                            if (chmod($fullpath, $mode) === false) {
300
                                return false;
301
                            }
302
                        } else {
303
                            if ($this->chmod($fullpath, $chmod, true) === false) {
304
                                return false;
305
                            }
306
                        }
307
                    }
308
                }
309
                closedir($dh);
310
            }
311
        }
312
313
        return true;
314
    }
315
}
316