Skip to content

Commit

Permalink
Internal cleanup after Scrutinizer analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-orlando committed Jan 16, 2016
1 parent 66e77b6 commit 24d3aeb
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions source/FluidXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ protected function newContext($context)
return new FluidContext($context, $this->namespaces);
}

protected function insertElement($element, array $optionals, callable $fn)
protected function handleOptionals($element, array $optionals)
{
if (! \is_array($element)) {
$element = [ $element ];
Expand All @@ -959,12 +959,19 @@ protected function insertElement($element, array $optionals, callable $fn)
}
}

return [ $element, $attributes, $switch_context ];
}

protected function insertElement($element, array $optionals, callable $fn)
{
list($element, $attributes, $switch_context) = $this->handleOptionals($element, $optionals);

$new_context = [];

foreach ($this->nodes as $n) {
foreach ($element as $k => $v) {
// I give up, it's a too complex job for only one method like me.
$cx = $this->handleInsertion($n, $k, $v, $optionals, $fn);
$cx = $this->handleInsertion($n, $k, $v, $fn, $optionals);

$new_context = \array_merge($new_context, $cx);
}
Expand Down Expand Up @@ -1062,7 +1069,7 @@ protected function attachNodes($parent, $nodes, $fn)
return $context;
}

protected function specialContentHandler($parent, $k, $v, $optionals, $fn)
protected function specialContentHandler($parent, $k, $v)
{
if (! \is_string($k) || $k !== '@'|| ! \is_string($v)) {
return false;
Expand All @@ -1083,7 +1090,7 @@ protected function specialContentHandler($parent, $k, $v, $optionals, $fn)
return [];
}

protected function specialAttributeHandler($parent, $k, $v, $optionals, $fn)
protected function specialAttributeHandler($parent, $k, $v)
{
if (! \is_string($k) || $k[0] !== '@' || ! \is_string($v)) {
return false;
Expand All @@ -1098,7 +1105,7 @@ protected function specialAttributeHandler($parent, $k, $v, $optionals, $fn)
return [];
}

protected function stringStringHandler($parent, $k, $v, $optionals, $fn)
protected function stringStringHandler($parent, $k, $v, $fn)
{
if (! \is_string($k) || ! \is_string($v)) {
return false;
Expand All @@ -1113,7 +1120,7 @@ protected function stringStringHandler($parent, $k, $v, $optionals, $fn)
return [ $el ];
}

protected function stringMixedHandler($parent, $k, $v, $optionals, $fn)
protected function stringMixedHandler($parent, $k, $v, $fn, $optionals)
{
if (! \is_string($k) || \is_string($v)) {
return false;
Expand All @@ -1133,7 +1140,7 @@ protected function stringMixedHandler($parent, $k, $v, $optionals, $fn)
return [ $el ];
}

protected function integerArrayHandler($parent, $k, $v, $optionals, $fn)
protected function integerArrayHandler($parent, $k, $v, $fn, $optionals)
{
if (! \is_int($k) || ! \is_array($v)) {
return false;
Expand All @@ -1145,15 +1152,15 @@ protected function integerArrayHandler($parent, $k, $v, $optionals, $fn)
$context = [];

foreach ($v as $kk => $vv) {
$cx = $this->handleInsertion($parent, $kk, $vv, $optionals, $fn);
$cx = $this->handleInsertion($parent, $kk, $vv, $fn, $optionals);

$context = \array_merge($context, $cx);
}

return $context;
}

protected function integerStringNotXmlHandler($parent, $k, $v, $optionals, $fn)
protected function integerStringNotXmlHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! \is_string($v) || is_an_xml_string($v)) {
return false;
Expand All @@ -1168,7 +1175,7 @@ protected function integerStringNotXmlHandler($parent, $k, $v, $optionals, $fn)
return [ $el ];
}

protected function integerXmlHandler($parent, $k, $v, $optionals, $fn)
protected function integerXmlHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! is_an_xml_string($v)) {
return false;
Expand All @@ -1177,19 +1184,18 @@ protected function integerXmlHandler($parent, $k, $v, $optionals, $fn)
// The user has passed an XML document instance:
// [ '<tag></tag>', DOMNode, SimpleXMLElement, FluidXml ]

$nodes = [];

$wrapper = new \DOMDocument();
$wrapper->formatOutput = true;
$wrapper->preserveWhiteSpace = false;

$vv = \ltrim($v);
if ($vv[1] === '?') {
$wrapper->loadXML($vv);
$v = \ltrim($v);

if ($v[1] === '?') {
$wrapper->loadXML($v);
$nodes = $wrapper->childNodes;
} else {
// A way to import strings with multiple root nodes.
$wrapper->loadXML("<root>$vv</root>");
$wrapper->loadXML("<root>$v</root>");

// Algorithm 1:
$nodes = $wrapper->documentElement->childNodes;
Expand All @@ -1202,7 +1208,7 @@ protected function integerXmlHandler($parent, $k, $v, $optionals, $fn)
return $this->attachNodes($parent, $nodes, $fn);
}

protected function integerDomdocumentHandler($parent, $k, $v, $optionals, $fn)
protected function integerDomdocumentHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof \DOMDocument) {
return false;
Expand All @@ -1217,7 +1223,7 @@ protected function integerDomdocumentHandler($parent, $k, $v, $optionals, $fn)
// return $this->attachNodes($parent, $v->documentElement, $fn);
}

protected function integerDomnodelistHandler($parent, $k, $v, $optionals, $fn)
protected function integerDomnodelistHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof \DOMNodeList) {
return false;
Expand All @@ -1226,7 +1232,7 @@ protected function integerDomnodelistHandler($parent, $k, $v, $optionals, $fn)
return $this->attachNodes($parent, $v, $fn);
}

protected function integerDomnodeHandler($parent, $k, $v, $optionals, $fn)
protected function integerDomnodeHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof \DOMNode) {
return false;
Expand All @@ -1235,7 +1241,7 @@ protected function integerDomnodeHandler($parent, $k, $v, $optionals, $fn)
return $this->attachNodes($parent, $v, $fn);
}

protected function integerSimplexmlHandler($parent, $k, $v, $optionals, $fn)
protected function integerSimplexmlHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof \SimpleXMLElement) {
return false;
Expand All @@ -1244,7 +1250,7 @@ protected function integerSimplexmlHandler($parent, $k, $v, $optionals, $fn)
return $this->attachNodes($parent, \dom_import_simplexml($v), $fn);
}

protected function integerFluidxmlHandler($parent, $k, $v, $optionals, $fn)
protected function integerFluidxmlHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof FluidXml) {
return false;
Expand All @@ -1253,7 +1259,7 @@ protected function integerFluidxmlHandler($parent, $k, $v, $optionals, $fn)
return $this->attachNodes($parent, $v->dom()->documentElement, $fn);
}

protected function integerFluidcontextHandler($parent, $k, $v, $optionals, $fn)
protected function integerFluidcontextHandler($parent, $k, $v, $fn)
{
if (! \is_int($k) || ! $v instanceof FluidContext) {
return false;
Expand Down

0 comments on commit 24d3aeb

Please sign in to comment.