| Conditions | 9 |
| Paths | 49 |
| Total Lines | 80 |
| Code Lines | 42 |
| 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 |
||
| 47 | public function classicAction($name, Request $request, $folder = 'main') |
||
| 48 | { |
||
| 49 | // get. |
||
| 50 | $_GET = $request->query->all(); |
||
| 51 | // post. |
||
| 52 | $_POST = $request->request->all(); |
||
| 53 | $rootDir = $this->get('kernel')->getRealRootDir(); |
||
| 54 | $mainPath = $rootDir.$folder.'/'; |
||
| 55 | $fileToLoad = $mainPath.$name; |
||
| 56 | |||
| 57 | // Setting legacy values inside the container |
||
| 58 | $this->setContainerValuesToLegacy(); |
||
| 59 | |||
| 60 | if (is_file($fileToLoad) && |
||
| 61 | \Security::check_abs_path($fileToLoad, $mainPath) |
||
| 62 | ) { |
||
| 63 | /** |
||
| 64 | * Some legacy Chamilo files still use this variables directly, |
||
| 65 | * instead of using a function. |
||
| 66 | **/ |
||
| 67 | $is_allowed_in_course = api_is_allowed_in_course(); |
||
| 68 | $is_courseAdmin = api_is_course_admin(); |
||
| 69 | $is_platformAdmin = api_is_platform_admin(); |
||
| 70 | $toolNameFromFile = basename(dirname($fileToLoad)); |
||
| 71 | $charset = 'UTF-8'; |
||
| 72 | // Default values |
||
| 73 | $_course = api_get_course_info(); |
||
| 74 | $_user = api_get_user_info(); |
||
| 75 | $_cid = api_get_course_id(); |
||
| 76 | $debug = $this->container->get('kernel')->getEnvironment() == 'dev' ? true : false; |
||
| 77 | |||
| 78 | // Loading legacy file |
||
| 79 | ob_start(); |
||
| 80 | require_once $fileToLoad; |
||
| 81 | $out = ob_get_contents(); |
||
| 82 | ob_end_clean(); |
||
| 83 | |||
| 84 | // No browser cache when executing an exercise. |
||
| 85 | if ($name == 'exercise/exercise_submit.php') { |
||
| 86 | $responseHeaders = array( |
||
| 87 | 'cache-control' => 'no-store, no-cache, must-revalidate' |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Loading code to be added |
||
| 92 | $js = isset($htmlHeadXtra) ? $htmlHeadXtra : array(); |
||
|
|
|||
| 93 | |||
| 94 | // Loading legacy breadcrumb $interbreadcrumb |
||
| 95 | $interbreadcrumb = isset($interbreadcrumb) ? $interbreadcrumb : null; |
||
| 96 | |||
| 97 | // We change the layout based in this variable |
||
| 98 | // This could be changed on the fly by a legacy script. |
||
| 99 | $template = Container::$legacyTemplate; |
||
| 100 | $params = [ |
||
| 101 | 'legacy_breadcrumb' => $interbreadcrumb, |
||
| 102 | 'js' => $js |
||
| 103 | ]; |
||
| 104 | |||
| 105 | // This means the page comes from legacy use Display::display_header |
||
| 106 | if (!empty($out)) { |
||
| 107 | $params['content'] = $out; |
||
| 108 | } else { |
||
| 109 | // This means the page comes from legacy use of $tpl = new Template(); |
||
| 110 | $legacyParams = \Template::$params; |
||
| 111 | if (!empty($legacyParams)) { |
||
| 112 | $params = array_merge($legacyParams, $params); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // Render using Symfony2 layouts see folder: |
||
| 117 | // src/Chamilo/ThemeBundle/Resources/views/Layout |
||
| 118 | return $this->render( |
||
| 119 | $template, |
||
| 120 | $params |
||
| 121 | ); |
||
| 122 | } else { |
||
| 123 | // Found does not exist |
||
| 124 | throw new NotFoundHttpException(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 133 |
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.