FileContentsGetter::perform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
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