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

SelfRemoving::execute()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0145

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 13
cp 0.8462
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 4
nop 0
crap 2.0145
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\Exception\RuntimeException;
18
use Gennadyx\Skeleton\VarAwareInterface;
19
use Gennadyx\Skeleton\VarAwareTrait;
20
use Symfony\Component\Filesystem\Filesystem;
21
use Symfony\Component\Finder\Finder;
22
23
/**
24
 * Class SelfRemoving
25
 *
26
 * @author Gennady Knyazkin <[email protected]>
27
 */
28
final class SelfRemoving implements ActionInterface, VarAwareInterface
29
{
30
    use VarAwareTrait,
31
        FilesystemAwareTrait;
32
33
    /**
34
     * Function execute
35
     *
36
     * @throws RuntimeException
37
     */
38 2
    public function execute()
39
    {
40 2
        $root = $this->vars['root'];
41
42
        try {
43 2
            $finder     = Finder::create()
44 2
                ->files()
45 2
                ->in($root)
46 2
                ->exclude(basename($this->vars['skeleton']))
47 2
                ->depth(0)
48 2
                ->ignoreDotFiles(false);
49 2
            $this->fs->remove($finder);
50 2
            $this->fs->remove([$root.'/src', $root.'/tests']);
51
        } catch (\Exception $e) {
52
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
53
        }
54 2
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 4
    public function getPriority(): int
60
    {
61 4
        return 2;
62
    }
63
}
64