TraitForFileSystem   D
last analyzed

Complexity

Total Complexity 82

Size/Duplication

Total Lines 413
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 413
loc 413
ccs 185
cts 185
cp 1
rs 4.8717
wmc 82
lcom 1
cbo 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A cd() 4 4 1
C rm() 29 29 8
A scandir() 4 4 3
A stat() 5 5 3
B getDiskTotalSpace() 28 28 3
B getDiskFreeSpace() 36 36 4
A chgrp() 5 5 3
A chmod() 8 8 4
A chown() 8 8 3
A clearstatcache() 7 7 3
C copy() 46 46 13
A mv() 13 13 4
A namePatternMatch() 10 10 3
A getGlob() 4 4 1
A isUploadedFile() 5 5 1
A getRealpathCache() 4 4 1
A getRealpathCacheSize() 4 4 1
B close() 15 15 6
A touch() 12 12 4
A getDirKeys() 4 4 1
A getFileKeys() 4 4 1
C createStructure() 22 22 11

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TraitForFileSystem 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 TraitForFileSystem, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*******************************************************************
3
 * Created by:  Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:36:42
4
 * Contact:     [email protected] - https://okramlabs.com
5
 * @copyright   2015 OkramLabs - https://okramlabs.com
6
 * @license     MIT
7
 *
8
 * Package name: libhowi-filesystem
9
 * @category     HOWI3
10
 * @package      libhowi
11
 * @subpackage   filesystem
12
 * 
13
 * Lang:      PHP
14
 * Encoding:  UTF-8
15
 * File:      TraitForFileSystem.inc
16
 * @link      https://
17
 ********************************************************************
18
 * Contributors:
19
 * @author Marko Kungla <[email protected]>
20
 *           Github: https://github.com/mkungla
21
 ********************************************************************
22
 * Comments:
23
 */
24
namespace HOWI3\libhowi\Filesystem\php5;
25
26
use \RecursiveIteratorIterator;
27
use \HOWI3\libhowi\Filesystem\php5\Objects\DirectoryTreeObject;
28
29 View Code Duplication
trait TraitForFileSystem
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
32
    /**
33
     *
34
     * {@inheritDoc}
35
     *
36
     */
