Passed
Push — master ( 848a13...c93e13 )
by Mauro
02:28
created

SerializeChecker   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 12

1 Method

Rating   Name   Duplication   Size   Complexity  
C isSerialized() 0 33 12
1
<?php
2
/**
3
 * This file is part of the InMemoryList package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 */
10
11
namespace InMemoryList\Domain\Helper;
12
13
class SerializeChecker
14
{
15
    /**
16
     * @param $data
17
     *
18
     * @return bool
19
     */
20
    public static function isSerialized($data)
21
    {
22
        if (!is_string($data)) {
23
            return false;
24
        }
25
26
        $data = trim($data);
27
        if ('N;' === $data) {
28
            return true;
29
        }
30
31
        if (!preg_match('/^([adObis]):/', $data, $badions)) {
32
            return false;
33
        }
34
35
        switch ($badions[1]) {
36
            case 'a':
37
            case 'O':
38
            case 's':
39
                if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data)) {
40
                    return true;
41
                }
42
                break;
43
            case 'b':
44
            case 'i':
45
            case 'd':
46
                if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data)) {
47
                    return true;
48
                }
49
                break;
50
        }
51
52
        return false;
53
    }
54
}