SixConnexCall   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 62
ccs 27
cts 27
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setApiCall() 0 14 2
A options() 0 3 1
A getCallBody() 0 4 1
A __construct() 0 4 1
A overrideOptions() 0 5 1
A addOption() 0 9 2
1
<?php
2
3
4
namespace LaravelSixConnex;
5
6
use \LaravelSixConnex\Exceptions\SixConnexException;
0 ignored issues
show
Bug introduced by
The type \LaravelSixConnex\Exceptions\SixConnexException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class SixConnexCall implements CallBody
9
{
10
    public static string $typeParameter = '_apicall';
11
12
    protected string $type;
13
    protected array $options;
14
15 8
    public function __construct(array $options = [], ?string $type = null)
16
    {
17 8
        $this->options = $options;
18 8
        $this->setApiCall($type ?? static::TYPE_READ);
19
    }
20
21 8
    public function setApiCall(string $type = 'read'): self
22
    {
23 8
        if (!in_array($type, [
24 8
            static::TYPE_READ,
25 8
            static::TYPE_READALL,
26 8
            static::TYPE_CREATE,
27 8
            static::TYPE_UPDATE,
28 8
            static::TYPE_DELETE,
29 8
        ])) {
30 1
            throw new SixConnexException('Not valid ' . static::$typeParameter);
31
        }
32 8
        $this->type = $type;
33
34 8
        return $this;
35
    }
36
37 1
    public function options(): array
38
    {
39 1
        return $this->options;
40
    }
41
42
    /**
43
     * @param $key
44
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
45
     *
46
     * @return $this
47
     */
48 5
    public function addOption($key, $value = null): self
49
    {
50 5
        if (is_array($key)) {
51 2
            $this->options = array_merge($this->options, $key);
52
        } else {
53 4
            $this->options[ $key ] = $value;
54
        }
55
56 5
        return $this;
57
    }
58
59 1
    public function overrideOptions(array $options): self
60
    {
61 1
        $this->options = $options;
62
63 1
        return $this;
64
    }
65
66 4
    public function getCallBody(): array
67
    {
68 4
        return array_merge($this->options, [
69 4
            static::$typeParameter => $this->type,
70 4
        ]);
71
    }
72
}
73