Passed
Pull Request — master (#572)
by Dmitriy
02:20 queued 52s
created

Installer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A chmodRecursive() 0 9 2
A postUpdate() 0 5 1
A copyEnvFile() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure;
6
7
use Composer\Script\Event;
8
use FilesystemIterator as FSIterator;
9
use RecursiveDirectoryIterator as DirIterator;
10
use RecursiveIteratorIterator as RIterator;
11
12
final class Installer
13
{
14
    /**
15
     * @psalm-suppress UndefinedClass
16
     */
17
    public static function postUpdate(Event $event = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

17
    public static function postUpdate(/** @scrutinizer ignore-unused */ Event $event = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        self::copyEnvFile();
20
        self::chmodRecursive('runtime', 0777);
21
        self::chmodRecursive('public/assets', 0777);
22
    }
23
24
    private static function chmodRecursive(string $path, int $mode): void
25
    {
26
        chmod($path, $mode);
27
        $iterator = new RIterator(
28
            new DirIterator($path, FSIterator::SKIP_DOTS | FSIterator::CURRENT_AS_PATHNAME),
29
            RIterator::SELF_FIRST
30
        );
31
        foreach ($iterator as $item) {
32
            chmod($item, $mode);
33
        }
34
    }
35
36
    public static function copyEnvFile(): void
37
    {
38
        if (!file_exists('.env')) {
39
            copy('.env.example', '.env');
40
        }
41
    }
42
}
43