Passed
Push — master ( c49abf...239941 )
by Scrutinizer
02:00
created

Parser::parse()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 6
eloc 19
c 3
b 1
f 0
nc 5
nop 1
dl 0
loc 33
rs 9.0111
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