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

Unlink   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A once() 0 10 2
A __invoke() 0 10 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