Conditions | 10 |
Paths | 20 |
Total Lines | 55 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
32 | public function check() |
||
33 | { |
||
34 | if ($this->path[0] == '/') { |
||
35 | $filename = $this->path; |
||
36 | } else { |
||
37 | $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path); |
||
38 | } |
||
39 | |||
40 | if (file_exists($filename)) { |
||
41 | $isWriteable = is_writeable($filename); |
||
42 | } else { |
||
43 | $isWriteable = is_writeable(dirname($filename)); |
||
44 | } |
||
45 | |||
46 | if (!$isWriteable) { |
||
47 | if (function_exists('posix_getgroups')) { |
||
48 | $userID = posix_geteuid(); |
||
49 | $user = posix_getpwuid($userID); |
||
50 | |||
51 | $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename)); |
||
52 | $currentOwner = posix_getpwuid($currentOwnerID); |
||
53 | |||
54 | $message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is " |
||
55 | . "currently owned by '$currentOwner[name]'. "; |
||
56 | |||
57 | if ($user['name'] == $currentOwner['name']) { |
||
58 | $message .= 'We recommend that you make the file writeable.'; |
||
59 | } else { |
||
60 | $groups = posix_getgroups(); |
||
61 | $groupList = []; |
||
62 | foreach ($groups as $group) { |
||
63 | $groupInfo = posix_getgrgid($group); |
||
64 | if (in_array($currentOwner['name'], $groupInfo['members'])) { |
||
65 | $groupList[] = $groupInfo['name']; |
||
66 | } |
||
67 | } |
||
68 | if ($groupList) { |
||
|
|||
69 | $message .= " We recommend that you make the file group-writeable and change the group to " |
||
70 | . "one of these groups:\n - " . implode("\n - ", $groupList) |
||
71 | . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename"; |
||
72 | } else { |
||
73 | $message .= " There is no user-group that contains both the web-server user and the owner " |
||
74 | . "of this file. Change the ownership of the file, create a new group, or temporarily " |
||
75 | . "make the file writeable by everyone during the install process."; |
||
76 | } |
||
77 | } |
||
78 | } else { |
||
79 | $message = "The webserver user needs to be able to write to this file:\n$filename"; |
||
80 | } |
||
81 | |||
82 | return [EnvironmentCheck::ERROR, $message]; |
||
83 | } |
||
84 | |||
85 | return [EnvironmentCheck::OK, '']; |
||
86 | } |
||
87 | } |
||
88 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.