SelfRemoving   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 13
cts 15
cp 0.8667

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriority() 0 4 1
A execute() 0 17 2
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\Exception\RuntimeException;
19
use Gennadyx\Skeleton\VarAwareInterface;
20
use Symfony\Component\Finder\Finder;
21
22
/**
23
 * Class SelfRemoving
24
 *
25
 * @author Gennady Knyazkin <[email protected]>
26
 */
27
final class SelfRemoving implements ActionInterface, VarAwareInterface
28
{
29
    use VarAwareTrait,
30
        FilesystemAwareTrait;
31
32
    /**
33
     * Function execute
34
     *
35
     * @throws RuntimeException
36
     */
37 2
    public function execute()
38
    {
39 2
        $root = $this->vars['root'];
40
41
        try {
42 2
            $finder     = Finder::create()
43 2
                ->files()
44 2
                ->in($root)
45 2
                ->exclude(basename($this->vars['skeleton']))
46 2
                ->depth(0)
47 2
                ->ignoreDotFiles(false);
48 2
            $this->fs->remove($finder);
0 ignored issues
show
Documentation introduced by
$finder is of type object<Symfony\Component\Finder\Finder>, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49 2
            $this->fs->remove([$root.'/src', $root.'/tests']);
0 ignored issues
show
Documentation introduced by
array($root . '/src', $root . '/tests') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        } catch (\Exception $e) {
51
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
52
        }
53 2
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 4
    public function getPriority(): int
59
    {
60 4
        return 2;
61
    }
62
}
63