Skip to content

Commit

Permalink
cs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jan 30, 2025
1 parent 87a4883 commit 1797f5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Fork/ForkContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use function Amp\Parallel\Ipc\connect;
use function count;
use function define;
use function extension_loaded;
use function fwrite;
use function is_file;
use function is_string;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static function start(
?Cancellation $cancellation = null,
int $childConnectTimeout = self::DEFAULT_START_TIMEOUT,
): self {
$serializer = extension_loaded('igbinary')
$serializer = extension_loaded('igbinary')
? new IgbinarySerializer
: new NativeSerializer;

Expand Down
34 changes: 23 additions & 11 deletions src/Psalm/Internal/Fork/IgbinarySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,47 @@

use Amp\Serialization\SerializationException;
use Amp\Serialization\Serializer;
use Throwable;

use function igbinary_serialize;
use function igbinary_unserialize;
use function sprintf;

/**
* @internal
*/
final class IgbinarySerializer implements Serializer
{
public function __construct()
{
}

public function serialize($data): string
{
try {
return \igbinary_serialize($data);
} catch (\Throwable $exception) {
$data = igbinary_serialize($data);
if ($data === false) {
throw new SerializationException("Could not serialize data!");
}
return $data;
} catch (Throwable $exception) {
throw new SerializationException(
\sprintf('The given data could not be serialized: %s', $exception->getMessage()),
sprintf(
'The given data could not be serialized: %s',
$exception->getMessage(),
),
0,
$exception
$exception,
);
}
}

public function unserialize(string $data)
{
try {
return \igbinary_unserialize($data);
} catch (\Throwable $exception) {
throw new SerializationException('Exception thrown when unserializing data', 0, $exception);
return igbinary_unserialize($data);
} catch (Throwable $exception) {
throw new SerializationException(
'Exception thrown when unserializing data',
0,
$exception,
);
}
}
}

0 comments on commit 1797f5a

Please sign in to comment.