Completed
Pull Request — devel (#144)
by Litera
03:43
created

BasePresenter::renderHtmlCheckBox()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A BasePresenter::setModel() 0 5 1
1
<?php
2
3
namespace App\Presenters;
4
5
use Nette,
6
	App\Model;
7
use Nette\Utils\ArrayHash;
8
use Nette\Utils\Strings;
9
use Nette\Http\Request;
10
use App\Models\SunlightModel;
11
use Nette\Caching\Cache;
12
use App\Traits\Loggable;
13
14
/**
15
 * Base presenter for all application presenters.
16
 */
17
abstract class BasePresenter extends Nette\Application\UI\Presenter
18
{
19
20
	use Loggable;
21
22
	const FLASH_TYPE_OK    = 'success';
23
	const FLASH_TYPE_ERROR = 'error';
24
25
	/**
26
	 * @var string
27
	 */
28
	public $backlink = '';
29
30
	/** @var Model */
31
	protected $model;
32
33
	/** @var Nette\DI\Container */
34
	protected $container;
35
36
	/** @var Latte */
37
	protected $latte;
38
39
	/** @var Router */
40
	protected $router;
41
42
	/** @var string */
43
	protected $action;
44
45
	/** @var Nette\Http\Request */
46
	protected $request;
47
48
	/** @var integer */
49
	protected $meetingId;
50
51
	/**
52
	 * Startup
53
	 */
54
	protected function startup()
55
	{
56
		parent::startup();
57
58
		$meetingId = $this->getHttpRequest()->getQuery('mid', '');
59
60
		$backlink = $this->getHttpRequest()->getQuery('backlink');
61
		if(!empty($backlink)) {
62
			$this->setBacklink($backlink);
63
		}
64
65
		if($meetingId){
66
			$_SESSION['meetingID'] = $meetingId;
67
		} elseif(!isset($_SESSION['meetingID'])) {
68
			$meeting = $this->getContainer()->getService('meeting');
69
			$_SESSION['meetingID'] = $meeting->getLastMeetingId();
70
		}
71
72
		$this->setMeetingId($_SESSION['meetingID']);
73
74
		$model = $this->getModel();
75
		if($model) {
76
			$model->setMeetingId($_SESSION['meetingID']);
77
		}
78
79
		$this->debugMode = $this->getContainer()->getParameters()['debugMode'];
80
	}
81
82
83
	/**
84
	 * Before render
85
	 * Prepare variables for template
86
	 */
87
	public function beforeRender()
88
	{
89
		parent::beforeRender();
90
91
		$template = $this->getTemplate();
92
		$meeting = $this->getContainer()->getService('meeting');
93
94
		$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...
95
		$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...
96
		$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...
97
		$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...
98
		$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...
99
		$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...
100
		$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...
101
		$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...
102
		$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...
103
		$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...
104
		$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...
105
106
		$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...
107
			return $this->getContainer()->getService('category')->all();
108
		});
109
110
		if(isset($_SESSION[SESSION_PREFIX.'user'])) {
111
			$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...
112
		}
113
		$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...
114
		$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...
115
		$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...
116
		$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...
117
		$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...
118
		$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...
119
		//$this->template->backlink = $this->getParameter("backlink");
120
121
		//$this->template->production = $this->context->parameters['environment'] === 'production' ? 1 : 0;
122
		//$this->template->version = $this->context->parameters['site']['version'];
123
	}
124
125
	/**
126
	 * template
127
	 * @var string
128
	 */
129
	protected $template = 'listing';
130
131
	/**
132
	 * template directory
133
	 * @var string
134
	 */
135
	protected $templateDir = '';
136
137
	/**
138
	 * category ID
139
	 * @var integer
140
	 */
141
	protected $itemId = NULL;
142
143
	/**
144
	 * action what to do
145
	 * @var string
146
	 */
147
	protected $cms = '';
148
149
	/**
150
	 * page where to return
151
	 * @var string
152
	 */
