Skip to content

Commit

Permalink
[*]: fix php-docs
Browse files Browse the repository at this point in the history
[~]: refactoring methods with "__"-prefix into "_" (no breaking changes)
  • Loading branch information
voku committed May 8, 2017
1 parent e5362d4 commit 12438b6
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions src/voku/helper/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function getInstance()
*/
public function add_filter($tag, $function_to_add, $priority = self::PRIORITY_NEUTRAL, $include_path = null)
{
$idx = $this->__filter_build_unique_id($function_to_add);
$idx = $this->_filter_build_unique_id($function_to_add);

$this->filters[$tag][$priority][$idx] = array(
'function' => $function_to_add,
Expand All @@ -179,7 +179,7 @@ public function add_filter($tag, $function_to_add, $priority = self::PRIORITY_NE
*/
public function remove_filter($tag, $function_to_remove, $priority = self::PRIORITY_NEUTRAL)
{
$function_to_remove = $this->__filter_build_unique_id($function_to_remove);
$function_to_remove = $this->_filter_build_unique_id($function_to_remove);

if (!isset($this->filters[$tag][$priority][$function_to_remove])) {
return false;
Expand Down Expand Up @@ -250,7 +250,7 @@ public function has_filter($tag, $function_to_check = false)
return $has;
}

if (!($idx = $this->__filter_build_unique_id($function_to_check))) {
if (!($idx = $this->_filter_build_unique_id($function_to_check))) {
return false;
}

Expand All @@ -268,10 +268,10 @@ public function has_filter($tag, $function_to_check = false)
*
* Info: Additional variables passed to the functions hooked to <tt>$tag</tt>.
*
* @param string $tag The name of the filter hook.
* @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
* @param string|array $tag The name of the filter hook.
* @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
*
* @return mixed The filtered value after all hooked functions are applied to it.
* @return mixed The filtered value after all hooked functions are applied to it.
* @access public
* @since 1.0.0
*/
Expand All @@ -283,7 +283,7 @@ public function apply_filters($tag, $value)
if (isset($this->filters['all'])) {
$this->current_filter[] = $tag;
$args = func_get_args();
$this->__call_all_hook($args);
$this->_call_all_hook($args);
}

if (!isset($this->filters[$tag])) {
Expand Down Expand Up @@ -349,7 +349,7 @@ public function apply_filters_ref_array($tag, $args)
if (isset($this->filters['all'])) {
$this->current_filter[] = $tag;
$all_args = func_get_args();
$this->__call_all_hook($all_args);
$this->_call_all_hook($all_args);
}

if (!isset($this->filters[$tag])) {
Expand Down Expand Up @@ -498,7 +498,7 @@ public function do_action($tag, $arg = '')
if (isset($this->filters['all'])) {
$this->current_filter[] = $tag;
$all_args = func_get_args();
$this->__call_all_hook($all_args);
$this->_call_all_hook($all_args);
}

if (!isset($this->filters[$tag])) {
Expand Down Expand Up @@ -588,7 +588,7 @@ public function do_action_ref_array($tag, $args)
if (isset($this->filters['all'])) {
$this->current_filter[] = $tag;
$all_args = func_get_args();
$this->__call_all_hook($all_args);
$this->_call_all_hook($all_args);
}

if (!isset($this->filters[$tag])) {
Expand Down Expand Up @@ -669,15 +669,15 @@ public function current_filter()
/**
* Build Unique ID for storage and retrieval.
*
* @param string $function Used for creating unique id
* @param string|array $function Used for creating unique id
*
* @return string|bool Unique ID for usage as array key or false if
* $priority === false and $function is an
* object reference, and it does not already have a unique id.
* @access private
* @since 1.0.0
*/
private function __filter_build_unique_id($function)
private function _filter_build_unique_id($function)
{
if (is_string($function)) {
return $function;
Expand All @@ -696,7 +696,9 @@ private function __filter_build_unique_id($function)
if (is_object($function[0])) {
// Object Class Calling
return spl_object_hash($function[0]) . $function[1];
} elseif (is_string($function[0])) {
}

if (is_string($function[0])) {
// Static Calling
return $function[0] . $function[1];
}
Expand All @@ -712,8 +714,11 @@ private function __filter_build_unique_id($function)
* @access public
* @since 1.0.0
*/
public function __call_all_hook($args)
public function _call_all_hook($args)
{
// <-- refactoring "__call_all_hook()" into "_call_all_hook()" is a breaking change (BC),
// so we will only deprecate the usage

reset($this->filters['all']);

do {
Expand All @@ -731,6 +736,19 @@ public function __call_all_hook($args)
} while (next($this->filters['all']) !== false);
}

/** @noinspection MagicMethodsValidityInspection */
/**
* @param array $args
*
* @deprecated use "this->_call_all_hook()"
* @access public
* @since 1.0.0
*/
public function __call_all_hook($args)
{
$this->_call_all_hook($args);
}

/**
* Add hook for shortcode tag.
*
Expand Down Expand Up @@ -806,9 +824,9 @@ public function remove_shortcode($tag)
unset(self::$shortcode_tags[$tag]);

return true;
} else {
return false;
}

return false;
}

/**
Expand Down Expand Up @@ -866,7 +884,9 @@ public function has_shortcode($content, $tag)
foreach ($matches as $shortcode) {
if ($tag === $shortcode[2]) {
return true;
} elseif (!empty($shortcode[5]) && $this->has_shortcode($shortcode[5], $tag)) {
}

if (!empty($shortcode[5]) && $this->has_shortcode($shortcode[5], $tag)) {
return true;
}
}
Expand Down Expand Up @@ -900,7 +920,7 @@ public function do_shortcode($content)
"/$pattern/s",
array(
$this,
'__do_shortcode_tag',
'_do_shortcode_tag',
),
$content
);
Expand Down Expand Up @@ -975,7 +995,7 @@ public function get_shortcode_regex()
*
* @return mixed False on failure.
*/
private function __do_shortcode_tag($m)
private function _do_shortcode_tag($m)
{
// allow [[foo]] syntax for escaping a tag
if ($m[1] == '[' && $m[6] == ']') {
Expand All @@ -985,13 +1005,13 @@ private function __do_shortcode_tag($m)
$tag = $m[2];
$attr = $this->shortcode_parse_atts($m[3]);

// enclosing tag - extra parameter
if (isset($m[5])) {
// enclosing tag - extra parameter
return $m[1] . call_user_func(self::$shortcode_tags[$tag], $attr, $m[5], $tag) . $m[6];
} else {
// self-closing tag
return $m[1] . call_user_func(self::$shortcode_tags[$tag], $attr, null, $tag) . $m[6];
}

// self-closing tag
return $m[1] . call_user_func(self::$shortcode_tags[$tag], $attr, null, $tag) . $m[6];
}

/**
Expand Down Expand Up @@ -1108,7 +1128,7 @@ public function strip_shortcodes($content)
"/$pattern/s",
array(
$this,
'__strip_shortcode_tag',
'_strip_shortcode_tag',
),
$content
);
Expand All @@ -1123,7 +1143,7 @@ public function strip_shortcodes($content)
*
* @return string
*/
private function __strip_shortcode_tag($m)
private function _strip_shortcode_tag($m)
{
// allow [[foo]] syntax for escaping a tag
if ($m[1] == '[' && $m[6] == ']') {
Expand Down

0 comments on commit 12438b6

Please sign in to comment.