Passed
Push — ofaj ( d9b422...0f9380 )
by
unknown
11:25 queued 11s
created

PersonalDriver::getConfiguration()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 75
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 58
nc 4
nop 0
dl 0
loc 75
rs 8.9163
c 1
b 1
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Component\Editor\Driver;
5
6
/**
7
 * Class PersonalDriver.
8
 *
9
 * @todo add more checks in upload/rm
10
 */
11
class PersonalDriver extends Driver implements DriverInterface
12
{
13
    public $name = 'PersonalDriver';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function setup()
19
    {
20
        $userId = api_get_user_id();
21
        $dir = \UserManager::getUserPathById($userId, 'system');
22
        if (!empty($dir)) {
23
            if (!is_dir($dir)) {
24
                mkdir($dir);
25
            }
26
27
            if (!is_dir($dir.'my_files')) {
28
                mkdir($dir.'my_files');
29
            }
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getConfiguration()
37
    {
38
        if ($this->allow()) {
39
            $userId = api_get_user_id();
40
41
            if (!empty($userId)) {
42
                // Adding user personal files
43
                $dir = \UserManager::getUserPathById($userId, 'system');
44
                $dirWeb = \UserManager::getUserPathById($userId, 'web');
45
                $mimeType = [
46
                    'application',
47
                    'text/html',
48
                    'text/javascript',
49
                    'text/ecmascript',
50
                    'image/svg+xml',
51
                    'image/svg',
52
                ];
53
54
                $driver = [
55
                    'driver' => 'PersonalDriver',
56
                    'alias' => get_lang('MyFiles'),
57
                    'path' => $dir.'my_files',
58
                    'URL' => $dirWeb.'my_files',
59
                    'accessControl' => [$this, 'access'],
60
                    'uploadDeny' => $mimeType,
61
                    'disabled' => [
62
                        'duplicate',
63
                        //'rename',
64
                        //'mkdir',
65
                        'mkfile',
66
                        'copy',
67
                        'cut',
68
                        'paste',
69
                        'edit',
70
                        'extract',
71
                        'archive',
72
                        'help',
73
                        'resize',
74
                    ],
75
                ];
76
                if (api_get_configuration_value('social_myfiles_office_files_upload_allowed')) {
77
                    //Allow all office suite documents to be uploaded in the "My files" section of the social network
78
                    $driver['uploadOrder'] = ['deny', 'allow'];
79
                    $driver['uploadAllow'] = [
80
                        'application/pdf',
81
                        'application/msword',
82
                        'application/vnd.ms-excel',
83
                        'application/vnd.ms-excel.addin.macroEnabled.12',
84
                        'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
85
                        'application/vnd.ms-excel.sheet.macroEnabled.12',
86
                        'application/vnd.ms-excel.template.macroEnabled.12',
87
                        'application/vnd.ms-powerpoint',
88
                        'application/vnd.ms-powerpoint.addin.macroEnabled.12',
89
                        'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
90
                        'application/vnd.ms-powerpoint.slide.macroenabled.12',
91
                        'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
92
                        'application/vnd.ms-powerpoint.template.macroEnabled.12',
93
                        'application/vnd.ms-word.document.macroEnabled.12',
94
                        'application/vnd.ms-word.template.macroEnabled.12',
95
                        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
96
                        'application/vnd.openxmlformats-officedocument.presentationml.slide',
97
                        'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
98
                        'application/vnd.openxmlformats-officedocument.presentationml.template',
99
                        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
100
                        'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
101
                        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
102
                        'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
103
                    ];
104
                }
105
106
                return $driver;
107
            }
108
        }
109
110
        return [];
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function upload($fp, $dst, $name, $tmpname, $hashes = [])
117
    {
118
        $this->setConnectorFromPlugin();
119
        if ($this->allow()) {
120
            return parent::upload($fp, $dst, $name, $tmpname);
121
        }
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function rm($hash)
128
    {
129
        $this->setConnectorFromPlugin();
130
131
        if ($this->allow()) {
132
            return parent::rm($hash);
133
        }
134
    }
135
136
    /**
137
     * @return bool
138
     */
139
    public function allow()
140
    {
141
        //if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
142
        return !api_is_anonymous();
143
    }
144
}
145