37 12
    public function cd($path = false, $validate_dir_name = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
38
    {
39 12
        return $this->setCwd($path, $validate_dir_name);
0 ignored issues
show
Bug introduced by
It seems like setCwd() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
    }
41
42
    /**
43
     * rmdir
44
     *
45
     * {@inheritDoc}
46
     *
47
     */
48 4
    public function rm($pathname, $shred = false)
49
    {
50 4
        $pathname = $this->makeAbsolute($pathname);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
51 4
        $response = false;
52 4
        if (is_dir($pathname)) {
53
            
54 4
            $files = array_diff(scandir($pathname), 
55
                array(
56 4
                    '.',
57
                    '..'
58 4
                ));
59 4
            foreach ($files as $file) {
60
                
61 2
                (is_dir("$pathname/$file") ? $this->rm("$pathname/$file", $shred) : (! empty($shred) &&
62 2
                     ! $this->isLink($pathname . DIRECTORY_SEPARATOR . $file) ? exec(
0 ignored issues
show
Bug introduced by
It seems like isLink() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63 2
                        "shred -fzu $pathname" . DIRECTORY_SEPARATOR . "$file") : $this->rm(
64 2
                        $pathname . DIRECTORY_SEPARATOR . $file, $shred)));
65 4
            }
66
            
67 4
            $response = rmdir($pathname);
68 4
            $this->info(702, $pathname);
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69 4
            $this->response()->setStatus($response);
0 ignored issues
show
Bug introduced by
It seems like response() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
70 4
        } else {
71 4
            $this->info(702, $pathname);
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72 4
            $this->response()->setStatus($response);
0 ignored issues
show
Bug introduced by
It seems like response() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
73 4
            (! empty($shred) && ! $this->isLink($pathname) ? exec("shred -fzu $pathname") : unlink($pathname));
0 ignored issues
show
Bug introduced by
It seems like isLink() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
74
        }
75 4
        return $response;
76
    }
77
78
    /**
79
     *
80
     * {@inheritDoc}
81
     *
82
     */
83 2
    public function scandir($path = false)
84
    {
85 2
        return ! empty($path) && is_dir($this->makeAbsolute($path)) ? scandir($this->makeAbsolute($path)) : false;
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
86
    }
87
88
    /**
89
     *
90
     * {@inheritDoc}
91
     *
92
     */
93 2
    public function stat($filename = false)
94
    {
95 2
        return ! empty($filename) && file_exists($this->makeAbsolute($filename)) ? stat(
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
96 2
            $this->makeAbsolute($filename)) : false;
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
97
    }
98
99
    /**
100
     *
101
     * {@inheritDoc}
102
     *
103
     */
104 2
    public function getDiskTotalSpace($partition_location = false, $convert = false)
105
    {
106 2
        if (empty($partition_location))
107 2
            $partition_location = $this->getCwd();
0 ignored issues
show
Bug introduced by
It seems like getCwd() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
108
        
109 2
        if (empty($convert))
110 2
            return disk_total_space($partition_location);
111
        
112 2
        $bytestotal = 0;
0 ignored issues
show
Unused Code introduced by
$bytestotal 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...
113
        $suffixes = array(
114 2
            'B',
115 2
            'kB',
116 2
            'MB',
117 2
            'GB',
118 2
            'TB',
119 2
            'PB',
120 2
            'EB',
121 2
            'ZB',
122
            'YB'
123 2
        );
124 2
        $bytestotal = disk_total_space($partition_location);
125
        
126 2
        $base = log($bytestotal, 1024);
127
        return array(
128 2
            round(pow(1024, $base - floor($base)), 2),
129 2
            $suffixes[floor($base)]
130 2
        );
131
    }
132
133
    /**
134
     *
135
     * {@inheritDoc}
136
     *
137
     */
138 2
    public function getDiskFreeSpace($partition_location = false, $convert = false)
139
    {
140 2
        if (empty($partition_location))
141 2
            $partition_location = $this->getCwd();
0 ignored issues
show
Bug introduced by
It seems like getCwd() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
142
        
143 2
        if (empty($convert))
144 2
            return disk_free_space($partition_location);
145
        
146
        $result = [
147 2
            0,
148
            'B'
149 2
        ];
150 2
        $bytestotal = 0;
0 ignored issues
show
Unused Code introduced by
$bytestotal 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...
151
        $suffixes = array(
152 2
            'B',
153 2
            'kB',
154 2
            'MB',
155 2
            'GB',
156 2
            'TB',
157 2
            'PB',
158 2
            'EB',
159 2
            'ZB',
160
            'YB'
161 2
        );
162 2
        $bytestotal = disk_free_space($partition_location);
163
        
164 2
        $base = log($bytestotal, 1024);
165
        
166 2
        if ($bytestotal > 0) {
167
            $result = array(
168 2
                round(pow(1024, $base - floor($base)), 2),
169 2
                $suffixes[floor($base)]
170 2
            );
171 2
        }
172 2
        return $result;
173
    }
174
175
    /**
176
     *
177
     * {@inheritDoc}
178
     *
179
     */
180 2
    public function chgrp($filename = false, $group = false)
181
    {
182 2
        return ! empty($filename) && $this->exists($this->makeAbsolute($filename)) ? chgrp(
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like exists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
183 2
            $this->makeAbsolute($filename), $group) : false;
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
184
    }
185
186
    /**
187
     *
188
     * {@inheritDoc}
189
     *
190
     */
191 2
    public function chmod($filename = false, $mode = false)
192
    {
193 2
        $filename = $this->makeAbsolute($filename);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
194 2
        if (file_exists($filename) && ! empty($mode) && is_int($mode))
195 2
            return chmod($filename, octdec(str_pad($mode, 4, 0, STR_PAD_LEFT)));
196
        else
197 2
            return false;
198
    }
199
200
    /**
201
     *
202
     * {@inheritDoc}
203
     *
204
     */
205 2
    public function chown($filename = false, $user = false)
206
    {
207 2
        $filename = $this->makeAbsolute($filename);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
208 2
        if (file_exists($filename) && ! empty($user))
209 2
            return chown($filename, $user);
210
        else
211 2
            return false;
212
    }
213
214
    /**
215
     *
216
     * {@inheritDoc}
217
     *
218
     */
219 4
    public function clearstatcache($clear_realpath_cache = false, $filename = false)
220
    {
221 4
        if (! empty($filename) && ! empty($clear_realpath_cache))
222 4
            clearstatcache($clear_realpath_cache, $this->makeAbsolute($filename));
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
223
        else
224 4
            clearstatcache();
225 4
    }
226
227
    /**
228
     *
229
     * {@inheritDoc}
230
     *
231
     */
232 2
    public function copy($source = false, $dest = false, $context = false)
233
    {
234 2
        $source = $this->makeAbsolute($source);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
235 2
        $dest = $this->makeAbsolute($dest);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
236
        
237 2
        if (! empty($source) && ! empty($dest) && ! is_dir($source)) {
238
            
239 2
            if (empty($context))
240 2
                return copy($source, $dest);
241
            else
242 2
                return copy($source, $dest, $context);
243 2
        } elseif ((! empty($source) && ! empty($dest)) && is_dir($source) && ! file_exists($dest)) {
244
            
245 2
            $tmp_key = basename($source);
246 2
            $tmp_key2 = basename($dest);
247 2
            $tmp_src_key = $this->dir($tmp_key, dirname($source));
0 ignored issues
show
Bug introduced by
It seems like dir() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
248
            
249 2
            $this->dir($tmp_key2, dirname($dest), false, $tmp_src_key->getPerms());
0 ignored issues
show
Bug introduced by
It seems like dir() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
250 2
            $this->close($tmp_key);
0 ignored issues
show
Documentation introduced by
$tmp_key is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
251 2
            $this->close($tmp_key2);
0 ignored issues
show
Documentation introduced by
$tmp_key2 is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
252
            
253 2
            foreach ($iterator = new RecursiveIteratorIterator(
254 2
                new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),  // DirectoryTreeObject::CURRENT_AS_FILEINFO
255 2
                \RecursiveIteratorIterator::SELF_FIRST) as $item) {
256 2
                if ($item->isDir()) {
257 2
                    if (empty($context)) {
258 2
                        mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 
259 2
                            octdec(str_pad($iterator->getPerms(), 4, 0, STR_PAD_LEFT)));
260 2
                    } 
261
262
                    else
263 2
                        mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 
264 2
                            octdec(str_pad($iterator->getPerms(), 4, 0, STR_PAD_LEFT)), false, $context);
265 2
                } else {
266 2
                    if (empty($context))
267 2
                        $this->copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
0 ignored issues
show
Documentation introduced by
$dest . DIRECTORY_SEPARA...rator->getSubPathName() is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
                    else
269 2
                        $this->copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 
0 ignored issues
show
Documentation introduced by
$dest . DIRECTORY_SEPARA...rator->getSubPathName() is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
270 2
                            $context);
271
                }
