| Conditions | 11 |
| Paths | 168 |
| Total Lines | 73 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 46 | if ($defaultExpireDate === 'yes') { |
||
| 47 | $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
||
| 48 | $defaultExpireSettings['defaultExpireDateSet'] = true; |
||
| 49 | $defaultExpireSettings['expireAfterDays'] = (int)$config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
||
| 50 | $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes'; |
||
| 51 | } |
||
| 52 | |||
| 53 | return $defaultExpireSettings; |
||
| 54 | } |
||
| 55 | |||
| 56 | public static function calcExpireDate() { |
||
| 57 | $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; |
||
| 58 | $expireAt = time() + $expireAfter; |
||
| 59 | $date = new \DateTime(); |
||
| 60 | $date->setTimestamp($expireAt); |
||
| 61 | $date->setTime(0, 0, 0); |
||
| 62 | //$dateString = $date->format('Y-m-d') . ' 00:00:00'; |
||
| 63 | |||
| 64 | return $date; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * calculate expire date |
||
| 69 | * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
||
| 70 | * @param int $creationTime timestamp when the share was created |
||
| 71 | * @param int $userExpireDate expire timestamp set by the user |
||
| 72 | * @return mixed integer timestamp or False |
||
| 73 | */ |
||
| 74 | public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) { |
||
| 75 | $expires = false; |
||
| 76 | $defaultExpires = null; |
||
| 77 | |||
| 78 | if (!empty($defaultExpireSettings['defaultExpireDateSet'])) { |
||
| 79 | $defaultExpires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400; |
||
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | if (isset($userExpireDate)) { |
||
| 84 | // if the admin decided to enforce the default expire date then we only take |
||
| 85 | // the user defined expire date of it is before the default expire date |
||
| 86 | if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
||
|
|
|||
| 87 | $expires = min($userExpireDate, $defaultExpires); |
||
| 88 | } else { |
||
| 89 | $expires = $userExpireDate; |
||
| 90 | } |
||
| 91 | } elseif ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
||
| 92 | $expires = $defaultExpires; |
||
| 93 | } |
||
| 94 | |||
| 95 | return $expires; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Strips away a potential file names and trailing slashes: |
||
| 100 | * - http://localhost |
||
| 101 | * - http://localhost/ |
||
| 102 | * - http://localhost/index.php |
||
| 103 | * - http://localhost/index.php/s/{shareToken} |
||
| 104 | * |
||
| 105 | * all return: http://localhost |
||
| 106 | * |
||
| 107 | * @param string $remote |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | protected static function fixRemoteURL($remote) { |
||
| 111 | $remote = str_replace('\\', '/', $remote); |
||
| 112 | if ($fileNamePosition = strpos($remote, '/index.php')) { |
||
| 113 | $remote = substr($remote, 0, $fileNamePosition); |
||
| 114 | } |
||
| 115 | $remote = rtrim($remote, '/'); |
||
| 116 | |||
| 117 | return $remote; |
||
| 118 | } |
||
| 119 | |||
| 154 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: