AbstractTask   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 29
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 20 3
A getType() 0 5 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