InstallFiles   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 17
cts 19
cp 0.8947

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriority() 0 4 1
B execute() 0 25 3
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\Action\Traits\VarAwareTrait;
18
use Gennadyx\Skeleton\VarAwareInterface;
19
use Stringy\StaticStringy;
20
use Symfony\Component\Finder\Finder;
21
22
/**
23
 * Class InstallFiles
24
 *
25
 * @author Gennady Knyazkin <[email protected]>
26
 */
27
final class InstallFiles implements ActionInterface, VarAwareInterface
28
{
29
    use VarAwareTrait,
30
        FilesystemAwareTrait;
31
32 2
    public function execute()
33
    {
34
        try {
35
            /** @var Finder $finder */
36 2
            $finder     = Finder::create()
37 2
                ->files()
38 2
                ->in($this->vars['skeleton'])
39 2
                ->ignoreDotFiles(false);
40
41 2
            foreach ($finder as $file) {
42 2
                $target = str_replace(
43 2
                    $this->vars['skeleton'],
44 2
                    $this->vars['root'],
45 2
                    $file->getRealPath()
46
                );
47 2
                $this->fs->rename(
48 2
                    $file->getRealPath(),
49 2
                    (string)StaticStringy::removeRight($target, '.skltn'),
50 2
                    true
51
                );
52
            }
53
        } catch (\Exception $e) {
54
            throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
55
        }
56 2
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 4
    public function getPriority(): int
62
    {
63 4
        return 3;
64
    }
65
}
66