Completed
Pull Request — master (#9)
by
unknown
09:21
created

ProductSeo::getImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JoppeDc\SyliusBetterSeoPlugin\Entity;
6
7
use Sylius\Component\Product\Model\ProductInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, JoppeDc\SyliusBetterSeoP...Entity\ProductInterface. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Sylius\Component\Resource\Model\ResourceInterface;
9
use Sylius\Component\Resource\Model\TranslatableInterface;
10
use Sylius\Component\Resource\Model\TranslatableTrait;
11
use Sylius\Component\Resource\Model\TranslationInterface;
12
13
class ProductSeo implements TranslatableInterface, ResourceInterface
14
{
15
    use TranslatableTrait {
16
        __construct as private initializeTranslationsCollection;
17
        getTranslation as private doGetTranslation;
18
    }
19
20
    /**
21
     * @var int|null
22
     */
23
    protected $id;
24
25
    /**
26
     * @var ProductInterface|null
27
     */
28
    private $product;
29
30
    public function __construct()
31
    {
32
        $this->initializeTranslationsCollection();
33
    }
34
35
    public function __toString()
36
    {
37
        return (string) $this->getId();
38
    }
39
40
    public function getPageTitle(): ?string
41
    {
42
        return $this->getTranslation()->getPageTitle();
43
    }
44
45
    public function setPageTitle(?string $pageTitle): void
46
    {
47
        $this->getTranslation()->setPageTitle($pageTitle);
48
    }
49
50
    public function getOgTitle(): ?string
51
    {
52
        return $this->getTranslation()->getOgTitle();
53
    }
54
55
    public function setOgTitle(?string $ogTitle): void
56
    {
57
        $this->getTranslation()->setOgTitle($ogTitle);
58
    }
59
60
    public function getOgDescription(): ?string
61
    {
62
        return $this->getTranslation()->getOgDescription();
63
    }
64
65
    public function setOgDescription(?string $ogDescription): void
66
    {
67
        $this->getTranslation()->setOgDescription($ogDescription);
68
    }
69
70
    public function getTwitterTitle(): ?string
71
    {
72
        return $this->getTranslation()->getTwitterTitle();
73
    }
74
75
    public function setTwitterTitle(?string $twitterTitle): void
76
    {
77
        $this->getTranslation()->setTwitterTitle($twitterTitle);
78
    }
79
80
    public function getTwitterDescription(): ?string
81
    {
82
        return $this->getTranslation()->getTwitterDescription();
83
    }
84
85
    public function setTwitterDescription(?string $twitterDescription): void
86
    {
87
        $this->getTranslation()->setTwitterDescription($twitterDescription);
88
    }
89
90
    public function getTwitterSite(): ?string
91
    {
92
        return $this->getTranslation()->getTwitterSite();
93
    }
94
95
    public function setTwitterSite(?string $twitterSite): void
96
    {
97
        $this->getTranslation()->setTwitterSite($twitterSite);
98
    }
99
100
    public function getExtraTags(): ?string
101
    {
102
        return $this->getTranslation()->getExtraTags();
103
    }
104
105
    public function setExtraTags(?string $extraTags): void
106
    {
107
        $this->getTranslation()->setExtraTags($extraTags);
108
    }
109
110
    public function getImage(): ?string
111
    {
112
        return $this->getTranslation()->getImage();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getTranslation()->getImage() returns the type Sylius\Component\Core\Model\ImageInterface which is incompatible with the type-hinted return null|string.
Loading history...
113
    }
114
115
    public function setImage(?string $image): void
116
    {
117
        $this->getTranslation()->setImage($image);
0 ignored issues
show
Bug introduced by
It seems like $image can also be of type string; however, parameter $image of JoppeDc\SyliusBetterSeoP...Translation::setImage() does only seem to accept Sylius\Component\Core\Model\ImageInterface|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        $this->getTranslation()->setImage(/** @scrutinizer ignore-type */ $image);
Loading history...
118
    }
119
120
    public function getId()
121
    {
122
        return $this->id;
123
    }
124
125
    public function setId(?int $id): void
126
    {
127
        $this->id = $id;
128
    }
129
130
    /**
131
     * @return ProductSeoTranslation
132
     */
133
    public function getTranslation(?string $locale = null): TranslationInterface
134
    {
135
        /** @var ProductSeoTranslation $translation */
136
        $translation = $this->doGetTranslation($locale);
137
138
        return $translation;
139
    }
140
141
    public function getProduct(): ?ProductInterface
142
    {
143
        return $this->product;
144
    }
145
146
    public function setProduct(?ProductInterface $product): void
147
    {
148
        $this->product = $product;
149
    }
150
151
    protected function createTranslation(): ProductSeoTranslation
152
    {
153
        return new ProductSeoTranslation();
154
    }
155
}
156