Completed
Push — site-variables ( 7710cc )
by Arnaud
01:59
created

Site::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Renderer;
10
11
use Cecil\Builder;
12
use Cecil\Collection\Page\Page;
13
use Cecil\Exception\Exception;
14
15
/**
16
 * Class Site.
17
 */
18
class Site implements \ArrayAccess
19
{
20
    /**
21
     * Builder object.
22
     *
23
     * @var Builder
24
     */
25
    protected $builder;
26
27
    /**
28
     * Site constructor.
29
     *
30
     * @param Builder $builder
31
     */
32
    public function __construct(Builder $builder)
33
    {
34
        $this->builder = $builder;
35
    }
36
37
    /**
38
     * Implement ArrayAccess.
39
     *
40
     * @param mixed $offset
41
     *
42
     * @return bool
43
     */
44
    public function offsetExists($offset)
45
    {
46
        return $this->builder->getConfig()->getAll()->has($offset);
47
    }
48
49
    /**
50
     * Implement ArrayAccess.
51
     *
52
     * @param mixed $offset
53
     *
54
     * @return mixed|null
55
     */
56
    public function offsetGet($offset)
57
    {
58
        switch ($offset) {
59
            case 'taxonomies':
60
                return $this->builder->getTaxonomies();
61
            case 'language':
62
                return new Language($this->builder->getConfig());
63
        }
64
65
        return $this->builder->getConfig()->getAll()->get($offset);
66
    }
67
68
    /**
69
     * Implement ArrayAccess.
70
     *
71
     * @param mixed $offset
72
     * @param mixed $value
73
     */
74
    public function offsetSet($offset, $value)
75
    {
76
        return $this->builder->getConfig()->getAll()->set($offset, $value);
77
    }
78
79
    /**
80
     * Implement ArrayAccess.
81
     *
82
     * @param mixed $offset
83
     */
84
    public function offsetUnset($offset)
85
    {
86
        return $this->builder->getConfig()->getAll()->remove($offset);
87
    }
88
89
    /**
90
     * All pages, filtered by published status.
91
     */
92
    public function getPages()
93
    {
94
        return $this->builder->getPages()->filter(function (Page $page) {
0 ignored issues
show
Unused Code introduced by
The parameter $page is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
            return true;
96
            return $page->getVariable('published');
0 ignored issues
show
Unused Code introduced by
return $page->getVariable('published'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
97
        });
98
    }
99
100
    /**
101
     * Navigation menus.
102
     */
103
    public function getMenus()
104
    {
105
        return $this->builder->getMenus();
106
    }
107
108
    /**
109
     * Current time.
110
     */
111
    public function getTime()
112
    {
113
        return time();
114
    }
115
}
116