| Conditions | 13 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 10 |
| Ratio | 19.61 % |
| 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 |
||
| 98 | public static function createLocalStorage($extensionKey, $name, $message = '') |
||
| 99 | {
|
||
| 100 | if (!is_string($extensionKey) || empty($extensionKey)) {
|
||
| 101 | throw new \InvalidArgumentException('$extensionKey must be a non empty string.', 1491580810);
|
||
| 102 | } |
||
| 103 | |||
| 104 | if (!is_string($name) || empty($name)) {
|
||
| 105 | throw new \InvalidArgumentException('$name must be a non empty string.', 1491681665);
|
||
| 106 | } |
||
| 107 | |||
| 108 | View Code Duplication | if (self::createDirectoryAtWebRoot($name) !== true) {
|
|
|
1 ignored issue
–
show
|
|||
| 109 | FlashMessageUtility::showFlashMessage( |
||
| 110 | $extensionKey, |
||
| 111 | 'Local storage ' . $name . ' could not be created!', |
||
| 112 | 'Local storage not created', |
||
| 113 | FlashMessage::WARNING |
||
| 114 | ); |
||
| 115 | |||
| 116 | return null; |
||
| 117 | } |
||
| 118 | |||
| 119 | /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
||
| 120 | $storage = self::findLocalStorage($name); |
||
| 121 | |||
| 122 | if ($storage !== null) {
|
||
| 123 | FlashMessageUtility::showFlashMessage( |
||
| 124 | $extensionKey, |
||
| 125 | 'Local storage ' . $name . ' was found.' . (is_string($message) && !empty($message) ? ' ' . $message : ''), |
||
| 126 | 'Local storage found', |
||
| 127 | FlashMessage::NOTICE |
||
| 128 | ); |
||
| 129 | |||
| 130 | return $storage->getUid(); |
||
| 131 | } |
||
| 132 | |||
| 133 | $uid = self::getStorageRepository()->createLocalStorage( |
||
| 134 | $name . self::STORAGE_SUFFIX, |
||
| 135 | $name, |
||
| 136 | 'relative', |
||
| 137 | 'This is the local ' . $name . '/ directory. This storage mount has been created automatically by ' . $extensionKey . '.' . (is_string($message) && !empty($message) ? ' ' . $message : ''), |
||
| 138 | false |
||
| 139 | ); |
||
| 140 | |||
| 141 | FlashMessageUtility::showFlashMessage( |
||
| 142 | $extensionKey, |
||
| 143 | 'Local storage ' . $name . ' successfully created.' . (is_string($message) && !empty($message) ? ' ' . $message : ''), |
||
| 144 | 'Local storage created' |
||
| 145 | ); |
||
| 146 | |||
| 147 | return $uid; |
||
| 148 | } |
||
| 149 | |||
| 176 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.