272 2
            }
273
            
274 2
            return true;
275
        } else
276 2
            return false;
277
    }
278
279
    /**
280
     *
281
     * {@inheritDoc}
282
     *
283
     */
284 2
    public function mv($oldname = false, $newname = false, $context = false)
285
    {
286 2
        if (empty($oldname) || empty($newname))
287 2
            return false;
288
        
289 2
        $oldname = $this->makeAbsolute($oldname);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
290 2
        $newname = $this->makeAbsolute($newname);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
291
        
292 2
        if (! empty($context))
293 2
            return rename($oldname, $newname, $context);
294
        
295 2
        return rename($oldname, $newname);
296
    }
297
298
    /**
299
     *
300
     * {@inheritDoc}
301
     *
302
     */
303 2
    public function namePatternMatch($pattern = false, $string = false, $flags = false)
304
    {
305 2
        if (empty($pattern))
306 2
            return false;
307
        
308 2
        if (! empty($flags))
309 2
            return fnmatch($pattern, $string, $flags);
310
        else
311 2
            return fnmatch($pattern, $string);
312
    }
313
314
    /**
315
     *
316
     * {@inheritDoc}
317
     *
318
     */
319 2
    public function getGlob($pattern = false, $flags = 0)
320
    {
321 2
        return glob($pattern, $flags);
322
    }
