Error4xxPresenter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 27
c 0
b 0
f 0
rs 10
wmc 6
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A startup() 0 7 2
A renderDefault() 0 6 2
A render404() 0 6 2
1
<?php
2
3
namespace App\Presenters;
4
5
use Nette;
6
7
8
class Error4xxPresenter extends Nette\Application\UI\Presenter
9
{
10
11
	public function startup()
12
	{
13
		parent::startup();
14
		if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
15
			$this->error();
16
		}
17
	}
18
19
20
	public function renderDefault(Nette\Application\BadRequestException $exception)
21
	{
22
		// load template 403.latte or 404.latte or ... 4xx.latte
23
		$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
24
		$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
25
	}
26
27
28
	public function render404(Nette\Application\BadRequestException $exception)
29
	{
30
		$file = __DIR__ . "/../templates/Error/{$exception->getCode()}.latte";
31
		$latte = new \Latte\Engine;
32
		$latte->render(is_file($file) ? $file : __DIR__ . '/../templates/Error/4xx.latte');
33
	}
34
}
35