Completed
Push — master ( 379248...c97627 )
by ARCANEDEV
04:05
created

FoldersPermissionsComposer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compose() 0 11 1
A checkPermissions() 0 9 1
A getFolderPermission() 0 4 1
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_NAME = 'foundation::system.information._includes.folders-permissions';
18
19
    /* ------------------------------------------------------------------------------------------------
20
     |  Main Functions
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->checkPermissions([
31
            'storage/app/'       => 775,
32
            'storage/framework/' => 775,
33
            'storage/logs/'      => 775,
34
            'bootstrap/cache/'   => 775,
35
        ]);
36
37
        $view->with('permissions', $permissions);
38
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Other Functions
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * Check the permissions.
46
     *
47
     * @param  array  $folders
48
     *
49
     * @return \Illuminate\Support\Collection
50
     */
51
    private function checkPermissions(array $folders)
52
    {
53
        return collect($folders)->transform(function ($permission, $folder) {
54
            return [
55
                'chmod'   => $permission,
56
                'allowed' => $this->getFolderPermission($folder) >= $permission
57
            ];
58
        });
59
    }
60
61
    /**
62
     * Get a folder permission.
63
     *
64
     * @param  string  $folder
65
     *
66
     * @return int
67
     */
68
    private function getFolderPermission($folder)
69
    {
70
        return (int) substr(sprintf('%o', fileperms(base_path($folder))), -4);
71
    }
72
}
73