AbstractTask::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Anticaptcha\Task;
4
5
use Anticaptcha\Entity;
6
use ReflectionClass;
7
use ReflectionProperty;
8
9
abstract class AbstractTask extends Entity
10
{
11 2
    public function getType(): string
12
    {
13 2
        $parts = explode('\\', static::class);
14
15 2
        return end($parts);
16
    }
17
18 1
    public function toArray(): array
19
    {
20 1
        $obj = new ReflectionClass(static::class);
21
22 1
        $attributes = [
23 1
            'type' => $this->getType()
24
        ];
25
26 1
        foreach ($obj->getProperties(ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
27 1
            $name = $reflectionProperty->getName();
28 1
            $value = $this->$name ?? null;
29
30 1
            if (is_null($value)) {
31
                continue;
32
            }
33
34 1
            $attributes[$name] = $value;
35
        }
36
37 1
        return $attributes;
38
    }
39
}
40