Parser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 35 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KEINOS\MSTDN_TOOLS\Parser;
6
7
final class Parser extends ParserProtectedMethods implements ParserInterface
8
{
9
    public function parse(string $line)
10
    {
11
        if ($this->isSkippable($line)) {
12
            return false; // Return false to skip further process
13
        }
14
15
        if ($this->isFlagUpEventDelete() && self::isDataTootId($line)) {
16
            $id_toot = self::extractDataFromString($line);
17
18
            $this->resetFlags();
19
            $this->clearBuffer();
20
21
            $result = json_encode([
22
                    'event'   => 'delete',
23
                    'payload' => [
24
                        'id' => "${id_toot}"
25
                    ],
26
            ]);
27
            return $result;
28
        }
29
30
        if ($this->isFlagUpEventUpdate()) {
31
            if (false !== $payload_array = $this->bufferPayloadUpdate($line)) {
32
                $this->resetFlags();
33
                $this->clearBuffer();
34
35
                $result = json_encode([
36
                    'event'   => 'update',
37
                    'payload' => $payload_array
38
                ]);
39
                return $result;
40
            }
41
        }
42
43
        return false;
44
    }
45
}
46