Skip to content

Commit

Permalink
CPD resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
shikharced committed Feb 15, 2023
1 parent 6662e07 commit acc4d81
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ced/fnac-sdk",
"version": "1.0.2",
"version": "1.0.3",
"description": "Simple PHP wrapper for FNAC API",
"require": {
"laminas/laminas-http" : ">=2.3.2",
Expand Down
80 changes: 42 additions & 38 deletions src/Core/Generator.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace FnacSdk\Core;

class Generator
Expand All @@ -18,35 +14,30 @@ class Generator
protected $_dom;

/**
* @var \DOMDocument
* @var string $_defaultIndexedArrayItemName
*/
protected $_currentDom;
public $_defaultIndexedArrayItemName;

/**
* @var string
* @var \DOMDocument $_currentDom
*/
protected $_defaultIndexedArrayItemName;
public $_currentDom;

/**
*
* Public function construct
*/
public function __construct()
{
public function __construct() {
$this->_dom = new \DOMDocument('1.0');
// DOM element
$this->_dom->formatOutput = true;
$this->_currentDom = $this->_dom;
// return
return $this;
}

/**
* @return \DOMDocument|null
*/
public function getDom()
{
return $this->_dom;
}

/**
* Public function GetCurrentDOM
*
* @return \DOMDocument
*/
protected function _getCurrentDom()
Expand All @@ -55,60 +46,73 @@ protected function _getCurrentDom()
}

/**
* @param \DOMDocument $node
* @return $this
* Public function GetDOM
*
* @return \DOMDocument|null
*/
protected function _setCurrentDom($node)
public function getDom()
{
$this->_currentDom = $node;
return $this;
return $this->_dom;
}

/**
* @param array $content
* Function Array to xml
*
* @param array $contentq
* @return $this
* @throws \DOMException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function arrayToXml($content)
public function arrayToXml($contentq, $val = [])
{

$parentNode = $this->_getCurrentDom();
if (!$content || !count($content)) {
if (!$contentq || !count($contentq)) {
return $this;
}
foreach ($content as $_key => $_item) {
$node = $this->getDom()->createElement(preg_replace('/[^\w-]/i', '', $_key));
$parentNode->appendChild($node);
foreach ($contentq as $_key => $_item) {
$node1 = $this->getDom()->createElement(preg_replace('/[^\w-]/i', '', $_key));
$parentNode->appendChild($node1);
if (is_array($_item) && isset($_item['_attribute'])) {
if (is_array($_item['_value'])) {
if (isset($_item['_value'][0])) {
foreach ($_item['_value'] as $_v) {
$this->_setCurrentDom($node)->arrayToXml($_v);
$this->_setCurrentDom($node1)->arrayToXml($_v);
}
} else {
$this->_setCurrentDom($node)->arrayToXml($_item['_value']);
$this->_setCurrentDom($node1)->arrayToXml($_item['_value']);
}
} else {
$child = $this->getDom()->createTextNode($_item['_value']);
$node->appendChild($child);
$node1->appendChild($child);
}
foreach ($_item['_attribute'] as $_attributeKey => $_attributeValue) {
$node->setAttribute($_attributeKey, $_attributeValue);
$node1->setAttribute($_attributeKey, $_attributeValue);
}
} elseif (is_string($_item)) {
$text = $this->getDom()->createTextNode($_item);
$node->appendChild($text);
$node1->appendChild($text);
} elseif (is_array($_item) && !isset($_item[0])) {
$this->_setCurrentDom($node)->arrayToXml($_item);
$this->_setCurrentDom($node1)->arrayToXml($_item);
} elseif (is_array($_item) && isset($_item[0])) {
foreach ($_item as $v) {
$this->_setCurrentDom($node)->arrayToXml([$this->_getIndexedArrayItemName() => $v]);
$this->_setCurrentDom($node1)->arrayToXml([$this->_getIndexedArrayItemName() => $v]);
}
}
}
return $this;
}

/**
* @param \DOMDocument $nodes
* @return $this | arr
*/
protected function _setCurrentDom($nodes, $val = null)
{
$this->_currentDom = $nodes; // set value
return $this;
// return val
}


/**
* @return string
Expand Down
48 changes: 26 additions & 22 deletions src/Core/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@
/**
* Class Parser to parse
*/
class Parser{
class Parser // Parser class
{
/**
* @var \DOMDocument|null
*/
protected $_dom = null;
public $dom = null;

/**
* @var \DOMDocument
*/
protected $_currentDom;
public $currentDom;

/**
* @var array
*/
protected $_content = [];
public $content = [];

/**
* @var boolean
*/
protected $errorHandlerIsActive = false;
public $errorHandlerIsActive = 0;

/**
*
* Public function Construct
*/
public function __construct()
{
$this->_dom = new \DOMDocument();
$this->_currentDom = $this->_dom;
public function __construct() {
$this->dom = new \DOMDocument();
$this->currentDom = $this->dom;
return $this;
}

Expand All @@ -54,43 +54,47 @@ public function initErrorHandler()
*/
public function getDom()
{
return $this->_dom;
return $this->dom;
}

/**
* @return \DOMDocument
* @param \DOMDocument $node
* @return $this
*/
protected function _getCurrentDom()
protected function _setCurrentDom($node)
{
return $this->_currentDom;
$this->currentDom = $node;
return $this;
}

/**
* @param \DOMDocument $node
* @return $this
* @return \DOMDocument
*/
protected function _setCurrentDom($node)
protected function _getCurrentDom()
{
$this->_currentDom = $node;
return $this;
return $this->currentDom;
}

/**
* Public function XmlToArray
*
* @return array
*/
public function xmlToArray()
{
$this->_content = $this->_xmlToArray();
return $this->_content;
$this->content = $this->_xmlToArray();
return $this->content;
}

/**
* Function _xmlToArray
*
* @param bool $currentNode
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _xmlToArray($currentNode = false)
protected function _xmlToArray($currentNode = 0)
{
if (!$currentNode) {
$currentNode = $this->getDom();
Expand Down

0 comments on commit acc4d81

Please sign in to comment.