Conditions | 10 |
Paths | 62 |
Total Lines | 55 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
70 | public static function getjs($scope, $basevar = '') { |
||
71 | if ($basevar == '') { |
||
72 | $basevar = config('sirgrimorum.transarticles.default_base_var'); |
||
73 | } |
||
74 | $lang = App::getLocale(); |
||
75 | $listo = false; |
||
76 | try { |
||
77 | $modelClass = config('sirgrimorum.transarticles.default_articles_model'); |
||
78 | $langColumn = config('sirgrimorum.transarticles.default_lang_column'); |
||
79 | $findArticles = config('sirgrimorum.transarticles.default_findarticles_function_name'); |
||
80 | $findArticle = config('sirgrimorum.transarticles.default_findarticle_function_name'); |
||
81 | $articles = $modelClass::{$findArticles}($scope)->where($langColumn, "=", $lang)->get(); |
||
82 | if ($articles) { |
||
83 | $listo = true; |
||
84 | } else { |
||
85 | $articles = $modelClass::{$findArticles}($scope)->get(); |
||
86 | if ($articles) { |
||
87 | $listo = true; |
||
88 | } else { |
||
89 | $articles = $modelClass::{$findArticle}($scope)->where($langColumn, "=", $lang)->first(); |
||
90 | $listo = false; |
||
91 | if ($articles) { |
||
92 | $jsarray = []; |
||
93 | data_fill($jsarray, $scope, $articles->content); |
||
94 | } else { |
||
95 | $articles = $modelClass::{$findArticle}($scope)->first(); |
||
96 | if ($articles) { |
||
97 | $jsarray = []; |
||
98 | data_fill($jsarray, $scope, $articles->content); |
||
99 | //$jsarray = $articles->content; |
||
100 | } else { |
||
101 | $jsarray = []; |
||
102 | data_fill($jsarray, $scope, $scope); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | } catch (Exception $ex) { |
||
108 | return $scope . " - Error:" . print_r($ex->getMessage(), true); |
||
109 | } |
||
110 | if ($listo) { |
||
111 | if ($articles) { |
||
112 | $trans = []; |
||
113 | foreach ($articles as $article) { |
||
114 | $trans[$article->nickname] = $article->content; |
||
115 | } |
||
116 | $jsarray = json_encode($trans); |
||
117 | return "<script>window.{$basevar} = window.{$basevar} || {};{$basevar}.{$scope} = {$jsarray};</script>"; |
||
118 | } else { |
||
119 | $jsarray = []; |
||
120 | data_fill($jsarray, $scope, $scope); |
||
121 | } |
||
122 | } |
||
123 | $jsarray = json_encode($jsarray); |
||
124 | return "<script>window.{$basevar} = window.{$basevar} || {};{$basevar} = {$jsarray};</script>"; |
||
125 | } |
||
128 |