Completed
Push — master ( 5d51b4...87fdd9 )
by Paul
10s
created

Bundle/PageBundle/Entity/Traits/WebViewTrait.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Victoire\Bundle\PageBundle\Entity\Traits;
4
5
use Symfony\Component\PropertyAccess\PropertyAccess;
6
use Victoire\Bundle\CoreBundle\Annotations as VIC;
7
use Victoire\Bundle\PageBundle\Entity\PageStatus;
8
use Victoire\Bundle\SeoBundle\Entity\PageSeo;
9
10
/**
11
 * This trait make a view displayable for public.
12
 */
13
trait WebViewTrait
14
{
15
    /**
16
     * @ORM\OneToOne(targetEntity="\Victoire\Bundle\SeoBundle\Entity\PageSeo", cascade={"persist", "remove"})
17
     * @ORM\JoinColumn(name="seo_id", referencedColumnName="id", onDelete="SET NULL")
18
     */
19
    protected $seo;
20
21
    /**
22
     * @ORM\OneToMany(targetEntity="Victoire\Bundle\SeoBundle\Entity\PageSeo", mappedBy="redirectTo")
23
     */
24
    protected $referers;
25
26
    /**
27
     * @ORM\Column(name="status", type="string", nullable=false)
28
     */
29
    protected $status = PageStatus::PUBLISHED;
30
31
    /**
32
     * @var \Datetime
33
     *
34
     * @ORM\Column(name="publishedAt", type="datetime")
35
     * @VIC\BusinessProperty("date")
36
     */
37
    protected $publishedAt;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(name="homepage", type="boolean", nullable=false)
43
     */
44
    protected $homepage;
45
46
    /**
47
     * Set seo.
48
     *
49
     * @param PageSeo $seo
50
     *
51
     * @return WebViewTrait
52
     */
53
    public function setSeo(PageSeo $seo)
54
    {
55
        $this->seo = $seo;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Get seo.
62
     *
63
     * @return PageSeo
64
     */
65
    public function getSeo()
66
    {
67
        return $this->seo;
68
    }
69
70
    /**
71
     * Get referers.
72
     *
73
     * @return string
74
     */
75
    public function getReferers()
76
    {
77
        return $this->referers;
78
    }
79
80
    /**
81
     * Set the refere.
82
     *
83
     * @param string $referers
84
     */
85
    public function setReferers($referers)
86
    {
87
        $this->referers = $referers;
88
    }
89
90
    /**
91
     * Set status.
92
     *
93
     * @param string $status
94
     */
95
    public function setStatus($status)
96
    {
97
        $this->status = $status;
98
    }
99
100
    /**
101
     * Get status.
102
     *
103
     * @return string
104
     */
105
    public function getStatus()
106
    {
107
        return $this->status;
108
    }
109
110
    /**
111
     * Set publishedAt.
112
     *
113
     * @param \DateTime $publishedAt
114
     */
115
    public function setPublishedAt($publishedAt)
116
    {
117
        $this->publishedAt = $publishedAt;
118
    }
119
120
    /**
121
     * Get publishedAt.
122
     *
123
     * @return \DateTime
124
     */
125
    public function getPublishedAt()
126
    {
127
        return $this->publishedAt;
128
    }
129
130
    /**
131
     * Is this page published.
132
     *
133
     * @return bool
134
     */
135
    public function isPublished()
136
    {
137
        if (
138
            $this->getStatus() === PageStatus::PUBLISHED ||
139
            ($this->getStatus() === PageStatus::SCHEDULED &&
140
            $this->getPublishedAt() < new \DateTime())
141
            ) {
142
            return true;
143
        } else {
144
            return false;
145
        }
146
    }
147
148
    /**
149
     * Get homepage.
150
     *
151
     * @return bool
152
     */
153
    public function isHomepage()
154
    {
155
        return $this->homepage;
156
    }
157
158
    /**
159
     * Set homepage.
160
     *
161
     * @param bool $homepage
162
     *
163
     * @return $this
164
     */
165
    public function setHomepage($homepage)
166
    {
167
        $this->homepage = $homepage;
168
169
        return $this;
170
    }
171
172
    public function getUrl()
173
    {
174
        return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getUrl');
0 ignored issues
show
It seems like translate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
175
    }
176
177
    public function setUrl($name, $locale = null)
178
    {
179
        $this->translate($locale)->setUrl($name);
0 ignored issues
show
It seems like translate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
180
    }
181
}
182