Skip to content

Commit

Permalink
Refactored args order in Escaper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed May 25, 2015
1 parent bcace50 commit 41075aa
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/Kernel/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function __construct(AuraHtmlEscaper $escaper, $encoding = 'utf8')
* @param string $strategy
* @param string|null $encoding
* @return mixed
* @see \Foil\Kernel\Escaper::escapeString()
* @see \Foil\Kernel\Escaper::escapeArray()
* @see \Foil\Kernel\Escaper::escapeObject()
*/
public function escape($data, $strategy = 'html', $encoding = null)
{
Expand All @@ -62,7 +65,7 @@ public function escape($data, $strategy = 'html', $encoding = null)
}

return method_exists($this, $method)
? $this->$method($data, $strategy, $encoding, $this->escaper($encoding))
? $this->$method($data, $strategy, $this->escaper($encoding), $encoding)
: $data;
}

Expand All @@ -78,14 +81,14 @@ public function decode($data, $encoding = null)
} elseif (is_array($data) || $data instanceof Traversable) {
$result = [];
foreach ($data as $i => $item) {
$result[$i] = $this->decode($data, $encoding);
$result[$i] = $this->decode($item, $encoding);
}

return $result;
}

return is_object($data) && method_exists($data, '__toString')
? $this->decode($data->__toString(), $data, $encoding)
? $this->decode($data->__toString(), $encoding)
: $data;
}

Expand All @@ -109,23 +112,22 @@ private function escaper($encoding)
/**
* @param string $data
* @param string $strategy
* @param string $encoding
* @param \Aura\Html\Escaper $escaper
* @return string|array
* @return array|string
*/
private function escapeString($data, $strategy, $encoding, AuraHtmlEscaper $escaper)
private function escapeString($data, $strategy, AuraHtmlEscaper $escaper)
{
return $escaper->$strategy($data);
}

/**
* @param array $data
* @param string $strategy
* @param string $encoding
* @param \Aura\Html\Escaper $escaper
* @return string|array
* @param string $encoding
* @return array|string
*/
private function escapeArray(array $data, $strategy, $encoding, AuraHtmlEscaper $escaper)
private function escapeArray(array $data, $strategy, AuraHtmlEscaper $escaper, $encoding)
{
if ($strategy === 'attr') {
return $escaper->attr($data);
Expand All @@ -140,14 +142,14 @@ private function escapeArray(array $data, $strategy, $encoding, AuraHtmlEscaper
/**
* @param object $data
* @param string $strategy
* @param string $encoding
* @param \Aura\Html\Escaper $escaper
* @return string|array
* @param string $encoding
* @return array|string
*/
private function escapeObject($data, $strategy, $encoding, AuraHtmlEscaper $escaper)
private function escapeObject($data, $strategy, AuraHtmlEscaper $escaper, $encoding)
{
if (method_exists($data, '__toString')) {
return $this->escapeString($data->__toString(), $strategy, $encoding, $escaper);
return $this->escapeString($data->__toString(), $strategy, $escaper, $encoding);
} elseif ($data instanceof Traversable) {
$result = [];
foreach ($data as $i => $item) {
Expand All @@ -158,7 +160,7 @@ private function escapeObject($data, $strategy, $encoding, AuraHtmlEscaper $esca
}

return $strategy === 'attr'
? $this->escapeArray(get_object_vars($data), $strategy, $encoding, $escaper)
? $this->escapeArray(get_object_vars($data), $strategy, $escaper, $encoding)
: $data;
}
}

0 comments on commit 41075aa

Please sign in to comment.