Installer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 3
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A copyEnvFile() 0 4 2
A postUpdate() 0 4 1
A chmodRecursive() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App;
6
7
use FilesystemIterator as FSIterator;
8
use RecursiveDirectoryIterator as DirIterator;
9
use RecursiveIteratorIterator as RIterator;
10
11
final class Installer
12
{
13
    /**
14
     * @psalm-suppress UndefinedClass
15
     */
16
    public static function postUpdate(): void
17
    {
18
        self::chmodRecursive('runtime', 0777);
19
        self::chmodRecursive('public/assets', 0777);
20
    }
21
22
    private static function chmodRecursive(string $path, int $mode): void
23
    {
24
        chmod($path, $mode);
25
26
        /** @psalm-var iterable<array-key, string> $iterator */
27
        $iterator = new RIterator(
28
            new DirIterator($path, FSIterator::SKIP_DOTS | FSIterator::CURRENT_AS_PATHNAME),
29
            RIterator::SELF_FIRST
30
        );
31
32
        foreach ($iterator as $item) {
33
            chmod($item, $mode);
34
        }
35
    }
36
37
    public static function copyEnvFile(): void
38
    {
39
        if (!file_exists('.env')) {
40
            copy('.env.example', '.env');
41
        }
42
    }
43
}
44