Skip to content

Commit

Permalink
make php-cs-fixer happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiano Degan committed May 6, 2020
1 parent fcc13b2 commit 10a5d0e
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ public function toArray($value)
return (array) $value;
}

$array = [];
$className = get_class($value);
$array = [];
$className = \get_class($value);

foreach ((array) $value as $key => $val) {
if ($this->ignoreKey($key)) {
continue;
}

$key = $this->getExportedKey($key, $className);
$key = $this->getExportedKey($key, $className);
$array[$key] = $val;
}

Expand All @@ -169,40 +170,6 @@ public function toArray($value)
return $array;
}

private function ignoreKey($key) {
// Exception traces commonly reference hundreds to thousands of
// objects currently loaded in memory. Including them in the result
// has a severe negative performance impact.
if ("\0Error\0trace" === $key || "\0Exception\0trace" === $key) {
return true;
}

// See https://github.com/php/php-src/commit/5721132
if ($key === "\0gcdata") {
return true;
}

return false;
}

private function getExportedKey($key, $className)
{
// properties are transformed to keys in the following way:
// private $property => "\0Classname\0property"
// protected $property => "\0*\0property"
// public $property => "property"
$ignoredPrefixes = array("", "*", $className);
if (\preg_match('/^\0(.+)\0(.+)$/', (string) $key, $matches)) {
if (in_array($matches[1], $ignoredPrefixes)) {
$key = $matches[2];
} else {
$key = "{$matches[1]}::{$matches[2]}";
}
}

return $key;
}

/**
* Recursive implementation of export
*
Expand Down Expand Up @@ -319,4 +286,40 @@ protected function recursiveExport(&$value, $indentation, $processed = null)

return \var_export($value, true);
}

private function ignoreKey($key)
{
// Exception traces commonly reference hundreds to thousands of
// objects currently loaded in memory. Including them in the result
// has a severe negative performance impact.
if ("\0Error\0trace" === $key || "\0Exception\0trace" === $key) {
return true;
}

// See https://github.com/php/php-src/commit/5721132
if ($key === "\0gcdata") {
return true;
}

return false;
}

private function getExportedKey($key, $className)
{
// properties are transformed to keys in the following way:
// private $property => "\0Classname\0property"
// protected $property => "\0*\0property"
// public $property => "property"
$ignoredPrefixes = ['', '*', $className];

if (\preg_match('/^\0(.+)\0(.+)$/', (string) $key, $matches)) {
if (\in_array($matches[1], $ignoredPrefixes)) {
$key = $matches[2];
} else {
$key = "{$matches[1]}::{$matches[2]}";
}
}

return $key;
}
}

0 comments on commit 10a5d0e

Please sign in to comment.