TwitterCard::setSite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MadWeb\Seoable\Protocols;
4
5
use MadWeb\Seoable\Fields\TwitterCard\Description;
6
use MadWeb\Seoable\Fields\TwitterCard\Images;
7
use MadWeb\Seoable\Fields\TwitterCard\Site;
8
use MadWeb\Seoable\Fields\TwitterCard\Title;
9
use MadWeb\Seoable\Fields\TwitterCard\Type;
10
use MadWeb\Seoable\Fields\TwitterCard\Url;
11
use MadWeb\Seoable\Fields\TwitterCard\Values;
12
13
/**
14
 * @method TwitterCard setTitleRaw(string $value)
15
 * @method TwitterCard setDescriptionRaw(string $value)
16
 * @method TwitterCard setUrlRaw(string $value)
17
 * @method TwitterCard setSiteRaw(string $value)
18
 * @method TwitterCard setTypeRaw(string $value)
19
 * @method TwitterCard setImagesRaw(array|string $value)
20
 * @method TwitterCard setValuesRaw(array $value)
21
 * @method TwitterCard addValueRaw(string $key, mixed $value)
22
 */
23
class TwitterCard extends Protocol
24
{
25
    /** @param array|string $value */
26 3
    public function setTitle($value, string $templateKey = ''): self
27
    {
28 3
        $this->twitterCardService->setTitle($this->parseValue(
29 3
            $value,
30 3
            $templateKey ? new Title($value, $this->model, $templateKey) : Title::class
31
        ));
32
33 3
        return $this;
34
    }
35
36
    /** @param array|string $value */
37 3
    public function setDescription($value, string $templateKey = ''): self
38
    {
39 3
        $this->twitterCardService->setDescription($this->parseValue(
40 3
            $value,
41 3
            $templateKey ? new Description($value, $this->model, $templateKey) : Description::class
42
        ));
43
44 3
        return $this;
45
    }
46
47 3
    public function setUrl(string $value): self
48
    {
49 3
        $this->twitterCardService->setUrl($this->parseValue($value, Url::class));
50
51 3
        return $this;
52
    }
53
54 3
    public function setSite(string $value): self
55
    {
56 3
        $this->twitterCardService->setSite($this->parseValue($value, Site::class));
57
58 3
        return $this;
59
    }
60
61 3
    public function setType(string $value): self
62
    {
63 3
        $this->twitterCardService->setType($this->parseValue($value, Type::class));
64
65 3
        return $this;
66
    }
67
68
    /** @param array|string $value */
69 3
    public function setImages($value): self
70
    {
71 3
        $this->twitterCardService->setImage($this->parseValue($value, Images::class));
72
73 3
        return $this;
74
    }
75
76 3
    public function setValues(array $value): self
77
    {
78 3
        foreach ($this->parseValue($value, Values::class) as $item) {
79 3
            $this->twitterCardService->addValue(...array_values($item));
0 ignored issues
show
Bug introduced by
The call to addValue() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
array_values($item) is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
        }
81
82 3
        return $this;
83
    }
84
85
    /** @param array|string $value */
86 3
    public function addValue(string $key, $value): self
87
    {
88 3
        $this->twitterCardService->addValue(
0 ignored issues
show
Bug introduced by
The call to addValue() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
89 3
            ...array_values(
0 ignored issues
show
Documentation introduced by
array_values($this->pars...Card\Values::class)[0]) is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90 3
                $this->parseValue([compact('key', 'value')], Values::class)[0]
91
            )
92
        );
93
94 3
        return $this;
95
    }
96
97 3
    protected function getRawFields(): array
98
    {
99 3
        return $this->modelSeoData['twitter_card'] ?? [];
100
    }
101
}
102