153
	protected $page = '';
154
155
	/**
156
	 * heading tetxt
157
	 * @var string
158
	 */
159
	protected $heading = '';
160
161
	/**
162
	 * action what to do next
163
	 * @var string
164
	 */
165
	protected $todo = '';
166
167
	/**
168
	 * data
169
	 * @var array
170
	 */
171
	protected $data = array();
172
173
	/**
174
	 * error handler
175
	 * @var string
176
	 */
177
	protected $error = '';
178
179
	/**
180
	 * database connection
181
	 * @var string
182
	 */
183
	protected $database = NULL;
184
185
	/**
186
	 * debug mode
187
	 * @var boolean
188
	 */
189
	protected $debugMode = false;
190
191
	protected $sunlight;
192
193
	protected function parseTutorEmail($item)
194
	{
195
		$mails = explode(',', $item->email);
196
		$names = explode(',', $item->tutor);
197
198
		$i = 0;
199
		$recipient = [];
200
		foreach ($mails as $mail) {
201
			$mail = trim($mail);
202
			$name = trim($names[$i]);
203
204
			$recipient['email'] = $mail;
205
			$recipient['name'] = ($name) ? $name : '';
206
			$recipients[] = ArrayHash::from($recipient);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$recipients was never initialized. Although not strictly required by PHP, it is generally a good practice to add $recipients = 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...
207
		}
208
209
		return $recipients;
0 ignored issues
show
Bug introduced by
The variable $recipients 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...
210
	}
211
212
	// zaheshovane udaje, aby se nedali jen tak ziskat data z databaze
213
	protected function formKeyHash($id, $meetingId)
214
	{
215
		return ((int)$id . $meetingId) * 116 + 39147;
216
	}
217
218
	/**
219
	 * @return Model
220
	 */
221
	protected function getModel()
222
	{
223
		return $this->model;
224
	}
225
226
	/**
227
	 * @param  Model $model
228
	 * @return $this
229
	 */
230
	protected function setModel($model)
231
	{
232
		$this->model = $model;
233
		return $this;
234
	}
235
236
	/**
237
	 * @return Container
238
	 */
239
	protected function getContainer()
240
	{
241
		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...
242
	}
243
244
	/**
245
	 * @param  Container $container
246
	 * @return $this
247
	 */
248
	protected function setContainer($container)
249
	{
250
		$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...
251
		return $this;
252
	}
253
254
	/**
255
	 * @return Router
256
	 */
257
	protected function getRouter()
258
	{
259
		return $this->router;
260
	}
261
262
	/**
263
	 * @param  Router $router
264
	 * @return $this
265
	 */
266
	protected function setRouter($router)
267
	{
268
		$this->router = $router;
269
		return $this;
270
	}
271
272
	/**
273
	 * @return Latte
274
	 */
275
	protected function getLatte()
276
	{
277
		return $this->latte;
278
	}
279
280
	/**
281
	 * @param  Latte $latte
282
	 * @return $this
283
	 */
284
	protected function setLatte($latte)
285
	{
286
		$this->latte = $latte;
287
		return $this;
288
	}
289
290
	/**
291
	 * @return string
292
	 */
293
	public function getAction($fullyQualified = false)
294
	{
295
		return $this->action;
296
	}
297
298
	/**
299
	 * @param  string $action
300
	 * @return $this
301
	 */
302
	public function setAction($action)
303
	{
304
		$this->action = $action;
305
		return $this;
306
	}
307
308
	/**
309
	 * @return SunlightModel
310
	 */
311
	public function getSunlight()
312
	{
313
		if(empty($this->sunlight)) {
314
			$this->setSunlight($this->getContainer()->getService('sunlight'));
315
		}
316
317
		return $this->sunlight;
318
	}
319
320
	/**
321
	 * @param  SunlightModel $sunlight
322
	 * @return $this
323
	 */
324
	public function setSunlight(SunlightModel $sunlight)
