Completed
Push — app ( d2c122 )
by Akihito
02:39
created

Unlink::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.2
cc 4
eloc 6
nc 4
nop 1
crap 4
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package;
8
9
final class Unlink
10
{
11
    /**
12
     * @var array
13
     */
14
    private static $unlinkedPath = [];
15
16 11
    public function __invoke(string $path)
17
    {
18 11
        if (file_exists($path . '/.do_not_clear')) {
19 11
            return;
20
        }
21 11
        foreach (\glob(\rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*') as $file) {
22 11
            \is_dir($file) ? $this->__invoke($file) : \unlink($file);
23 11
            @\rmdir($file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
24
        }
25 11
    }
26
27 25
    public function once(string $path) : bool
28
    {
29 25
        if (in_array($path, self::$unlinkedPath, true)) {
30 20
            return true;
31
        }
32 7
        self::$unlinkedPath[] = $path;
33 7
        $this->__invoke($path);
34
35 7
        return false;
36
    }
37
}
38