From 84a7f5c6f0667e87f7ee4296d6a62ecfc8d264f8 Mon Sep 17 00:00:00 2001 From: esemve Date: Sun, 25 Feb 2018 15:27:43 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Callback.php | 3 +- src/Console/HookListeners.php | 100 ++++++++++++++++------------------ src/Facades/Hook.php | 2 +- src/Hook.php | 63 +++++++++++++-------- src/HookServiceProvider.php | 18 +++--- 5 files changed, 98 insertions(+), 88 deletions(-) diff --git a/src/Callback.php b/src/Callback.php index eb64117..a2be38c 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -23,10 +23,9 @@ public function call($parameters = null) { if ($this->run) { $this->run = false; + return call_user_func_array($this->function, ($parameters ? $parameters : $this->parameters)); } - - return null; } public function reset() diff --git a/src/Console/HookListeners.php b/src/Console/HookListeners.php index 37affae..18b09f7 100644 --- a/src/Console/HookListeners.php +++ b/src/Console/HookListeners.php @@ -1,52 +1,48 @@ - $lister) { - foreach ($lister as $key => $element) { - - $array[] = [ - $key, - $hook, - $element['caller']['class'] - ]; - } - } - - $headers = ['Sort', 'Hook name', 'Listener class']; - - $this->table($headers, $array); - - } -} + $lister) { + foreach ($lister as $key => $element) { + $array[] = [ + $key, + $hook, + $element['caller']['class'], + ]; + } + } + + $headers = ['Sort', 'Hook name', 'Listener class']; + + $this->table($headers, $array); + } +} diff --git a/src/Facades/Hook.php b/src/Facades/Hook.php index c03ea74..710d300 100644 --- a/src/Facades/Hook.php +++ b/src/Facades/Hook.php @@ -10,4 +10,4 @@ protected static function getFacadeAccessor() { return 'Hook'; } -} \ No newline at end of file +} diff --git a/src/Hook.php b/src/Hook.php index d729728..9c2b988 100644 --- a/src/Hook.php +++ b/src/Hook.php @@ -10,11 +10,13 @@ class Hook protected $testing = false; /** - * Return the hook answer - * @param string $hook Hook name - * @param array $params + * Return the hook answer. + * + * @param string $hook Hook name + * @param array $params * @param callable $callback - * @param string $htmlContent content wrapped by hook + * @param string $htmlContent content wrapped by hook + * * @return null|void */ public function get($hook, $params = [], callable $callback = null, $htmlContent = '') @@ -33,11 +35,13 @@ public function get($hook, $params = [], callable $callback = null, $htmlContent } unset($callbackObject); + return $output; } /** - * Stop all another hook running + * Stop all another hook running. + * * @param string $hook Hook name */ public function stop($hook) @@ -46,7 +50,8 @@ public function stop($hook) } /** - * Subscribe to hook + * Subscribe to hook. + * * @param string $hook Hook name * @param $priority * @param $function @@ -65,30 +70,34 @@ public function listen($hook, $function, $priority = null) $this->watch[$hook][$priority] = [ 'function' => $function, - 'caller' => [ + 'caller' => [ //'file' => $caller['file'], //'line' => $caller['line'], - 'class' => $caller['class'] - ] + 'class' => $caller['class'], + ], ]; ksort($this->watch[$hook]); } /** - * Return all registered hooks + * Return all registered hooks. + * * @return array */ public function getHooks() { $hookNames = (array_keys($this->watch)); ksort($hookNames); + return $hookNames; } /** - * Return all listeners for hook + * Return all listeners for hook. + * * @param string $hook + * * @return array */ public function getEvents($hook) @@ -103,9 +112,10 @@ public function getEvents($hook) } /** - * For testing - * @param string $name Hook name - * @param mixed $return Answer + * For testing. + * + * @param string $name Hook name + * @param mixed $return Answer */ public function mock($name, $return) { @@ -114,8 +124,10 @@ public function mock($name, $return) } /** - * Return the mock value + * Return the mock value. + * * @param string $hook Hook name + * * @return null|mixed */ protected function returnMockIfDebugModeAndMockExists($hook) @@ -124,16 +136,18 @@ protected function returnMockIfDebugModeAndMockExists($hook) if (array_key_exists($hook, $this->mock)) { $output = $this->mock[$hook]['return']; unset($this->mock[$hook]); + return $output; } } - return null; } /** - * Return a new callback object + * Return a new callback object. + * * @param callable $callback function - * @param array $params parameters + * @param array $params parameters + * * @return \Esemve\Hook\Callback */ protected function createCallbackObject($callback, $params) @@ -142,11 +156,13 @@ protected function createCallbackObject($callback, $params) } /** - * Run hook events - * @param string $hook Hook name - * @param array $params Parameters + * Run hook events. + * + * @param string $hook Hook name + * @param array $params Parameters * @param \Esemve\Hook\Callback $callback Callback object - * @param string $output html wrapped by hook + * @param string $output html wrapped by hook + * * @return mixed */ protected function run($hook, $params, Callback $callback, $output = null) @@ -172,7 +188,8 @@ protected function run($hook, $params, Callback $callback, $output = null) } /** - * Return the listeners + * Return the listeners. + * * @return array */ public function getListeners() diff --git a/src/HookServiceProvider.php b/src/HookServiceProvider.php index f6a4643..3900347 100644 --- a/src/HookServiceProvider.php +++ b/src/HookServiceProvider.php @@ -2,8 +2,8 @@ namespace Esemve\Hook; -use Illuminate\Support\ServiceProvider; use Blade; +use Illuminate\Support\ServiceProvider; class HookServiceProvider extends ServiceProvider { @@ -19,14 +19,13 @@ public function register() ]); $this->app->singleton('Hook', function () { - return new Hook; + return new Hook(); }); } protected function bootDirectives() { Blade::directive('hook', function ($parameter) { - $parameter = trim($parameter, '()'); $parameters = explode(',', $parameter); @@ -34,7 +33,7 @@ protected function bootDirectives() // $parameters[1] => bool => is this wrapper component? if (!isset($parameters[1])) { - return ' <' . '?php + return ' <'.'?php $__definedVars = (get_defined_vars()["__data"]); if (empty($__definedVars)) @@ -44,17 +43,16 @@ protected function bootDirectives() $output = \Hook::get("template.'.$name.'",["data"=>$__definedVars],function($data) { return null; }); if ($output) echo $output; - ?' . '>'; - }else{ - return ' <' . '?php + ?'.'>'; + } else { + return ' <'.'?php $__hook_name="'.$name.'"; ob_start(); - ?' . '>'; + ?'.'>'; } }); - Blade::directive('endhook',function($parameter){ - + Blade::directive('endhook', function ($parameter) { return ' <'.'?php $__definedVars = (get_defined_vars()["__data"]); if (empty($__definedVars))