Completed
Push — dev-master ( 6d999a...6012ae )
by Vijay
03:00
created

Page::page()   D

Complexity

Conditions 9
Paths 21

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 21
nop 2
dl 0
loc 32
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace FFCMS\Controllers;
4
5
use FFCMS\{Mappers};
6
7
8
/**
9
 * Index Controller Class.
10
 *
11
 * @author Vijay Mahrra <[email protected]>
12
 * @copyright (c) Copyright 2016 Vijay Mahrra
13
 * @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
14
 */
15
class Page extends Base
16
{
17
    protected $template_path = 'pages/';
18
19
    /**
20
     * Render a published page unless not published yet
21
     *
22
     * @param \Base $f3
23
     * @param array $params
24
     * @return void
25
     */
26
    public function page(\Base $f3, array $params = [])
27
    {
28
        if (empty($params['slug'])) {
29
            // 404
30
            echo 'page does not exist';
31
            die(404);
32
        }
33
34
        $page = new Mappers\Pages;
35
        $page->load(['slug = ?', $params['slug']]);
36
37
        // conditions if page is viewable
38
        $publishTime = strtotime($page->published);
39
        $expireTime = strtotime($page->expires);
0 ignored issues
show
Documentation introduced by
The property expires does not exist on object<FFCMS\Mappers\Pages>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40
        $showPage = $f3->get('REQUEST.preview') || (
41
            'published' == $page->status &&
42
            'public' == $page->scopes &&
43
            'page' == $page->category &&
44
            time() > $publishTime &&
45
            (0 >= $expireTime || $expireTime > time())
46
        );
47
48
        if (!$showPage) {
49
            // 404
50
            echo 'page unavailable';
51
            die(404);
52
        }
53
54
        $f3->set('pagesMapper', $page);
55
56
        echo \View::instance()->render($this->template_path . '/page.phtml');
57
    }
58
}
59