Completed
Push — master ( cea9b4...a629b9 )
by ARCANEDEV
13:47
created

FoldersPermissionsComposer::checkPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 2
cp 0
crap 2
rs 9.6666
1
<?php namespace Arcanesoft\Foundation\ViewComposers\System;
2
3
use Illuminate\View\View;
4
5
/**
6
 * Class     FoldersPermissionsComposer
7
 *
8
 * @package  Arcanesoft\Foundation\ViewComposers\System
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class FoldersPermissionsComposer
12
{
13
    /* -----------------------------------------------------------------
14
     |  Constants
15
     | -----------------------------------------------------------------
16
     */
17
    const VIEW = 'foundation::admin.system.information._includes.folders-permissions';
18
19
    /* -----------------------------------------------------------------
20
     |  Main Methods
21
     | -----------------------------------------------------------------
22
     */
23
    /**
24
     * Compose the view.
25
     *
26
     * @param  \Illuminate\View\View  $view
27
     */
28
    public function compose(View $view)
29
    {
30
        $permissions = $this->prepare([
31
            'storage/app/',
32
            'storage/framework/',
33
            'storage/logs/',
34
            'bootstrap/cache/',
35
        ]);
36
37
        $view->with('permissions', $permissions);
38
    }
39
40
    /* -----------------------------------------------------------------
41
     |  Other Methods
42
     | -----------------------------------------------------------------
43
     */
44
    /**
45
     * Prepare the permissions.
46
     *
47
     * @param  array  $folders
48
     *
49
     * @return \Illuminate\Support\Collection
50
     */
51
    private function prepare(array $folders)
52
    {
53
        return collect($folders)->mapWithKeys(function ($folder) {
54
            $path = base_path($folder);
55
56
            return [
57
                $folder => [
58
                    'chmod'    => (int) substr(sprintf('%o', fileperms($path)), -4),
59
                    'writable' => is_writable($path),
60
                ],
61
            ];
62
        });
63
    }
64
}
65