Skip to content

Commit bb87b2a

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent 9d55a13 commit bb87b2a

File tree

8 files changed

+77
-77
lines changed

8 files changed

+77
-77
lines changed

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ Monitoring and lookup of components or paths using `lookup` is **very precisely
7777
Iterating over children
7878
-----------------------
7979

80-
There is a method `getComponents($deep = FALSE, $type = NULL)` for that. First parameter determines if the components should be looked up in depth (recursively). With `TRUE`, it not only iterates all it's children, but also all chilren of it's children, etc. Second parameter servers as an optional filter by class or interface.
80+
There is a method `getComponents($deep = false, $type = null)` for that. First parameter determines if the components should be looked up in depth (recursively). With `true`, it not only iterates all it's children, but also all chilren of it's children, etc. Second parameter servers as an optional filter by class or interface.
8181

8282
For example, this is the way how validation of forms is "internally"((this is done by framework itself, you don't have to call it explicitly)) performed:
8383

8484
```php
85-
$valid = TRUE;
86-
foreach ($form->getComponents(TRUE, Nette\Forms\IControl::class) as $control) {
85+
$valid = true;
86+
foreach ($form->getComponents(true, Nette\Forms\IControl::class) as $control) {
8787
if (!$control->getRules()->validate()) {
88-
$valid = FALSE;
88+
$valid = false;
8989
break;
9090
}
9191
}

src/ComponentModel/Component.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Components are objects implementing IComponent. They has parent component and own name.
1717
*
1818
* @property-read string $name
19-
* @property-read IContainer|NULL $parent
19+
* @property-read IContainer|null $parent
2020
*/
2121
abstract class Component implements IComponent
2222
{
@@ -34,8 +34,8 @@ abstract class Component implements IComponent
3434

3535
public function __construct()
3636
{
37-
list($parent, $name) = func_get_args() + [NULL, NULL];
38-
if ($parent !== NULL) {
37+
list($parent, $name) = func_get_args() + [null, null];
38+
if ($parent !== null) {
3939
$parent->addComponent($this, $name);
4040

4141
} elseif (is_string($name)) {
@@ -46,38 +46,38 @@ public function __construct()
4646

4747
/**
4848
* Lookup hierarchy for component specified by class or interface name.
49-
* @param string|NULL
49+
* @param string|null
5050
* @param bool
51-
* @return IComponent|NULL
51+
* @return IComponent|null
5252
*/
53-
public function lookup($type, $throw = TRUE)
53+
public function lookup($type, $throw = true)
5454
{
5555
if (!isset($this->monitors[$type])) { // not monitored or not processed yet
5656
$obj = $this->parent;
5757
$path = self::NAME_SEPARATOR . $this->name;
5858
$depth = 1;
59-
while ($obj !== NULL) {
59+
while ($obj !== null) {
6060
$parent = $obj->getParent();
61-
if ($type ? $obj instanceof $type : $parent === NULL) {
61+
if ($type ? $obj instanceof $type : $parent === null) {
6262
break;
6363
}
6464
$path = self::NAME_SEPARATOR . $obj->getName() . $path;
6565
$depth++;
6666
$obj = $parent; // IComponent::getParent()
6767
if ($obj === $this) {
68-
$obj = NULL; // prevent cycling
68+
$obj = null; // prevent cycling
6969
}
7070
}
7171

7272
if ($obj) {
73-
$this->monitors[$type] = [$obj, $depth, substr($path, 1), FALSE];
73+
$this->monitors[$type] = [$obj, $depth, substr($path, 1), false];
7474

7575
} else {
76-
$this->monitors[$type] = [NULL, NULL, NULL, FALSE]; // not found
76+
$this->monitors[$type] = [null, null, null, false]; // not found
7777
}
7878
}
7979

80-
if ($throw && $this->monitors[$type][0] === NULL) {
80+
if ($throw && $this->monitors[$type][0] === null) {
8181
throw new Nette\InvalidStateException("Component '$this->name' is not attached to '$type'.");
8282
}
8383

@@ -88,11 +88,11 @@ public function lookup($type, $throw = TRUE)
8888
/**
8989
* Lookup for component specified by class or interface name. Returns backtrace path.
9090
* A path is the concatenation of component names separated by self::NAME_SEPARATOR.
91-
* @param string|NULL
91+
* @param string|null
9292
* @param bool
93-
* @return string|NULL
93+
* @return string|null
9494
*/
95-
public function lookupPath($type = NULL, $throw = TRUE)
95+
public function lookupPath($type = null, $throw = true)
9696
{
9797
$this->lookup($type, $throw);
9898
return $this->monitors[$type][2];
@@ -107,10 +107,10 @@ public function lookupPath($type = NULL, $throw = TRUE)
107107
public function monitor($type)
108108
{
109109
if (empty($this->monitors[$type][3])) {
110-
if ($obj = $this->lookup($type, FALSE)) {
110+
if ($obj = $this->lookup($type, false)) {
111111
$this->attached($obj);
112112
}
113-
$this->monitors[$type][3] = TRUE; // mark as monitored
113+
$this->monitors[$type][3] = true; // mark as monitored
114114
}
115115
}
116116

@@ -152,7 +152,7 @@ protected function detached($obj)
152152

153153

154154
/**
155-
* @return string|NULL
155+
* @return string|null
156156
*/
157157
public function getName()
158158
{
@@ -162,7 +162,7 @@ public function getName()
162162

163163
/**
164164
* Returns the container if any.
165-
* @return IContainer|NULL
165+
* @return IContainer|null
166166
*/
167167
public function getParent()
168168
{
@@ -179,30 +179,30 @@ public function getParent()
179179
* @throws Nette\InvalidStateException
180180
* @internal
181181
*/
182-
public function setParent(IContainer $parent = NULL, $name = NULL)
182+
public function setParent(IContainer $parent = null, $name = null)
183183
{
184-
if ($parent === NULL && $this->parent === NULL && $name !== NULL) {
184+
if ($parent === null && $this->parent === null && $name !== null) {
185185
$this->name = $name; // just rename
186186
return $this;
187187

188-
} elseif ($parent === $this->parent && $name === NULL) {
188+
} elseif ($parent === $this->parent && $name === null) {
189189
return $this; // nothing to do
190190
}
191191

192192
// A component cannot be given a parent if it already has a parent.
193-
if ($this->parent !== NULL && $parent !== NULL) {
193+
if ($this->parent !== null && $parent !== null) {
194194
throw new Nette\InvalidStateException("Component '$this->name' already has a parent.");
195195
}
196196

197197
// remove from parent?
198-
if ($parent === NULL) {
198+
if ($parent === null) {
199199
$this->refreshMonitors(0);
200-
$this->parent = NULL;
200+
$this->parent = null;
201201

202202
} else { // add to parent
203203
$this->validateParent($parent);
204204
$this->parent = $parent;
205-
if ($name !== NULL) {
205+
if ($name !== null) {
206206
$this->name = $name;
207207
}
208208

@@ -227,11 +227,11 @@ protected function validateParent(IContainer $parent)
227227
/**
228228
* Refreshes monitors.
229229
* @param int
230-
* @param array|NULL (array = attaching, NULL = detaching)
230+
* @param array|null (array = attaching, null = detaching)
231231
* @param array
232232
* @return void
233233
*/
234-
private function refreshMonitors($depth, &$missing = NULL, &$listeners = [])
234+
private function refreshMonitors($depth, &$missing = null, &$listeners = [])
235235
{
236236
if ($this instanceof IContainer) {
237237
foreach ($this->getComponents() as $component) {
@@ -241,11 +241,11 @@ private function refreshMonitors($depth, &$missing = NULL, &$listeners = [])
241241
}
242242
}
243243

244-
if ($missing === NULL) { // detaching
244+
if ($missing === null) { // detaching
245245
foreach ($this->monitors as $type => $rec) {
246246
if (isset($rec[1]) && $rec[1] > $depth) {
247247
if ($rec[3]) { // monitored
248-
$this->monitors[$type] = [NULL, NULL, NULL, TRUE];
248+
$this->monitors[$type] = [null, null, null, true];
249249
$listeners[] = [$this, $rec[0]];
250250
} else { // not monitored, just randomly cached
251251
unset($this->monitors[$type]);
@@ -262,25 +262,25 @@ private function refreshMonitors($depth, &$missing = NULL, &$listeners = [])
262262
unset($this->monitors[$type]);
263263

264264
} elseif (isset($missing[$type])) { // known from previous lookup
265-
$this->monitors[$type] = [NULL, NULL, NULL, TRUE];
265+
$this->monitors[$type] = [null, null, null, true];
266266

267267
} else {
268-
$this->monitors[$type] = NULL; // forces re-lookup
269-
if ($obj = $this->lookup($type, FALSE)) {
268+
$this->monitors[$type] = null; // forces re-lookup
269+
if ($obj = $this->lookup($type, false)) {
270270
$listeners[] = [$this, $obj];
271271
} else {
272-
$missing[$type] = TRUE;
272+
$missing[$type] = true;
273273
}
274-
$this->monitors[$type][3] = TRUE; // mark as monitored
274+
$this->monitors[$type][3] = true; // mark as monitored
275275
}
276276
}
277277
}
278278

279279
if ($depth === 0) { // call listeners
280-
$method = $missing === NULL ? 'detached' : 'attached';
280+
$method = $missing === null ? 'detached' : 'attached';
281281
$prev = [];
282282
foreach ($listeners as $item) {
283-
if (!in_array($item, $prev, TRUE)) {
283+
if (!in_array($item, $prev, true)) {
284284
$item[0]->$method($item[1]);
285285
$prev[] = $item;
286286
}
@@ -297,17 +297,17 @@ private function refreshMonitors($depth, &$missing = NULL, &$listeners = [])
297297
*/
298298
public function __clone()
299299
{
300-
if ($this->parent === NULL) {
300+
if ($this->parent === null) {
301301
return;
302302

303303
} elseif ($this->parent instanceof Container) {
304304
$this->parent = $this->parent->_isCloning();
305-
if ($this->parent === NULL) { // not cloning
305+
if ($this->parent === null) { // not cloning
306306
$this->refreshMonitors(0);
307307
}
308308

309309
} else {
310-
$this->parent = NULL;
310+
$this->parent = null;
311311
$this->refreshMonitors(0);
312312
}
313313
}

src/ComponentModel/Container.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Container extends Component implements IContainer
2020
/** @var IComponent[] */
2121
private $components = [];
2222

23-
/** @var IComponent|NULL */
23+
/** @var IComponent|null */
2424
private $cloning;
2525

2626

@@ -35,9 +35,9 @@ class Container extends Component implements IContainer
3535
* @return static
3636
* @throws Nette\InvalidStateException
3737
*/
38-
public function addComponent(IComponent $component, $name, $insertBefore = NULL)
38+
public function addComponent(IComponent $component, $name, $insertBefore = null)
3939
{
40-
if ($name === NULL) {
40+
if ($name === null) {
4141
$name = $component->getName();
4242
}
4343

@@ -62,7 +62,7 @@ public function addComponent(IComponent $component, $name, $insertBefore = NULL)
6262
throw new Nette\InvalidStateException("Circular reference detected while adding component '$name'.");
6363
}
6464
$obj = $obj->getParent();
65-
} while ($obj !== NULL);
65+
} while ($obj !== null);
6666

6767
// user checking
6868
$this->validateChildComponent($component);
@@ -102,17 +102,17 @@ public function removeComponent(IComponent $component)
102102
}
103103

104104
unset($this->components[$name]);
105-
$component->setParent(NULL);
105+
$component->setParent(null);
106106
}
107107

108108

109109
/**
110110
* Returns component specified by name or path.
111111
* @param string|int
112112
* @param bool throw exception if component doesn't exist?
113-
* @return IComponent|NULL
113+
* @return IComponent|null
114114
*/
115-
public function getComponent($name, $throw = TRUE)
115+
public function getComponent($name, $throw = true)
116116
{
117117
if (isset($this->components[$name])) {
118118
return $this->components[$name];
@@ -126,7 +126,7 @@ public function getComponent($name, $throw = TRUE)
126126

127127
} else {
128128
$a = strpos($name, self::NAME_SEPARATOR);
129-
if ($a !== FALSE) {
129+
if ($a !== false) {
130130
$ext = (string) substr($name, $a + 1);
131131
$name = substr($name, 0, $a);
132132
}
@@ -175,7 +175,7 @@ public function getComponent($name, $throw = TRUE)
175175
/**
176176
* Component factory. Delegates the creation of components to a createComponent<Name> method.
177177
* @param string
178-
* @return IComponent|NULL
178+
* @return IComponent|null
179179
*/
180180
protected function createComponent($name)
181181
{
@@ -198,7 +198,7 @@ protected function createComponent($name)
198198
* @param string
199199
* @return \Iterator
200200
*/
201-
public function getComponents($deep = FALSE, $filterType = NULL)
201+
public function getComponents($deep = false, $filterType = null)
202202
{
203203
$iterator = new RecursiveComponentIterator($this->components);
204204
if ($deep) {
@@ -238,15 +238,15 @@ public function __clone()
238238
foreach ($this->components as $name => $component) {
239239
$this->components[$name] = clone $component;
240240
}
241-
$oldMyself->cloning = NULL;
241+
$oldMyself->cloning = null;
242242
}
243243
parent::__clone();
244244
}
245245

246246

247247
/**
248248
* Is container cloning now?
249-
* @return IComponent|NULL
249+
* @return IComponent|null
250250
* @internal
251251
*/
252252
public function _isCloning()

src/ComponentModel/IComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ interface IComponent
1717
const NAME_SEPARATOR = '-';
1818

1919
/**
20-
* @return string|NULL
20+
* @return string|null
2121
*/
2222
function getName();
2323

2424
/**
2525
* Returns the container if any.
26-
* @return IContainer|NULL
26+
* @return IContainer|null
2727
*/
2828
function getParent();
2929

@@ -33,5 +33,5 @@ function getParent();
3333
* @param string
3434
* @return static
3535
*/
36-
function setParent(IContainer $parent = NULL, $name = NULL);
36+
function setParent(IContainer $parent = null, $name = null);
3737
}

src/ComponentModel/IContainer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function removeComponent(IComponent $component);
3232
/**
3333
* Returns single component.
3434
* @param string|int
35-
* @return IComponent|NULL
35+
* @return IComponent|null
3636
*/
3737
function getComponent($name);
3838

@@ -42,5 +42,5 @@ function getComponent($name);
4242
* @param string
4343
* @return \Iterator
4444
*/
45-
function getComponents($deep = FALSE, $filterType = NULL);
45+
function getComponents($deep = false, $filterType = null);
4646
}

0 commit comments

Comments
 (0)