Completed
Push — master ( b6a150...3c3902 )
by Gennady
02:57
created

InstallFiles::execute()   B

Complexity

Conditions 3
Paths 6

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3.0146

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 15
cts 17
cp 0.8824
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 6
nop 0
crap 3.0146
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the skeleton package.
7
 *
8
 * (c) Gennady Knyazkin <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Gennadyx\Skeleton\Action;
15
16
use Gennadyx\Skeleton\Action\Traits\FilesystemAwareTrait;
17
use Gennadyx\Skeleton\VarAwareInterface;
18
use Gennadyx\Skeleton\VarAwareTrait;
19
use Stringy\StaticStringy;
20
use Symfony\Component\Filesystem\Filesystem;
21
use Symfony\Component\Finder\Finder;
22
23
/**
24
 * Class InstallFiles
25
 *
26
 * @author Gennady Knyazkin <[email protected]>
27
 */
28
final class InstallFiles implements ActionInterface, VarAwareInterface
29
{
30
    use VarAwareTrait,
31
        FilesystemAwareTrait;
32
33 2
    public function execute()
34
    {
35
        try {
36
            /** @var Finder $finder */
37 2
            $finder     = Finder::create()
38 2
                ->files()
39 2
                ->in($this->vars['skeleton'])
40 2
                ->ignoreDotFiles(false);
41
42 2
            foreach ($finder as $file) {
43 2
                $target = str_replace(
44 2
                    $this->vars['skeleton'],
45 2
                    $this->vars['root'],
46 2
                    $file->getRealPath()
47
                );
48 2
                $this->fs->rename(
49 2
                    $file->getRealPath(),
50 2
                    (string)StaticStringy::removeRight($target, '.skltn'),
51 2
                    true
52
                );
53
            }
54
        } catch (\Exception $e) {
55
            throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
56
        }
57 2
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 4
    public function getPriority(): int
63
    {
64 4
        return 3;
65
    }
66
}
67