GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 9e9d51...fc7292 )
by Borut
03:13
created

Storage::prepareFolders()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 11
Ratio 55 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 11
loc 20
rs 8.8571
cc 5
eloc 11
nc 4
nop 2
1
<?php
2
3
namespace Application\Tool;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
/**
8
 * @author Borut Balažek <[email protected]>
9
 */
10
class Storage
11
{
12
    /**
13
     * Prepare all the folders and files for storage.
14
     */
15
    public static function prepare()
16
    {
17
        self::prepareFolders(array(
18
            'var',
19
            'var/backups',
20
            'var/backups/database',
21
            'var/cache',
22
            'var/cache/assetic',
23
            'var/cache/file',
24
            'var/cache/http',
25
            'var/cache/profiler',
26
            'var/cache/proxy',
27
            'var/cache/template',
28
            'var/cache/security',
29
            'var/database',
30
            'var/logs',
31
            'var/sessions',
32
            'var/mailer',
33
            'var/mailer/spool',
34
        ));
35
36
        self::prepareLogFiles(array(
37
            'var/logs/development.log',
38
            'var/logs/testing.log',
39
            'var/logs/staging.log',
40
            'var/logs/production.log',
41
        ));
42
    }
43
44
    /**
45
     * Prepare the folders for storage.
46
     */
47
    public static function prepareFolders(array $paths = array(), $removeIfExists = false)
48
    {
49
        if (empty($paths)) {
50
            return false;
51
        }
52
53
        $fs = new Filesystem();
54
55 View Code Duplication
        foreach ($paths as $path) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
            if (
57
                $removeIfExists &&
58
                $fs->exists($path)
59
            ) {
60
                $fs->remove($path);
61
            }
62
63
            $fs->mkdir($paths);
64
            $fs->chmod($path, 0777);
65
        }
66
    }
67
68
    /**
69
     * Prepare the uploads folder (so images can be uploaded).
70
     */
71
    public static function prepareUploadsFolder($uploadsDirectory)
72
    {
73
        if (!$uploadsDirectory) {
74
            return false;
75
        }
76
77
        $fs = new Filesystem();
78
79
        $uploadsDirectory = 'web/assets/uploads';
80
81
        if (!$fs->exists($uploadsDirectory)) {
82
            $fs->mkdir($uploadsDirectory, 0755);
83
        }
84
85
        $user = PHP_OS == 'Darwin' // Fix for OSX
86
            ? get_current_user()
87
            : 'www-data'
88
        ;
89
90
        try {
91
            $fs->chown($uploadsDirectory, $user);
92
            $fs->chmod($uploadsDirectory, 0755);
93
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
94
        }
95
    }
96
97
    /**
98
     * Prepare the log files.
99
     */
100
    public static function prepareLogFiles(array $paths, $removeIfExists = false)
101
    {
102
        $fs = new Filesystem();
103
104 View Code Duplication
        foreach ($paths as $path) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
            if (
106
                $removeIfExists &&
107
                $fs->exists($path)
108
            ) {
109
                $fs->remove($path);
110
            }
111
112
            $fs->touch($path);
113
            $fs->chmod($path, 0777);
114
        }
115
    }
116
}
117