Passed
Push — master ( 9ca437...4484fd )
by Scrutinizer
01:32
created

Parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 20
c 3
b 1
f 0
dl 0
loc 35
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 33 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KEINOS\MSTDN_TOOLS;
6
7
final class Parser extends ParserProtectedMethods implements ParserInterface, ParserConstants
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' => "${id_toot}"
24
            ]);
25
            return $result;
26
        }
27
28
        if ($this->isFlagUpEventUpdate()) {
29
            if (false !== $payload_array = $this->bufferPayloadUpdate($line)) {
30
                $this->resetFlags();
31
                $this->clearBuffer();
32
33
                $result = json_encode([
34
                    'event'   => 'update',
35
                    'payload' => $payload_array
36
                ]);
37
                return $result;
38
            }
39
        }
40
41
        return false;
42
    }
43
}
44