Skip to content

Commit a259df1

Browse files
authored
Merge pull request #134 from alshenetsky/remove-outdated-code
Do not convert stdClass to array && remove outdated piece of code
2 parents 7c1d7e6 + fd5046c commit a259df1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"php": "^7.3|^7.4|^8.0",
2424
"ext-dom": "*",
2525
"ext-json": "*",
26+
"composer-runtime-api": "^2.0",
2627
"phpunit/phpunit": "^8.3|^9.0",
2728
"symfony/property-access": "^4.0|^5.0|^6.0",
2829
"symfony/serializer": "^4.0|^5.0|^6.0",

src/Drivers/ObjectDriver.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\Snapshots\Drivers;
44

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

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

28-
// The Symfony serialized doesn't support `stdClass` yet.
29-
// This may be removed when Symfony 5.1 is released.
3029
if ($data instanceof \stdClass) {
31-
$data = (array) $data;
30+
$serializerVersion = InstalledVersions::getVersion('symfony/serializer');
31+
32+
if (version_compare($serializerVersion, '5.1.0.0') < 0) {
33+
// The Symfony serializer (before 5.1 version) doesn't support `stdClass`.
34+
$data = (array) $data;
35+
}
3236
}
3337

3438
return $this->dedent(

0 commit comments

Comments
 (0)