FileContentsGetter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A perform() 0 12 3
A getOutput() 0 6 2
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 FileContentsGetter extends FileSelection
11
{
12
    protected $output = [];
13
14
    public function perform(): FileActionInterface
15
    {
16
        foreach ($this->iterator as $file) {
17
            if (!$file->isDir()) {
18
                $filename = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
19
                $this->logger->info('Getting contents', ['file' => $filename, 'dry-run' => $this->isTestMode]);
20
                $this->output[$filename] = file_get_contents($filename);
21
            }
22
        }
23
24
        return $this;
25
    }
26
27
    /**
28
     * Will return the output generated by the perform action
29
     * @return \Generator
30
     */
31
    public function getOutput(): \Generator
32
    {
33
        foreach ($this->output as $filename => $result) {
34
            yield $filename => $result;
35
        }
36
    }
37
}
38