FileProcessor::process()   C
last analyzed

Complexity

Conditions 7
Paths 13

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7.0572

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 17
cts 19
cp 0.8947
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 17
nc 13
nop 1
crap 7.0572
1
<?php
2
3
namespace Paro\EnvironmentParameters;
4
5
use Composer\IO\IOInterface;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
class FileProcessor
9
{
10
    /**
11
     * @var IOInterface
12
     */
13
    private $io;
14
    /**
15
     * @var FileHandler
16
     */
17
    private $fileHandler;
18
    /**
19
     * @var Filesystem
20
     */
21
    private $fs;
22
23
    /**
24
     * FileProcessor constructor.
25
     * @param Filesystem $fs
26
     * @param IOInterface $io
27
     * @param FileHandler $fileHandler
28
     */
29 2
    public function __construct(Filesystem $fs, IOInterface $io, FileHandler $fileHandler)
30
    {
31 2
        $this->fs = $fs;
32 2
        $this->io = $io;
33 2
        $this->fileHandler = $fileHandler;
34 2
    }
35
36
    /**
37
     * @param $configs
38
     * @return bool
39
     */
40 2
    public function process($configs)
41
    {
42 2
        if (!isset($configs['files'])) {
43
            return true;
44
        }
45
46 2
        $files = $configs['files'];
47 2
        if (array_keys($files) !== range(0, count($files) - 1)) {
48 1
            $files = array($files);
49 1
        }
50 2
        foreach ($files as $file) {
51 2
            if (!is_array($file)) {
52
                throw new \InvalidArgumentException('The extra.environment-parameters.files setting must be an array.');
53
            }
54
55 2
            $path = $this->fileHandler->findFile($this->fileHandler->processEnvironmentalVariable($file['file']));
56 2
            $destination = $configs['build-folder'] . '/' . (isset($file['name']) ? $file['name'] : $path);
57 2
            $this->fs->copy($path, $destination, true);
58 2
            if (isset($file['name'])) {
59 1
                $this->io->write(sprintf('<info>Copying the "%s" into "%s" file</info>', $path, $destination));
60 1
            } else {
61 1
                $this->io->write(sprintf('<info>Copying the "%s" file</info>', $path));
62
            }
63
64 2
        }
65 2
        return true;
66
    }
67
68
}
69