| Conditions | 10 |
| Paths | 33 |
| Total Lines | 72 |
| Code Lines | 34 |
| 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 namespace kcfinder\integration; |
||
| 58 | static function runIntegration() { |
||
| 59 | |||
| 60 | $laravelPath = self::getLaravelPath(); |
||
| 61 | |||
| 62 | if(file_exists($laravelPath . '/bootstrap/autoload.php')) { |
||
| 63 | $currentCwd = getcwd(); |
||
| 64 | |||
| 65 | // Simulate being in the laravel root folder so we can share the session (is this really needed?) |
||
| 66 | // chdir($laravelPath); |
||
| 67 | |||
| 68 | // bootstrap |
||
| 69 | require $laravelPath.'/bootstrap/autoload.php'; |
||
| 70 | $app = require_once $laravelPath.'/bootstrap/start.php'; |
||
| 71 | $app->boot(); //Boot the application's service providers. |
||
| 72 | |||
| 73 | //get the admin check closure that should be supplied in the admin config |
||
| 74 | $permission = \Illuminate\Support\Facades\Config::get('administrator::administrator.permission'); |
||
| 75 | $hasPermission = $permission(); |
||
| 76 | self::$authenticated = $hasPermission; |
||
| 77 | |||
| 78 | //start session if not started already |
||
| 79 | if (session_id() == "") { |
||
| 80 | session_start(); |
||
| 81 | $iStartedTheSession = true; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!isset($_SESSION['KCFINDER'])) { |
||
| 85 | $_SESSION['KCFINDER'] = array(); |
||
| 86 | } |
||
| 87 | |||
| 88 | //if this is a simple true value, user is logged in |
||
| 89 | if ($hasPermission == true) { |
||
| 90 | |||
| 91 | $configFactory = \Illuminate\Support\Facades\App::make('admin_config_factory'); |
||
| 92 | $modelName = \Illuminate\Support\Facades\Input::get('model'); |
||
| 93 | $fieldName = \Illuminate\Support\Facades\Input::get('field'); |
||
| 94 | |||
| 95 | if(!empty($modelName) && !empty($fieldName)) { |
||
| 96 | |||
| 97 | $modelConfig = $configFactory->make($modelName, true); |
||
| 98 | $modelConfigOptions = $modelConfig->getOption('edit_fields'); |
||
| 99 | $kcfinderOptions = $modelConfigOptions[$fieldName]["kcfinder"]; |
||
| 100 | |||
| 101 | //allow users to use an option called 'enabled' instead of 'disabled' |
||
| 102 | if(isset($kcfinderOptions["enabled"])) { |
||
| 103 | $kcfinderOptions["disabled"] = !$kcfinderOptions["enabled"]; |
||
| 104 | } |
||
| 105 | |||
| 106 | //save all options to the session |
||
| 107 | foreach ($kcfinderOptions as $optKey => $optValue) { |
||
| 108 | $_SESSION['KCFINDER'][$optKey] = $optValue; |
||
| 109 | } |
||
| 110 | |||
| 111 | self::$authenticated = !$_SESSION['KCFINDER']['disabled']; |
||
| 112 | |||
| 113 | } |
||
| 114 | } |
||
| 115 | else { |
||
| 116 | //clean and reset the session variable |
||
| 117 | $_SESSION['KCFINDER'] = array(); |
||
| 118 | } |
||
| 119 | |||
| 120 | //close the session if I started it |
||
| 121 | if (isset($iStartedTheSession)) { |
||
| 122 | session_write_close(); |
||
| 123 | } |
||
| 124 | |||
| 125 | // chdir($currentCwd); |
||
| 126 | return self::$authenticated; |
||
| 127 | } |
||
| 128 | else { |
||
| 129 | die("The integration service for 'Laravel Administrator' failed. Laravel root path not found!"); |
||
| 130 | } |
||
| 137 |