Skip to content

Commit

Permalink
Merge pull request #134 from alshenetsky/remove-outdated-code
Browse files Browse the repository at this point in the history
Do not convert stdClass to array && remove outdated piece of code
  • Loading branch information
freekmurze authored Dec 3, 2021
2 parents 7c1d7e6 + fd5046c commit a259df1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"php": "^7.3|^7.4|^8.0",
"ext-dom": "*",
"ext-json": "*",
"composer-runtime-api": "^2.0",
"phpunit/phpunit": "^8.3|^9.0",
"symfony/property-access": "^4.0|^5.0|^6.0",
"symfony/serializer": "^4.0|^5.0|^6.0",
Expand Down
10 changes: 7 additions & 3 deletions src/Drivers/ObjectDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Snapshots\Drivers;

use Composer\InstalledVersions;
use PHPUnit\Framework\Assert;
use Spatie\Snapshots\Driver;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
Expand All @@ -25,10 +26,13 @@ public function serialize($data): string

$serializer = new Serializer($normalizers, $encoders);

// The Symfony serialized doesn't support `stdClass` yet.
// This may be removed when Symfony 5.1 is released.
if ($data instanceof \stdClass) {
$data = (array) $data;
$serializerVersion = InstalledVersions::getVersion('symfony/serializer');

if (version_compare($serializerVersion, '5.1.0.0') < 0) {
// The Symfony serializer (before 5.1 version) doesn't support `stdClass`.
$data = (array) $data;
}
}

return $this->dedent(
Expand Down

0 comments on commit a259df1

Please sign in to comment.