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