@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $tpl = $this->getTplPath($this->widget->template); |
| 42 | 42 | |
| 43 | - $this->html = "<span title='WidgetObj : ".get_class($this->widget).".php
Template : {$tpl}{$this->cacheState()}'>{$this->html}</span>"; |
|
| 43 | + $this->html = "<span title='WidgetObj : " . get_class($this->widget) . ".php
Template : {$tpl}{$this->cacheState()}'>{$this->html}</span>"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | private function cacheState(): string |
| 52 | 52 | { |
| 53 | - if (! $this->policies->widgetShouldUseCache()) { |
|
| 53 | + if (!$this->policies->widgetShouldUseCache()) { |
|
| 54 | 54 | return ' 
 Cache: is globally turned off (You should put "enable_cache" => true in config\widgetize.php) '; |
| 55 | 55 | } |
| 56 | 56 | $l = $this->widget->cacheLifeTime->i ?? 0; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | private function addHtmlComments(): void |
| 62 | 62 | { |
| 63 | - $this->html = "<!-- '{".get_class($this->widget)."' Widget Start -->".$this->html."<!-- '".get_class($this->widget)."' Widget End -->"; |
|
| 63 | + $this->html = "<!-- '{" . get_class($this->widget) . "' Widget Start -->" . $this->html . "<!-- '" . get_class($this->widget) . "' Widget End -->"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | private function getTplPath(string $tpl): string |
| 71 | 71 | { |
| 72 | 72 | if (str_contains($tpl, 'Widgets::')) { |
| 73 | - $tpl = str_replace('Widgets::', app()->getNamespace().'Widgets\\', $tpl); |
|
| 73 | + $tpl = str_replace('Widgets::', app()->getNamespace() . 'Widgets\\', $tpl); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return str_replace('.', '\\', $tpl).'.blade.php'; |
|
| 76 | + return str_replace('.', '\\', $tpl) . '.blade.php'; |
|
| 77 | 77 | } |
| 78 | 78 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public function widgetShouldHaveDebugInfo(): bool |
| 13 | 13 | { |
| 14 | - return config('widgetize.debug_info') && ! app()->environment('production'); |
|
| 14 | + return config('widgetize.debug_info') && !app()->environment('production'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function widgetShouldUseCache(): bool |
| 25 | 25 | { |
| 26 | - return config('widgetize.enable_cache') && (! app()->environment('testing')); |
|
| 26 | + return config('widgetize.enable_cache') && (!app()->environment('testing')); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function normalize($widget): void |
| 16 | 16 | { |
| 17 | - if (! property_exists($widget, 'cacheLifeTime')) { |
|
| 17 | + if (!property_exists($widget, 'cacheLifeTime')) { |
|
| 18 | 18 | $M = config('widgetize.default_cache_lifetime', 0); |
| 19 | 19 | $widget->cacheLifeTime = $this->makeFromSeconds($M * 60); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - if (! property_exists($widget, 'cacheView')) { |
|
| 22 | + if (!property_exists($widget, 'cacheView')) { |
|
| 23 | 23 | $widget->cacheView = true; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -41,6 +41,6 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function makeFromSeconds($s) |
| 43 | 43 | { |
| 44 | - return new \DateInterval('PT'.(string) ceil($s).'S'); |
|
| 44 | + return new \DateInterval('PT' . (string)ceil($s) . 'S'); |
|
| 45 | 45 | } |
| 46 | 46 | } |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function cacheResult(array $args, callable $phpCode, $widgetObj, $form = 'HTML') |
| 31 | 31 | { |
| 32 | - if (! resolve(Policies::class)->widgetShouldUseCache() || $widgetObj->cacheLifeTime->s === 0) { |
|
| 32 | + if (!resolve(Policies::class)->widgetShouldUseCache() || $widgetObj->cacheLifeTime->s === 0) { |
|
| 33 | 33 | return $phpCode(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $cache = resolve('cache'); |
| 37 | 37 | |
| 38 | - if (! empty($widgetObj->cacheTags) && $this->cacheDriverSupportsTags()) { |
|
| 38 | + if (!empty($widgetObj->cacheTags) && $this->cacheDriverSupportsTags()) { |
|
| 39 | 39 | $cache = $cache->tags($widgetObj->cacheTags); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | $_key = json_encode($widget->extraCacheKeyDependency($arg)); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if (! $this->cacheDriverSupportsTags()) { |
|
| 67 | + if (!$this->cacheDriverSupportsTags()) { |
|
| 68 | 68 | $_key .= json_encode($this->getTagTokens($widget->cacheTags)); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $_key .= json_encode($arg, JSON_FORCE_OBJECT).app()->getLocale().$form.$widget->template.get_class($widget); |
|
| 71 | + $_key .= json_encode($arg, JSON_FORCE_OBJECT) . app()->getLocale() . $form . $widget->template . get_class($widget); |
|
| 72 | 72 | |
| 73 | 73 | return md5($_key); |
| 74 | 74 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | private function cacheDriverSupportsTags() : bool |
| 81 | 81 | { |
| 82 | - return ! in_array(config('cache.default', 'file'), ['file', 'database']); |
|
| 82 | + return !in_array(config('cache.default', 'file'), ['file', 'database']); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | private function getTagTokens(array $cacheTags) |
| 90 | 90 | { |
| 91 | - return array_map(function ($tag) { |
|
| 91 | + return array_map(function($tag) { |
|
| 92 | 92 | return $this->_cacheTag->getTagToken($tag); |
| 93 | 93 | }, $cacheTags); |
| 94 | 94 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | return \Cache::tags($tags)->flush(); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - foreach ((array) $tags as $tag) { |
|
| 106 | + foreach ((array)$tags as $tag) { |
|
| 107 | 107 | $this->_cacheTag->generateNewToken($tag); |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | private function checkControllerExists(string $ctrlClass): void |
| 30 | 30 | { |
| 31 | - if (! class_exists($ctrlClass)) { |
|
| 31 | + if (!class_exists($ctrlClass)) { |
|
| 32 | 32 | throw new \InvalidArgumentException("Controller class: [{$ctrlClass}] not found."); |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | [$ctrlClass, $method] = $ctrlClass; |
| 46 | - if (! method_exists($ctrlClass, $method)) { |
|
| 47 | - throw new \InvalidArgumentException("'data' method not found on ".$ctrlClass); |
|
| 46 | + if (!method_exists($ctrlClass, $method)) { |
|
| 47 | + throw new \InvalidArgumentException("'data' method not found on " . $ctrlClass); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | // We decide to call data method on the widget object by default. |
| 58 | 58 | // If the user has explicitly declared controller class path on |
| 59 | 59 | // widget then we decide to call data method on that instead. |
| 60 | - if (! property_exists($widget, 'controller')) { |
|
| 60 | + if (!property_exists($widget, 'controller')) { |
|
| 61 | 61 | return method_exists($widget, 'data') ? [[$widget, 'data'], null] : [null, null]; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if (is_string($widget->controller)) { |
| 65 | - if (! str_contains($widget->controller, '@')) { |
|
| 66 | - return [$widget->controller.'@data', $widget->controller]; |
|
| 65 | + if (!str_contains($widget->controller, '@')) { |
|
| 66 | + return [$widget->controller . '@data', $widget->controller]; |
|
| 67 | 67 | } |
| 68 | 68 | $widget->controller = explode('@', $widget->controller); |
| 69 | 69 | } elseif (is_callable($widget->controller)) { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | if (is_array($widget)) { |
| 33 | - $widget = (object) $widget; |
|
| 33 | + $widget = (object)$widget; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | event('widgetize.rendering_widget', [$widget]); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | return app($widget); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $widget = app()->getNamespace().'Widgets\\'.$widget; |
|
| 57 | + $widget = app()->getNamespace() . 'Widgets\\' . $widget; |
|
| 58 | 58 | |
| 59 | 59 | return app($widget); |
| 60 | 60 | } |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | private function generateHtml($widget, ...$args) |
| 71 | 71 | { |
| 72 | 72 | // Everything inside this function is executed only when the cache is not available. |
| 73 | - $expensivePhpCode = function () use ($widget, $args) { |
|
| 73 | + $expensivePhpCode = function() use ($widget, $args) { |
|
| 74 | 74 | $this->makeDataForView($widget, $args); |
| 75 | 75 | |
| 76 | 76 | return $this->renderTemplate($widget, ...$args); |
| 77 | 77 | }; |
| 78 | 78 | |
| 79 | - if (! $widget->cacheView) { |
|
| 79 | + if (!$widget->cacheView) { |
|
| 80 | 80 | return $expensivePhpCode(); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | private function makeDataForView($widget, array $args) |
| 94 | 94 | { |
| 95 | - $expensiveCode = function () use ($widget, $args) { |
|
| 95 | + $expensiveCode = function() use ($widget, $args) { |
|
| 96 | 96 | $viewData = $this->callController($widget, $args); |
| 97 | 97 | |
| 98 | 98 | if ($widget->presenter) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | try { |
| 126 | 126 | $this->html = view($widget->template, $data)->render(); |
| 127 | 127 | } catch (\Throwable $t) { |
| 128 | - throw new \ErrorException('There was some error rendering '.get_class($widget).', template file: \''.$widget->template.'\' Error: '.$t->getMessage()); |
|
| 128 | + throw new \ErrorException('There was some error rendering ' . get_class($widget) . ', template file: \'' . $widget->template . '\' Error: ' . $t->getMessage()); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // We try to minify the html before storing it in cache to save space. |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | private function callController($widget, array $args) |
| 146 | 146 | { |
| 147 | - if (! isset($widget->controller)) { |
|
| 147 | + if (!isset($widget->controller)) { |
|
| 148 | 148 | $viewData = []; |
| 149 | 149 | } elseif (is_array($widget->controller) && is_string($widget->controller[0])) { |
| 150 | 150 | $viewData = call_user_func_array($widget->controller, $args); |