Skip to content

Commit

Permalink
clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenExe committed Feb 13, 2016
1 parent 8784bb1 commit 001bdfc
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions src/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ private function initialize(array $temporaryCustom)
$this->exists = array_keys($this->temporaryCustom);
}

/**
* TODO: Возможно стоит всегда возвращать в одном формате. Экземпляр класса с методом `isEqual`
*/
/**
* @param $data
* @param $structure
* @param array $custom
* @return StructureDiffInfo
*/
public static function check($data, $structure, array $custom = [])
Expand Down Expand Up @@ -67,20 +65,16 @@ private function checkTypes($value, array $types)
* К примеру формата даты или длины
*/

if (in_array($this->getType($value), $types)) return /* success */;
if (in_array($this->getType($value), $types)) return; /* success */

if ($this->exists) {

if ($intersect = array_intersect($types, $this->exists)) {
foreach ($intersect as $key) {
$diff = $this->compare($value, $this->temporaryCustom[$key]);

if (empty($diff)) return /* success */;
if (empty($diff)) return; /* success */
}

/**
* TODO: Возможно стоит возвращать с наименьшим путем
*/
return $this->processDiff($diff, "custom:type:$key");
}
}
Expand All @@ -92,21 +86,18 @@ private function diffType($data, $structure)
{
$needTypes = explode('|', $structure);

if ($diff = $this->checkTypes($data, $needTypes)) {
return $diff;
}
return $this->checkTypes($data, $needTypes);
}

private function diffSet($data, $set)
{
$data = (array) $data;
$set = (array) $set;
$data = (array)$data;
$set = (array)$set;

if (array_diff($data, $set)) {
return $this->createDiff('set:out', StructureDiffInfo::TYPE);
}


foreach ($data as $value) {
if (in_array($value, $set, true)) continue;

Expand All @@ -128,36 +119,37 @@ private function diffStructure($data, array $structure)
}

if (is_array($data)) {
return $this->diffArrayData($data, $structure);
}
}

if (isset($structure['assoc'])) {
return $this->assoc($structure['assoc'], $data);
}

if(isset($structure['values'])) {

if (is_array($structure['values'])) {
foreach ($data as $key => $subData) {
private function diffArrayData(array $data, array $structure)
{
if (isset($structure['assoc'])) {
return $this->assoc($structure['assoc'], $data);
}

if ($diff = $this->assoc($structure['values'], $subData)) {
return $this->processDiff($diff, "[$key]");
}
if (isset($structure['values'])) {
if (is_array($structure['values'])) {
foreach ($data as $key => $subData) {

if ($diff = $this->assoc($structure['values'], $subData)) {
return $this->processDiff($diff, "[$key]");
}
} elseif (is_string($structure['values'])) {
$needTypes = explode('|', $structure['values']);

foreach ($data as $key => $subData) {

if ($diff = $this->checkTypes($subData, $needTypes)) {
return $this->processDiff($diff, "[$key]");
}
}
}
} elseif (is_string($structure['values'])) {
$needTypes = explode('|', $structure['values']);

} else {
foreach ($data as $key => $subData) {

return $this->createDiff('structure:type', StructureDiffInfo::CONFIG);
if ($diff = $this->checkTypes($subData, $needTypes)) {
return $this->processDiff($diff, "[$key]");
}
}
}
} else {
return $this->createDiff('structure:type', StructureDiffInfo::CONFIG);
}
}

Expand Down Expand Up @@ -208,7 +200,6 @@ private function processDiff(StructureDiffInfo $diff, $key)

/**
* @return Comparator
*/
private static function instance()
{
Expand Down

0 comments on commit 001bdfc

Please sign in to comment.