FileProcessor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 61
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C process() 0 27 7
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