Passed
Push — deprecate/getLogEntriesForPage... ( 209510...c5a454 )
by Tomas Norre
09:05 queued 05:28
created

JsonCompatibilityConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 11
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Converter;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
class JsonCompatibilityConverter
23
{
24
    /**
25
     * This is implemented as we want to switch away from serialized data to json data, when the crawler is storing
26
     * in the database. To ensure that older crawler entries, which have already been stored as serialized data
27
     * still works, we have added this converter that can be used for the reading part. The writing part will be done
28
     * in json from now on.
29
     * @see https://github.com/AOEpeople/crawler/issues/417
30
     *
31
     * @return array|bool
32
     */
33
    public function convert(string $dataString)
34
    {
35
        $unserialized = unserialize($dataString, ['allowed_classes' => false]);
36
        if ($unserialized) {
37
            return $unserialized;
38
        }
39
40
        $decoded = json_decode($dataString, true);
41
        if ($decoded) {
42
            return $decoded;
43
        }
44
45
        return false;
46
    }
47
}
48