Conditions | 10 |
Paths | 20 |
Total Lines | 51 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
26 | public function check() |
||
27 | { |
||
28 | if ($this->path[0] == '/') { |
||
29 | $filename = $this->path; |
||
30 | } else { |
||
31 | $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path); |
||
32 | } |
||
33 | |||
34 | if (file_exists($filename)) { |
||
35 | $isWriteable = is_writeable($filename); |
||
36 | } else { |
||
37 | $isWriteable = is_writeable(dirname($filename)); |
||
38 | } |
||
39 | |||
40 | if (!$isWriteable) { |
||
41 | if (function_exists('posix_getgroups')) { |
||
42 | $userID = posix_geteuid(); |
||
43 | $user = posix_getpwuid($userID); |
||
44 | |||
45 | $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename)); |
||
46 | $currentOwner = posix_getpwuid($currentOwnerID); |
||
47 | |||
48 | $message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is currently owned by '$currentOwner[name]'. "; |
||
49 | |||
50 | if ($user['name'] == $currentOwner['name']) { |
||
51 | $message .= "We recommend that you make the file writeable."; |
||
52 | } else { |
||
53 | $groups = posix_getgroups(); |
||
54 | $groupList = array(); |
||
55 | foreach ($groups as $group) { |
||
56 | $groupInfo = posix_getgrgid($group); |
||
57 | if (in_array($currentOwner['name'], $groupInfo['members'])) { |
||
58 | $groupList[] = $groupInfo['name']; |
||
59 | } |
||
60 | } |
||
61 | if ($groupList) { |
||
62 | $message .= " We recommend that you make the file group-writeable and change the group to one of these groups:\n - ". implode("\n - ", $groupList) |
||
63 | . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename"; |
||
64 | } else { |
||
65 | $message .= " There is no user-group that contains both the web-server user and the owner of this file. Change the ownership of the file, create a new group, or temporarily make the file writeable by everyone during the install process."; |
||
66 | } |
||
67 | } |
||
68 | } else { |
||
69 | $message = "The webserver user needs to be able to write to this file:\n$filename"; |
||
70 | } |
||
71 | |||
72 | return array(EnvironmentCheck::ERROR, $message); |
||
73 | } |
||
74 | |||
75 | return array(EnvironmentCheck::OK,''); |
||
76 | } |
||
77 | } |
||
78 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.