325
	{
326
		$this->sunlight = $sunlight;
327
		return $this;
328
	}
329
330
	/**
331
	 * @return integer
332
	 */
333
	protected function getMeetingId()
334
	{
335
		return $this->meetingId;
336
	}
337
338
	/**
339
	 * @param  integer  $meetingId
340
	 * @return $this
341
	 */
342
	protected function setMeetingId($meetingId)
343
	{
344
		$this->meetingId = $meetingId;
345
		return $this;
346
	}
347
348
	/**
349
	 * @param  string $guid
350
	 * @param  array  $data
351
	 * @return ActiveRow
352
	 */
353
	protected function updateByGuid($guid, array $data)
354
	{
355
		return $this->getModel()->updateBy('guid', $guid, $data);
356
	}
357
358
	public function remember($key, $minutes, \Closure $callback)
359
	{
360
		// If the item exists in the cache we will just return this immediately
361
		// otherwise we will execute the given Closure and cache the result
362
		// of that execution for the given number of minutes in storage.
363
		if (! is_null($data = $this->getCache()->load($key))) {
364
			$items = [];
365
366
			foreach($data as $item) {
367
				$object = new \stdClass();
368
				foreach ($item as $key => $value) {
369
					$object->$key = $value;
370
				}
371
				$items[] = $object;
372
			}
373
374
			return $items;
375
		}
376
377
		$data = $callback();
378
		$serialized = [];
379
		foreach ($data as $item) {
380
			$serialized[] = $item->toArray();
381
		}
382
383
		$this->getCache()->save(
384
			$key,
385
			$serialized,
386
			[
387
				Cache::EXPIRE => $minutes . ' minutes',
388
			]
389
		);
390
391
		return $data;
392
	}
393
394
	protected function getCache()
395
	{
396
		return $this->getContainer()->getService('cache');
397
	}
398
399
	/**
400
	 * @return string
401
	 */
402
	protected function getDebugMode()
403
	{
404
		return $this->debugMode;
405
	}
406
407
	/**
408
	 * @return string
409
	 */
410
	protected function getBacklink()
411
	{
412
		return $this->backlink;
413
	}
414
415
	/**
416
	 * @param  string $backlink
417
	 * @return $this
418
	 */
419
	protected function setBacklink($backlink)
420
	{
421
		$this->backlink = $backlink;
422
423
		return $this;
424
	}
425
426
	/**
427
	 * @return string
428
	 */
429
	protected function getBacklinkUrl()
430
	{
431
		if($this->getBacklink()) {
432
			return $this->link(
433
				$this->getBacklink(),
434
				[
435
					'backlink' => null
436
				]
437
			);
438
		}
439
	}
440
441
    /**
442
     * @param  Nette\Utils\ArrayHash $array
443
     * @return self
444
     */
445
    protected function setBacklinkFromArray(ArrayHash $array): self
446
    {
447
        if(array_key_exists('backlink', $array) && !empty($array['backlink'])) {
448
            $this->setBacklink($array['backlink']);
449
            unset($array['backlink']);
450
        }
451
452
        return $this;
453
    }
454
455
	/**
456
	 * Flashes success message
457
	 *
458
	 * @param  string $message Message
459
	 */
460
	protected function flashSuccess(string $message = '')
461
	{
462
		$this->flashMessage($message, self::FLASH_TYPE_OK);
463
	}
464
465
	/**
466
	 * Flashes failure message
467
	 *
468
	 * @param  string $message Message
469
	 */
470
	protected function flashFailure(string $message = '')
471
	{
472
		$this->flashMessage($message, self::FLASH_TYPE_ERROR);
473
	}
474
475
	/**
476
	 * Flashes error message
477
	 *
478
	 * @param  string $message Message
479
	 */
480
	protected function flashError(string $message = '')
481
	{
482
		$this->flashMessage($message, self::FLASH_TYPE_ERROR);
483
	}
484
485
}
486