Skip to content

Commit

Permalink
improve object property processor
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed May 26, 2024
1 parent 0ab738c commit 996162c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Processors/ObjectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Chevere\VarDump\Processors\Traits\ProcessorTrait;
use Reflection;
use ReflectionObject;
use Throwable;

final class ObjectProcessor implements ProcessorInterface, ProcessorNestedInterface
{
Expand Down Expand Up @@ -89,13 +88,14 @@ public function write(): void

return;
}
$this->setProperties(new ReflectionObject($this->var));
$this->setProperties($this->var);
}

private function setProperties(ReflectionObject $reflection): void
private function setProperties(object $object): void
{
$reflection = new ReflectionObject($object);
$properties = [];
$properties = $this->getProperties($reflection);
$properties = $this->getProperties($object, $reflection);
// @codeCoverageIgnoreStart
if ($properties === [] && $reflection->isInternal()) {
$properties = $this->getPublicProperties();
Expand Down Expand Up @@ -130,6 +130,7 @@ private function getPublicProperties(): array
* @return array<string, array<mixed>>
*/
private function getProperties(
object $object,
ReflectionObject $reflection
): array {
$properties = [];
Expand All @@ -139,12 +140,15 @@ private function getProperties(
continue;
}
$isUnset = false;

try {
if (! $property->isInitialized($object)) {
if ($property->hasDefaultValue()) {
$value = $property->getDefaultValue();
} else {
$value = '';
$isUnset = true;
}
} else {
$value = $property->getValue($this->var);
} catch (Throwable) {
$value = '';
$isUnset = true;
}
$properties[$property->getName()] = [
implode(
Expand Down

0 comments on commit 996162c

Please sign in to comment.