| Conditions | 12 |
| Paths | 1 |
| Total Lines | 71 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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 |
||
| 16 | public function boot() {
|
||
| 17 | $this->publishes([ |
||
| 18 | __DIR__ . '/Config/jslocalization.php' => config_path('sirgrimorum/jslocalization.php'),
|
||
| 19 | ], 'config'); |
||
| 20 | |||
| 21 | Blade::directive('jslocalization', function($expression) {
|
||
| 22 | $auxExpression = explode(',', str_replace(['(', ')', ' ', '"', "'"], '', $expression));
|
||
| 23 | if (count($auxExpression) > 2) {
|
||
| 24 | $langfile = $auxExpression[0]; |
||
| 25 | $group = $auxExpression[1]; |
||
| 26 | $basevar = $auxExpression[2]; |
||
| 27 | } elseif (count($auxExpression) > 1) {
|
||
| 28 | $langfile = $auxExpression[0]; |
||
| 29 | $group = $auxExpression[1]; |
||
| 30 | $basevar = ""; |
||
| 31 | } else {
|
||
| 32 | $langfile = $auxExpression[0]; |
||
| 33 | $group = ""; |
||
| 34 | $basevar = ""; |
||
| 35 | } |
||
| 36 | $translations = new \Sirgrimorum\JSLocalization\BindTranslationsToJs($this->app, config('sirgrimorum.jslocalization.bind_trans_vars_to_this_view', 'layout.app'), config('sirgrimorum.jslocalization.trans_group', 'messages'), config('sirgrimorum.jslocalization.default_base_var', 'translations'));
|
||
| 37 | return $translations->get($langfile, $group, $basevar); |
||
| 38 | }); |
||
| 39 | Blade::directive('jsmodel', function($expression) {
|
||
| 40 | $auxExpression = explode(',', str_replace([' ', '"', "'"], '', $expression));
|
||
| 41 | //echo "<pre>" . print_r($auxExpression, true) . "</pre>"; |
||
| 42 | if (count($auxExpression) > 1) {
|
||
| 43 | if ($auxExpression[0] == 'Auth::user()') {
|
||
| 44 | $model = \Auth::user(); |
||
| 45 | } else {
|
||
| 46 | if (stripos($auxExpression[0], "::") !== false) {
|
||
| 47 | list($base, $comando) = explode("::", $auxExpression[0]);
|
||
| 48 | if (stripos($auxExpression[0], "->") !== false) {
|
||
| 49 | $comandos = explode("->", $comando);
|
||
| 50 | $cuenta = 0; |
||
| 51 | foreach ($comandos as $subComando) {
|
||
| 52 | if (stripos($subComando, "()") !== false) {
|
||
| 53 | $subComando = str_replace("()", "", $subComando);
|
||
| 54 | if ($cuenta == 0) {
|
||
| 55 | $model = $base::{$subComando}();
|
||
| 56 | } else {
|
||
| 57 | $model = $model->{$subComando}();
|
||
|
|
|||
| 58 | } |
||
| 59 | } else {
|
||
| 60 | if ($cuenta == 0) {
|
||
| 61 | $model = $base::$subComando; |
||
| 62 | } else {
|
||
| 63 | $model = $model->$subComando; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | $cuenta++; |
||
| 67 | } |
||
| 68 | } else {
|
||
| 69 | if (stripos($comando, "()") !== false) {
|
||
| 70 | $comando = str_replace("()", "", $comando);
|
||
| 71 | $model = $base::{$comando}();
|
||
| 72 | } else {
|
||
| 73 | $model = $base::$comando; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } else {
|
||
| 77 | $model = $auxExpression[0]; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | $variable = $auxExpression[1]; |
||
| 81 | } else {
|
||
| 82 | $model = $auxExpression[0]; |
||
| 83 | $variable = ""; |
||
| 84 | } |
||
| 85 | $translations = new \Sirgrimorum\JSLocalization\BindTranslationsToJs($this->app, config('sirgrimorum.jslocalization.bind_trans_vars_to_this_view', 'layout.app'), config('sirgrimorum.jslocalization.trans_group', 'messages'), config('sirgrimorum.jslocalization.default_base_var', 'translations'));
|
||
| 86 | return $translations->put($model, $variable); |
||
| 87 | }); |
||
| 114 |