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 ( ebde4e...a45a6d )
by Borut
02:45
created

Storage   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 3 Features 0
Metric Value
wmc 11
c 5
b 3
f 0
lcom 1
cbo 1
dl 0
loc 96
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B prepare() 0 26 1
A prepareFolders() 0 16 3
B prepareUploadsFolder() 0 26 5
A prepareLogFiles() 0 10 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/cache',
20
            'var/cache/assetic',
21
            'var/cache/file',
22
            'var/cache/http',
23
            'var/cache/profiler',
24
            'var/cache/proxy',
25
            'var/cache/template',
26
            'var/cache/security',
27
            'var/database',
28
            'var/logs',
29
            'var/sessions',
30
            'var/mailer',
31
            'var/mailer/spool',
32
        ));
33
34
        self::prepareLogFiles(array(
35
            'var/logs/development.log',
36
            'var/logs/testing.log',
37
            'var/logs/staging.log',
38
            'var/logs/production.log',
39
        ));
40
    }
41
42
    /**
43
     * Prepare the folders for storage.
44
     */
45
    public static function prepareFolders(array $paths = array(), $uploadsPath = false)
46
    {
47
        if (empty($paths)) {
48
            return false;
49
        }
50
51
        $fs = new Filesystem();
52
53
        foreach ($paths as $path) {
54
            $fs->remove($path);
55
            $fs->mkdir($paths);
56
            $fs->chmod($path, 0777);
57
        }
58
59
        self::prepareUploadsFolder($uploadsPath);
60
    }
61
62
    /**
63
     * Prepare the uploads folder (so images can be uploaded).
64
     */
65
    public static function prepareUploadsFolder($uploadsDirectory)
66
    {
67
        if (!$uploadsDirectory) {
68
            return false;
69
        }
70
71
        $fs = new Filesystem();
72
73
        $uploadsDirectory = 'web/assets/uploads';
74
75
        if (!$fs->exists($uploadsDirectory)) {
76
            $fs->mkdir($uploadsDirectory, 0755);
77
        }
78
79
        $user = PHP_OS == 'Darwin' // Fix for OSX
80
            ? get_current_user()
81
            : 'www-data'
82
        ;
83
84
        try {
85
            $fs->chown($uploadsDirectory, $user);
86
            $fs->chmod($uploadsDirectory, 0755);
87
        } catch (\Exception $e) {
88
            // Not sure If we need to show this errors. Let's think about that...
89
        }
90
    }
91
92
    /**
93
     * Prepare the log files.
94
     */
95
    public static function prepareLogFiles(array $paths)
96
    {
97
        $fs = new Filesystem();
98
99
        foreach ($paths as $path) {
100
            $fs->remove($path);
101
            $fs->touch($path);
102
            $fs->chmod($path, 0777);
103
        }
104
    }
105
}
106