Completed
Push — master ( 4de43c...7a7d43 )
by Paul
06:26
created

BasePage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 42
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B getWebViewChildren() 0 18 7
1
<?php
2
3
namespace Victoire\Bundle\PageBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessTemplate;
7
use Victoire\Bundle\CoreBundle\Entity\View;
8
use Victoire\Bundle\CoreBundle\Entity\WebViewInterface;
9
10
/**
11
 * Page.
12
 *
13
 * @ORM\Entity(repositoryClass="Victoire\Bundle\PageBundle\Repository\BasePageRepository")
14
 * @ORM\Table("vic_base_page")
15
 * @ORM\HasLifecycleCallbacks
16
 */
17
abstract class BasePage extends View implements WebViewInterface
0 ignored issues
show
introduced by
Abstract class name is not prefixed with "Abstract"
Loading history...
18
{
19
    use \Victoire\Bundle\PageBundle\Entity\Traits\WebViewTrait;
20
21
    /**
22
     * Construct.
23
     **/
24
    public function __construct()
25
    {
26
        parent::__construct();
27
        $this->publishedAt = new \DateTime();
28
        $this->status = PageStatus::PUBLISHED;
29
        $this->homepage = false;
0 ignored issues
show
Documentation Bug introduced by
The property $homepage was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
30
    }
31
32
    /**
33
     * Get WebView children.
34
     * Exclude unpublished or not published yet if asked.
35
     *
36
     * @param bool $excludeUnpublished
37
     *
38
     * @return string
39
     */
40
    public function getWebViewChildren($excludeUnpublished = false)
41
    {
42
        $webViewChildren = [];
43
        foreach ($this->children as $child) {
44
            if (!$child instanceof BusinessTemplate) {
45
                $notPublished = $child->getStatus() != PageStatus::PUBLISHED;
46
                $scheduledDateNotReached = $child->getStatus() == PageStatus::SCHEDULED && $child->getPublishedAt() > new \DateTime();
47
48
                if ($excludeUnpublished && ($notPublished || $scheduledDateNotReached)) {
49
                    continue;
50
                }
51
52
                $webViewChildren[] = $child;
53
            }
54
        }
55
56
        return $webViewChildren;
57
    }
58
}
59