| Conditions | 12 |
| Paths | 5 |
| Total Lines | 78 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 53 | public function getLibraries($libraries = null) |
||
| 54 | { |
||
| 55 | $return = []; |
||
| 56 | |||
| 57 | if ($libraries !== null) { |
||
| 58 | // Get details for the specified libraries only. |
||
| 59 | foreach ($libraries as $library) { |
||
| 60 | // Look for library |
||
| 61 | $details = H5pLibrary::where('name', $library->name) |
||
| 62 | ->where('major_version', $library->majorVersion) |
||
| 63 | ->where('minor_version', $library->minorVersion) |
||
| 64 | ->whereNotNull('semantics') |
||
| 65 | ->first(); |
||
| 66 | |||
| 67 | if ($details) { |
||
| 68 | // Library found, add details to list |
||
| 69 | $library->tutorialUrl = $details->tutorial_url; |
||
| 70 | $library->title = $details->title; |
||
| 71 | $library->runnable = $details->runnable; |
||
| 72 | $library->restricted = $details->restricted === '1' ? true : false; |
||
| 73 | $return[] = $library; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } else { |
||
| 77 | |||
| 78 | // Load all libraries |
||
| 79 | $libraries = []; |
||
| 80 | $libraries_result = H5pLibrary::where('runnable', 1) |
||
| 81 | ->select([ |
||
| 82 | // 'id', |
||
| 83 | 'name', |
||
| 84 | 'title', |
||
| 85 | 'major_version AS majorVersion', |
||
| 86 | 'minor_version AS minorVersion', |
||
| 87 | 'patch_version AS patchVersion', |
||
| 88 | // 'runnable', |
||
| 89 | 'restricted', |
||
| 90 | // 'fullscreen', |
||
| 91 | // 'embed_types', |
||
| 92 | // 'preloaded_js', |
||
| 93 | // 'preloaded_css', |
||
| 94 | // 'drop_library_css', |
||
| 95 | // 'semantics', |
||
| 96 | 'tutorial_url', |
||
| 97 | // 'has_icon', |
||
| 98 | // 'created_at', |
||
| 99 | // 'updated_at' |
||
| 100 | ]) |
||
| 101 | ->whereNotNull('semantics') |
||
| 102 | ->orderBy('name', 'ASC') |
||
| 103 | ->get(); |
||
| 104 | |||
| 105 | // 모든 버전의 라리브러리가 로드되므로 하나의 가장 최신 라이브러리를 찾는 부분 |
||
| 106 | foreach ($libraries_result as $library) { |
||
| 107 | // Make sure we only display the newest version of a library. |
||
| 108 | foreach ($libraries as $key => $existingLibrary) { |
||
| 109 | if ($library->name === $existingLibrary->name) { |
||
| 110 | // Found library with same name, check versions |
||
| 111 | if (($library->majorVersion === $existingLibrary->majorVersion && |
||
| 112 | $library->minorVersion > $existingLibrary->minorVersion) || |
||
| 113 | ($library->majorVersion > $existingLibrary->majorVersion)) { |
||
| 114 | // This is a newer version |
||
| 115 | $existingLibrary->isOld = true; |
||
| 116 | } else { |
||
| 117 | // This is an older version |
||
| 118 | $library->isOld = true; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | // Check to see if content type should be restricted |
||
| 123 | $library->restricted = $library->restricted === '1' ? true : false; |
||
| 124 | |||
| 125 | // Add new library |
||
| 126 | $return[] = $library; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | return $return; |
||
| 131 | } |
||
| 186 |