323
324
    /**
325
     *
326
     * {@inheritDoc}
327
     *
328
     */
329 2
    public function isUploadedFile($filename = false)
330
    {
331 2
        $filename = $this->makeAbsolute($filename);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
332 2
        return is_uploaded_file($filename);
333
    }
334
335
    /**
336
     *
337
     * {@inheritDoc}
338
     *
339
     */
340 2
    public function getRealpathCache()
341
    {
342 2
        return realpath_cache_get();
343
    }
344
345
    /**
346
     *
347
     * {@inheritDoc}
348
     *
349
     */
350 2
    public function getRealpathCacheSize()
351
    {
352 2
        return realpath_cache_size();
353
    }
354
355
    /**
356
     *
357
     * {@inheritDoc}
358
     *
359
     */
360 4
    public function close($keyword = false)
361
    {
362 4
        if (!empty($keyword) && array_key_exists($keyword, $this->dirkeys) &&
0 ignored issues
show
Bug introduced by
The property dirkeys does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
363 4
             array_key_exists($this->dirkeys[$keyword], $this->dirs)) {
0 ignored issues
show
Bug introduced by
The property dirs does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
364 4
            unset($this->dirs[$this->dirkeys[$keyword]]);
365 4
            unset($this->dirkeys[$keyword]);
366 4
            return true;
367 2
        } elseif(!empty($keyword) && array_key_exists($keyword,$this->files)) {
0 ignored issues
show
Bug introduced by
The property files does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
368 2
            $this->files[$keyword] = null;
369 2
            unset($this->files[$keyword]);
370 2
            return true;
371
        } else {
372 2
            return false;
373
        }
374
    }
375
376
    /**
377
     *
378
     * {@inheritDoc}
379
     *
380
     */
381 2
    public function touch($filename = false, $time = false, $atime = false)
382
    {
383 2
        if (empty($filename))
384 2
            return false;
385
        
386 2
        $filename = $this->makeAbsolute($filename);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
387
        
388 2
        $time = ! empty($time) ? $time : time();
389 2
        $atime = ! empty($atime) ? $atime : time();
390
        
391 2
        return touch($filename, $time, $atime);
392
    }
393
394
    /**
395
     *
396
     * {@inheritDoc}
397
     *
398
     */
399 2
    public function getDirKeys()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
400
    {
401 2
        return $this->dirkeys;
402
    }
403
404
    /**
405
     *
406
     * {@inheritDoc}
407
     *
408
     */
409 2
    public function getFileKeys()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
410
    {
411 2
        return $this->files;
412
    }
413
    
414
    /**
415
     *
416
     * {@inheritDoc}
417
     *
418
     */
419 4
    public function createStructure($rootpath, $data_array, $skip_debug = false)
420
    {
421 4
        $absolute_path = $this->makeAbsolute($rootpath);
0 ignored issues
show
Bug introduced by
It seems like makeAbsolute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
422 4
        if (empty($skip_debug))
423 4
            $this->debug(810);
0 ignored issues
show
Bug introduced by
It seems like debug() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
424 4
        if (empty($rootpath) || ! is_array($data_array) ||
425 4
             (! $this->isWritable($absolute_path) && ! $this->isWritable(dirname($absolute_path))))
0 ignored issues
show
Bug introduced by
It seems like isWritable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
426 4
            return $this->warning(506) && false;
0 ignored issues
show
Bug introduced by
It seems like warning() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
427
        
428 4
        if (! $this->isDir($absolute_path))
0 ignored issues
show
Bug introduced by
It seems like isDir() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
429 4
            mkdir($absolute_path, 0755, true);
430
        
431 4
        foreach ($data_array as $key => $val) {
432 4
            if (is_array($val))
433 4
                ! $this->createStructure($absolute_path . DIRECTORY_SEPARATOR . $key, $val, true);
434
            else
435 4
                touch($absolute_path . DIRECTORY_SEPARATOR . $val);
436 4
        }
437 4
        if (empty($skip_debug))
438 4
            $this->info(704, $rootpath);
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
439 4
        return true;
440
    }
441
}
442