Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Base64Blob
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
4.05
0.00% covered (danger)
0.00%
0 / 1
 convertToDatabaseValue
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 convertToPHPValue
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Satag\AmicronEntityBundle\Doctrine;
6
7use Doctrine\DBAL\Platforms\AbstractPlatform;
8use Doctrine\DBAL\Types\BlobType;
9use Doctrine\DBAL\Types\ConversionException;
10
11class Base64Blob extends BlobType
12{
13    /**
14     * @return false|string|null
15     */
16    #[\Override]
17    public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
18    {
19        if ($value !== null) {
20            return base64_decode((string) $value, true);
21        }
22
23        return null;
24    }
25
26    /**
27     * @return string|null
28     *
29     * @throws ConversionException
30     * @throws ConversionException
31     */
32    #[\Override]
33    public function convertToPHPValue($value, AbstractPlatform $platform): mixed
34    {
35        $stream = parent::convertToPHPValue($value, $platform);
36        if (\is_resource($stream)) {
37            return base64_encode((string) stream_get_contents($stream));
38        }
39
40        return null;
41    }
42}