ComponentServices::toCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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