ComponentServices   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasApi() 0 3 1
A toCollection() 0 3 1
A __construct() 0 5 1
A toArray() 0 3 1
1
<?php
2
3
namespace Joesama\Pintu\Services;
4
5
use ReflectionClass;
6
use Illuminate\Support\Collection;
7
use Joesama\Pintu\Components\Manager;
8
use Illuminate\Contracts\Support\Arrayable;
9
10
class ComponentServices implements Arrayable
11
{
12
    /**
13
     * Component manager.
14
     *
15
     * @var Manager
16
     */
17
    protected $manager;
18
19
    /**
20
     * Initiate Component Services.
21
     *
22
     * @param array $provider
23
     */
24 2
    public function __construct(string $providerNameSpace)
25
    {
26 2
        $provider = new ReflectionClass($providerNameSpace);
27
28 2
        $this->manager = new Manager($provider);
29 1
    }
30
31
    /**
32
     * Return API collection.
33
     *
34
     * @return Collection
35
     */
36 1
    public function hasApi(): Collection
37
    {
38 1
        return $this->manager->getApi();
39
    }
40
41
    /**
42
     * Return response as collection.
43
     *
44
     * @return Collection
45
     */
46 1
    public function toCollection(): Collection
47
    {
48 1
        return $this->manager->getComponent();
49
    }
50
51
    /**
52
     * Return response as array.
53
     *
54
     * @return array
55
     */
56 1
    public function toArray(): array
57
    {
58 1
        return $this->toCollection()->toArray();
59
    }
60
}
61