Passed
Branch feature/6.x (3df42d)
by Schlaefer
08:49
created

SerializeType::marshal()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace App\Database\Type;
14
15
use Cake\Database\DriverInterface;
16
use Cake\Database\Type\BaseType;
0 ignored issues
show
Bug introduced by
The type Cake\Database\Type\BaseType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use PDO;
18
19
class SerializeType extends BaseType
20
{
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function toPHP($value, DriverInterface $driver)
26
    {
27
        if ($value === null) {
28
            return null;
29
        }
30
        if (empty($value)) {
31
            return [];
32
        }
33
34
        return unserialize($value);
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function toDatabase($value, DriverInterface $driver)
41
    {
42
        return serialize($value);
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function toStatement($value, DriverInterface $driver)
49
    {
50
        if ($value === null) {
51
            return PDO::PARAM_NULL;
52
        }
53
54
        return PDO::PARAM_STR;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function marshal($value): ?int
61
    {
62
        if ($value === null || $value === '') {
63
            return null;
64
        }
65
66
        return $value;
67
    }
68
}
69