Test Failed
Pull Request — master (#140)
by Litera
10:13
created

BasePresenter::logError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Presenters;
4
5
use Nette,
6
	App\Model;
7
use Nette\Utils\Strings;
8
use Nette\Http\Request;
9
use App\Models\SunlightModel;
10
use Nette\Caching\Cache;
11
use App\Traits\Loggable;
12
13
/**
14
 * Base presenter for all application presenters.
15
 */
16
abstract class BasePresenter extends Nette\Application\UI\Presenter
17
{
18
19
	use Loggable;
20
21
	const FLASH_TYPE_OK    = 'success';
22
	const FLASH_TYPE_ERROR = 'error';
23
24
	/**
25
	 * @var string
26
	 */
27
	public $backlink = '';
28
29
	/** @var Model */
30
	protected $model;
31
32
	/** @var Nette\DI\Container */
33
	protected $container;
34
35
	/** @var Latte */
36
	protected $latte;
37
38
	/** @var Router */
39
	protected $router;
40
41
	/** @var string */
42
	protected $action;
43
44
	/** @var Nette\Http\Request */
45
	protected $request;
46
47
	/** @var integer */
48
	protected $meetingId;
49
50
	protected $days = [
51
		'pátek'		=> 'pátek',
52
		'sobota'	=> 'sobota',
53
		'neděle'	=> 'neděle',
54
	];
55
56
	protected $hours = [
57
		0 => "00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"
58
	];
59
60
	protected $minutes = [
61
		00 => "00",
62
		05 => "05",
63
		10 => "10",
64
		15 => "15",
65
		20 => "20",
66
		25 => "25",
67
		30 => "30",
68
		35 => "35",
69
		40 => "40",
70
		45 => "45",
71
		50 => "50",
72
		55 => "55",
73
	];
74
75
	/**
76
	 * Startup
77
	 */
78
	protected function startup()
0 ignored issues
show
Coding Style introduced by
startup uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
79
	{
80
		parent::startup();
81
82
		$meetingId = $this->getHttpRequest()->getQuery('mid', '');
83
84
		$backlink = $this->getHttpRequest()->getQuery('backlink');
85
		if(!empty($backlink)) {
86
			$this->setBacklink($backlink);
87
		}
88
89
		if($meetingId){
90
			$_SESSION['meetingID'] = $meetingId;
91
		} elseif(!isset($_SESSION['meetingID'])) {
92
			$meeting = $this->getContainer()->getService('meeting');
93
			$_SESSION['meetingID'] = $meeting->getLastMeetingId();
94
		}
95
96
		$this->setMeetingId($_SESSION['meetingID']);
97
98
		$model = $this->getModel();
99
		if($model) {
100
			$model->setMeetingId($_SESSION['meetingID']);
101
		}
102
103
		$this->debugMode = $this->getContainer()->getParameters()['debugMode'];
104
	}
105
106
107
	/**
108
	 * Before render
109
	 * Prepare variables for template
110
	 */
111
	public function beforeRender()
0 ignored issues
show
Coding Style introduced by
beforeRender uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
112
	{
113
		parent::beforeRender();
114
115
		$template = $this->getTemplate();
116
		$meeting = $this->getContainer()->getService('meeting');
117
118
		$template->baseDir = ROOT_DIR;
0 ignored issues
show
Bug introduced by
Accessing baseDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
119
		$template->wwwDir = HTTP_DIR;
0 ignored issues
show
Bug introduced by
Accessing wwwDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
120
		$template->cssDir = CSS_DIR;
0 ignored issues
show
Bug introduced by
Accessing cssDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
121
		$template->jsDir = JS_DIR;
0 ignored issues
show
Bug introduced by
Accessing jsDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
122
		$template->imgDir = IMG_DIR;
0 ignored issues
show
Bug introduced by
Accessing imgDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
123
		$template->catDir = CAT_DIR;
0 ignored issues
show
Bug introduced by
Accessing catDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
124
		$template->blockDir = BLOCK_DIR;
0 ignored issues
show
Bug introduced by
Accessing blockDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
125
		$template->progDir = PROG_DIR;
0 ignored issues
show
Bug introduced by
Accessing progDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
126
		$template->visitDir = VISIT_DIR;
0 ignored issues
show
Bug introduced by
Accessing visitDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
127
		$template->expDir = EXP_DIR;
0 ignored issues
show
Bug introduced by
Accessing expDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
128
		$template->meetDir = MEET_DIR;
0 ignored issues
show
Bug introduced by
Accessing meetDir on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
129
130
		$template->categories = $this->remember('categories:all', 10, function () {
0 ignored issues
show
Bug introduced by
Accessing categories on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
131
			return $this->getContainer()->getService('category')->all();
132
		});
133
134
		if(isset($_SESSION[SESSION_PREFIX.'user'])) {
135
			$template->user = $this->getSunlight()->findUser($_SESSION[SESSION_PREFIX.'user']);
0 ignored issues
show
Bug introduced by
Accessing user on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
136
		}
137
		$template->meeting = $meeting->getPlaceAndYear($_SESSION['meetingID']);
0 ignored issues
show
Bug introduced by
Accessing meeting on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
138
		$template->menuItems = $meeting->getMenuItems();
0 ignored issues
show
Bug introduced by
Accessing menuItems on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
139
		$template->meeting_heading	= $meeting->getRegHeading();
0 ignored issues
show
Bug introduced by
Accessing meeting_heading on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
140
		$template->meetingId = $this->getMeetingId();
0 ignored issues
show
Bug introduced by
Accessing meetingId on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
141
		$template->backlinkUrl = $this->getBacklinkUrl();
0 ignored issues
show
Bug introduced by
Accessing backlinkUrl on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
142
		$template->backlink = $this->getBacklink();
0 ignored issues
show
Bug introduced by
Accessing backlink on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
143
		//$this->template->backlink = $this->getParameter("backlink");
144
145
		//$this->template->production = $this->context->parameters['environment'] === 'production' ? 1 : 0;
146
		//$this->template->version = $this->context->parameters['site']['version'];
147
	}
148
149
	/**
150
	 * template
151
	 * @var string
152
	 */
153
	protected $template = 'listing';
154
155
	/**
156
	 * template directory
157
	 * @var string
158
	 */
159
	protected $templateDir = '';
160
161
	/**
162
	 * category ID
163
	 * @var integer
164
	 */
165
	protected $itemId = NULL;
166
167
	/**
168
	 * action what to do
169
	 * @var string
170
	 */
171
	protected $cms = '';
172
173
	/**
174
	 * page where to return
175
	 * @var string
176
	 */
177
	protected $page = '';
178
179
	/**
180
	 * heading tetxt
181
	 * @var string
182
	 */
183
	protected $heading = '';
184
185
	/**
186
	 * action what to do next
187
	 * @var string
188
	 */
189
	protected $todo = '';
190
191
	/**
192
	 * data
193
	 * @var array
194
	 */
195
	protected $data = array();
196
197
	/**
198
	 * error handler
199
	 * @var string
200
	 */
201
	protected $error = '';
202
203
	/**
204
	 * database connection
205
	 * @var string
206
	 */
207
	protected $database = NULL;
208
209
	/**
210
	 * debug mode
211
	 * @var boolean
212
	 */
213
	protected $debugMode = false;
214
215
	protected $sunlight;
216
217
	/**
218
	 * Render check box
219
	 *
220
	 * @param	string	name
221
	 * @param	mixed	value
222
	 * @param	var		variable that match with value
223
	 * @return	string	html of chceck box
224
	 */
225
	protected function renderHtmlCheckBox($name, $value, $checked_variable)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $checked_variable is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
226
	{
227
		if($checked_variable == $value) {
228
			$checked = 'checked';
229
		} else {
230
			$checked = '';
231
		}
232
		$html_checkbox = "<input name='".$name."' type='checkbox' value='".$value."' ".$checked." />";
233
234
		return $html_checkbox;
235
	}
236
237
	protected function parseTutorEmail($item)
238
	{
239
		$mails = explode(',', $item->email);
240
		$names = explode(',', $item->tutor);
241
242
		$i = 0;
243
		foreach ($mails as $mail) {
244
			$mail = trim($mail);
245
			$name = trim($names[$i]);
246
247
			$recipient[$mail] = ($name) ? $name : '';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$recipient was never initialized. Although not strictly required by PHP, it is generally a good practice to add $recipient = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
248
		}
249
250
		return $recipient;
0 ignored issues
show
Bug introduced by
The variable $recipient does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
251
	}
252
253
	// zaheshovane udaje, aby se nedali jen tak ziskat data z databaze
254
	protected function formKeyHash($id, $meetingId)
255
	{
256
		return ((int)$id . $meetingId) * 116 + 39147;
257
	}
258
259
	/**
260
	 * @return Model
261
	 */
262
	protected function getModel()
263
	{
264
		return $this->model;
265
	}
266
267
	/**
268
	 * @param  Model $model
269
	 * @return $this
270
	 */
271
	protected function setModel($model)
272
	{
273
		$this->model = $model;
274
		return $this;
275
	}
276
277
	/**
278
	 * @return Container
279
	 */
280
	protected function getContainer()
281
	{
282
		return $this->context;
0 ignored issues
show
Documentation introduced by
The property $context is declared private in Nette\Application\UI\Presenter. 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...
283
	}
284
285
	/**
286
	 * @param  Container $container
287
	 * @return $this
288
	 */
289
	protected function setContainer($container)
290
	{
291
		$this->context = $container;
0 ignored issues
show
Documentation introduced by
The property $context is declared private in Nette\Application\UI\Presenter. Since you implemented __set(), maybe consider adding a @property or @property-write 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...
Documentation Bug introduced by
It seems like $container of type object<App\Presenters\Container> is incompatible with the declared type object<Nette\DI\Container> of property $context.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
292
		return $this;
293
	}
294
295
	/**
296
	 * @return Router
297
	 */
298
	protected function getRouter()
299
	{
300
		return $this->router;
301
	}
302
303
	/**
304
	 * @param  Router $router
305
	 * @return $this
306
	 */
307
	protected function setRouter($router)
308
	{
309
		$this->router = $router;
310
		return $this;
311
	}
312
313
	/**
314
	 * @return Latte
315
	 */
316
	protected function getLatte()
317
	{
318
		return $this->latte;
319
	}
320
321
	/**
322
	 * @param  Latte $latte
323
	 * @return $this
324
	 */
325
	protected function setLatte($latte)
326
	{
327
		$this->latte = $latte;
328
		return $this;
329
	}
330
331
	/**
332
	 * @return string
333
	 */
334
	public function getAction($fullyQualified = false)
335
	{
336
		return $this->action;
337
	}
338
339
	/**
340
	 * @param  string $action
341
	 * @return $this
342
	 */
343
	public function setAction($action)
344
	{
345
		$this->action = $action;
346
		return $this;
347
	}
348
349
	/**
350
	 * @return SunlightModel
351
	 */
352
	public function getSunlight()
353
	{
354
		if(empty($this->sunlight)) {
355
			$this->setSunlight($this->getContainer()->getService('sunlight'));
356
		}
357
358
		return $this->sunlight;
359
	}
360
361
	/**
362
	 * @param  SunlightModel $sunlight
363
	 * @return $this
364
	 */
365
	public function setSunlight(SunlightModel $sunlight)
366
	{
367
		$this->sunlight = $sunlight;
368
		return $this;
369
	}
370
371
	/**
372
	 * @return integer
373
	 */
374
	protected function getMeetingId()
375
	{
376
		return $this->meetingId;
377
	}
378
379
	/**
380
	 * @param  integer  $meetingId
381
	 * @return $this
382
	 */
383
	protected function setMeetingId($meetingId)
384
	{
385
		$this->meetingId = $meetingId;
386
		return $this;
387
	}
388
389
	/**
390
	 * @param  string $guid
391
	 * @param  array  $data
392
	 * @return ActiveRow
393
	 */
394
	protected function updateByGuid($guid, array $data)
395
	{
396
		return $this->getModel()->updateBy('guid', $guid, $data);
397
	}
398
399
	public function remember($key, $minutes, \Closure $callback)
400
	{
401
		// If the item exists in the cache we will just return this immediately
402
		// otherwise we will execute the given Closure and cache the result
403
		// of that execution for the given number of minutes in storage.
404
		if (! is_null($data = $this->getCache()->load($key))) {
405
			$items = [];
406
407
			foreach($data as $item) {
408
				$object = new \stdClass();
409
				foreach ($item as $key => $value) {
410
					$object->$key = $value;
411
				}
412
				$items[] = $object;
413
			}
414
415
			return $items;
416
		}
417
418
		$data = $callback();
419
		$serialized = [];
420
		foreach ($data as $item) {
421
			$serialized[] = $item->toArray();
422
		}
423
424
		$this->getCache()->save(
425
			$key,
426
			$serialized,
427
			[
428
				Cache::EXPIRE => $minutes . ' minutes',
429
			]
430
		);
431
432
		return $data;
433
	}
434
435
	protected function getCache()
436
	{
437
		return $this->getContainer()->getService('cache');
438
	}
439
440
	/**
441
	 * @return string
442
	 */
443
	protected function getDebugMode()
444
	{
445
		return $this->debugMode;
446
	}
447
448
	/**
449
	 * @return string
450
	 */
451
	protected function getBacklink()
452
	{
453
		return $this->backlink;
454
	}
455
456
	/**
457
	 * @param  string $backlink
458
	 * @return $this
459
	 */
460
	protected function setBacklink($backlink)
461
	{
462
		$this->backlink = $backlink;
463
464
		return $this;
465
	}
466
467
	/**
468
	 * @return string
469
	 */
470
	protected function getBacklinkUrl()
471
	{
472
		if($this->getBacklink()) {
473
			return $this->link(
474
				$this->getBacklink(),
475
				[
476
					'backlink' => null
477
				]
478
			);
479
		}
480
	}
481
482
	/**
483
	 * Flashes success message
484
	 *
485
	 * @param  string $message Message
486
	 */
487
	protected function flashSuccess(string $message = '')
488
	{
489
		$this->flashMessage($message, self::FLASH_TYPE_OK);
490
	}
491
492
	/**
493
	 * Flashes error message
494
	 *
495
	 * @param  string $message Message
496
	 */
497
	protected function flashError(string $message = '')
498
	{
499
		$this->flashMessage($message, self::FLASH_TYPE_ERROR);
500
	}
501
502
}
503