| Conditions | 10 |
| Paths | 97 |
| Total Lines | 97 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 30 | public function classicAction($name, Request $request) |
||
| 31 | { |
||
| 32 | // get. |
||
| 33 | $_GET = $request->query->all(); |
||
| 34 | // post. |
||
| 35 | $_POST = $request->request->all(); |
||
| 36 | |||
| 37 | $rootDir = $this->get('kernel')->getRealRootDir(); |
||
| 38 | |||
| 39 | //$_REQUEST = $request->request->all(); |
||
| 40 | $mainPath = $rootDir.'main/'; |
||
| 41 | $fileToLoad = $mainPath.$name; |
||
| 42 | |||
| 43 | // Setting legacy values inside the container |
||
| 44 | |||
| 45 | /** @var Connection $dbConnection */ |
||
| 46 | $dbConnection = $this->container->get('database_connection'); |
||
| 47 | $em = $this->get('kernel')->getContainer()->get('doctrine.orm.entity_manager'); |
||
| 48 | |||
| 49 | $database = new \Database($dbConnection, array()); |
||
| 50 | |||
| 51 | $database->setConnection($dbConnection); |
||
| 52 | $database->setManager($em); |
||
| 53 | Container::$container = $this->container; |
||
| 54 | Container::$dataDir = $this->container->get('kernel')->getDataDir(); |
||
| 55 | Container::$courseDir = $this->container->get('kernel')->getDataDir(); |
||
| 56 | //Container::$configDir = $this->container->get('kernel')->getConfigDir(); |
||
| 57 | $this->container->get('twig')->addGlobal('api_get_cidreq', api_get_cidreq()); |
||
| 58 | |||
| 59 | //$breadcrumb = $this->container->get('chamilo_core.block.breadcrumb'); |
||
| 60 | |||
| 61 | if (is_file($fileToLoad) && |
||
| 62 | \Security::check_abs_path($fileToLoad, $mainPath) |
||
| 63 | ) { |
||
| 64 | // Files inside /main need this variables to be set |
||
| 65 | $is_allowed_in_course = api_is_allowed_in_course(); |
||
| 66 | $is_courseAdmin = api_is_course_admin(); |
||
| 67 | $is_platformAdmin = api_is_platform_admin(); |
||
| 68 | |||
| 69 | $toolNameFromFile = basename(dirname($fileToLoad)); |
||
| 70 | $charset = 'UTF-8'; |
||
| 71 | // Default values |
||
| 72 | $_course = api_get_course_info(); |
||
| 73 | $_user = api_get_user_info(); |
||
| 74 | $debug = $this->container->get('kernel')->getEnvironment() == 'dev' ? true : false; |
||
| 75 | |||
| 76 | // Loading file |
||
| 77 | ob_start(); |
||
| 78 | require_once $fileToLoad; |
||
| 79 | $out = ob_get_contents(); |
||
| 80 | ob_end_clean(); |
||
| 81 | |||
| 82 | // No browser cache when executing an exercise. |
||
| 83 | if ($name == 'exercise/exercise_submit.php') { |
||
| 84 | $responseHeaders = array( |
||
| 85 | 'cache-control' => 'no-store, no-cache, must-revalidate' |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | $js = isset($htmlHeadXtra) ? $htmlHeadXtra : array(); |
||
|
|
|||
| 90 | |||
| 91 | // $interbreadcrumb is loaded in the require_once file. |
||
| 92 | $interbreadcrumb = isset($interbreadcrumb) ? $interbreadcrumb : null; |
||
| 93 | |||
| 94 | $template = Container::$legacyTemplate; |
||
| 95 | $defaultLayout = '@ChamiloTheme/Layout/layout_one_col.html.twig'; |
||
| 96 | if (!empty($template)) { |
||
| 97 | $defaultLayout = $template; |
||
| 98 | } |
||
| 99 | |||
| 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 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 | $defaultLayout, |
||
| 120 | $params |
||
| 121 | ); |
||
| 122 | } else { |
||
| 123 | // Found does not exist |
||
| 124 | throw new NotFoundHttpException(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 |
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.