FileDeleter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A perform() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\FileOperations;
6
7
/**
8
 * Gets the contents of our previously declared iterator
9
 */
10
class FileDeleter extends FileSelection
11
{
12
    /**
13
     * Contains the full path of all files that were deleted
14
     * @var array
15
     */
16
    public $deletedFiles = [];
17
18
    /**
19
     * Performs the actual deletion of the previous delete selection
20
     *
21
     * @return FileDeleter Returns same object for easy method concatenation
22
     */
23
    public function perform(): FileActionInterface
24
    {
25
        foreach ($this->iterator as $file) {
26
            $fullFile = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
27
            $this->deletedFiles[] = $fullFile;
28
            $this->logger->info('Removing', ['file' => $fullFile, 'dry-run' => $this->isTestMode]);
29
            if ($this->isTestMode === false) {
30
                if ($file->isDir()) {
31
                    rmdir($fullFile);
32
                } else {
33
                    unlink($fullFile);
34
                }
35
            }
36
        }
37
38
        return $this;
39
    }
40
}
41