Completed
Push — master ( 8f5f7c...7faed5 )
by Basenko
04:23
created

TwitterCard::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace MadWeb\Seoable\Protocols;
4
5
use MadWeb\Seoable\Fields\TwitterCard\Url;
6
use MadWeb\Seoable\Fields\TwitterCard\Site;
7
use MadWeb\Seoable\Fields\TwitterCard\Type;
8
use MadWeb\Seoable\Fields\TwitterCard\Title;
9
use MadWeb\Seoable\Fields\TwitterCard\Images;
10
use MadWeb\Seoable\Fields\TwitterCard\Values;
11
use MadWeb\Seoable\Fields\TwitterCard\Description;
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
    public function setTitle($value, string $templateKey = ''): self
27
    {
28
        $this->twitterCardService->setTitle($this->parseValue(
29
            $value,
30
            $templateKey ? new Title($value, $this->model, $templateKey) : Title::class
31
        ));
32
33
        return $this;
34
    }
35
36
    /** @param array|string $value */
37
    public function setDescription($value, string $templateKey = ''): self
38
    {
39
        $this->twitterCardService->setDescription($this->parseValue(
40
            $value,
41
            $templateKey ? new Description($value, $this->model, $templateKey) : Description::class
42
        ));
43
44
        return $this;
45
    }
46
47
    public function setUrl(string $value): self
48
    {
49
        $this->twitterCardService->setUrl($this->parseValue($value, Url::class));
50
51
        return $this;
52
    }
53
54
    public function setSite(string $value): self
55
    {
56
        $this->twitterCardService->setSite($this->parseValue($value, Site::class));
57
58
        return $this;
59
    }
60
61
    public function setType(string $value): self
62
    {
63
        $this->twitterCardService->setType($this->parseValue($value, Type::class));
64
65
        return $this;
66
    }
67
68
    /** @param array|string $value */
69
    public function setImages($value): self
70
    {
71
        $this->twitterCardService->setImages($this->parseValue($value, Images::class));
0 ignored issues
show
Deprecated Code introduced by
The method Artesaos\SEOTools\TwitterCards::setImages() has been deprecated with message: use setImage($image) instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
72
73
        return $this;
74
    }
75
76
    public function setValues(array $value): self
77
    {
78
        foreach ($this->parseValue($value, Values::class) as $item) {
79
            $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
        return $this;
83
    }
84
85
    /** @param array|string $value */
86
    public function addValue(string $key, $value): self
87
    {
88
        $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
            ...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
                $this->parseValue([compact('key', 'value')], Values::class)[0]
91
            )
92
        );
93
94
        return $this;
95
    }
96
97
    protected function getRawFields(): array
98
    {
99
        return $this->modelSeoData['twitter_card'];
100
    }
101
}
102