Skip to content

Commit fabaead

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent 2485dfd commit fabaead

28 files changed

+98
-98
lines changed

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Let's save the contents of the '`$data`' variable under the '`$key`' key:
4444
$cache->save($key, $data);
4545
```
4646

47-
This way, we can read from the cache: (if there is no such item in the cache, the `NULL` value is returned)
47+
This way, we can read from the cache: (if there is no such item in the cache, the `null` value is returned)
4848

4949
```php
5050
$value = $cache->load($key);
51-
if ($value === NULL) ...
51+
if ($value === null) ...
5252
```
5353

5454
Method `load()` has second parameter `callable` `$fallback`, which is called when there is no such item in the cache. This callback receives the array *$dependencies* by reference, which you can use for setting expiration rules.
@@ -60,10 +60,10 @@ $value = $cache->load($key, function(& $dependencies) {
6060
});
6161
```
6262

63-
We could delete the item from the cache either by saving NULL or by calling `remove()` method:
63+
We could delete the item from the cache either by saving null or by calling `remove()` method:
6464

6565
```php
66-
$cache->save($key, NULL);
66+
$cache->save($key, null);
6767
// or
6868
$cache->remove($key);
6969
```
@@ -107,7 +107,7 @@ if ($block = $cache->start($key)) {
107107
}
108108
```
109109

110-
In case that the output is already present in the cache, the `start()` method prints it and return `NULL`. Otherwise, it starts to buffer the output and
110+
In case that the output is already present in the cache, the `start()` method prints it and return `null`. Otherwise, it starts to buffer the output and
111111
returns the `$block` object using which we finally save the data to the cache.
112112

113113

@@ -126,13 +126,13 @@ $cache->save($key, $data, array(
126126
```
127127

128128
It's obvious from the code itself, that we saved the data for next 20 minutes. After this period, the cache will report that there is no record
129-
under the '`$key`' key (ie, will return `NULL`). In fact, you can use any time value that is a valid value for PHP function strToTime().
129+
under the '`$key`' key (ie, will return `null`). In fact, you can use any time value that is a valid value for PHP function strToTime().
130130
If we want to extend the validity period with each reading, it can be achieved this way:
131131

132132
```php
133133
$cache->save($key, $data, array(
134134
Cache::EXPIRE => '20 minutes',
135-
Cache::SLIDING => TRUE,
135+
Cache::SLIDING => true,
136136
));
137137
```
138138

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CacheMacro implements Latte\IMacro
3131
*/
3232
public function initialize()
3333
{
34-
$this->used = FALSE;
34+
$this->used = false;
3535
}
3636

3737

@@ -56,8 +56,8 @@ public function nodeOpened(Latte\MacroNode $node)
5656
if ($node->modifiers) {
5757
throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
5858
}
59-
$this->used = TRUE;
60-
$node->empty = FALSE;
59+
$this->used = true;
60+
$node->empty = false;
6161
$node->openingCode = Latte\PhpWriter::using($node)
6262
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>',
6363
Nette\Utils\Random::generate()
@@ -94,7 +94,7 @@ public static function initRuntime(Latte\Runtime\Template $template): void
9494
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
9595
* @return Nette\Caching\OutputHelper|\stdClass
9696
*/
97-
public static function createCache(Nette\Caching\IStorage $cacheStorage, string $key, ?array &$parents, array $args = NULL)
97+
public static function createCache(Nette\Caching\IStorage $cacheStorage, string $key, ?array &$parents, array $args = null)
9898
{
9999
if ($args) {
100100
if (array_key_exists('if', $args) && !$args['if']) {
@@ -118,7 +118,7 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, string
118118
* Ends the output cache.
119119
* @param Nette\Caching\OutputHelper[]
120120
*/
121-
public static function endCache(array &$parents, array $args = NULL): void
121+
public static function endCache(array &$parents, array $args = null): void
122122
{
123123
$helper = array_pop($parents);
124124
if ($helper instanceof Nette\Caching\OutputHelper) {
@@ -128,7 +128,7 @@ public static function endCache(array &$parents, array $args = NULL): void
128128
if (isset($args['expire'])) {
129129
$args['expiration'] = $args['expire']; // back compatibility
130130
}
131-
$helper->dependencies[Cache::TAGS] = $args['tags'] ?? NULL;
131+
$helper->dependencies[Cache::TAGS] = $args['tags'] ?? null;
132132
$helper->dependencies[Cache::EXPIRATION] = $args['expiration'] ?? '+ 7 days';
133133
$helper->end();
134134
}

src/Caching/Cache.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Cache
4343
private $namespace;
4444

4545

46-
public function __construct(IStorage $storage, $namespace = NULL)
46+
public function __construct(IStorage $storage, $namespace = null)
4747
{
4848
$this->storage = $storage;
4949
$this->namespace = $namespace . self::NAMESPACE_SEPARATOR;
@@ -84,10 +84,10 @@ public function derive(string $namespace)
8484
* @param mixed
8585
* @return mixed
8686
*/
87-
public function load($key, callable $fallback = NULL)
87+
public function load($key, callable $fallback = null)
8888
{
8989
$data = $this->storage->read($this->generateKey($key));
90-
if ($data === NULL && $fallback) {
90+
if ($data === null && $fallback) {
9191
return $this->save($key, function (&$dependencies) use ($fallback) {
9292
return $fallback(...[&$dependencies]);
9393
});
@@ -99,7 +99,7 @@ public function load($key, callable $fallback = NULL)
9999
/**
100100
* Reads multiple items from the cache.
101101
*/
102-
public function bulkLoad(array $keys, callable $fallback = NULL): array
102+
public function bulkLoad(array $keys, callable $fallback = null): array
103103
{
104104
if (count($keys) === 0) {
105105
return [];
@@ -112,9 +112,9 @@ public function bulkLoad(array $keys, callable $fallback = NULL): array
112112
$storageKeys = array_map([$this, 'generateKey'], $keys);
113113
if (!$this->storage instanceof IBulkReader) {
114114
$result = array_combine($keys, array_map([$this->storage, 'read'], $storageKeys));
115-
if ($fallback !== NULL) {
115+
if ($fallback !== null) {
116116
foreach ($result as $key => $value) {
117-
if ($value === NULL) {
117+
if ($value === null) {
118118
$result[$key] = $this->save($key, function (&$dependencies) use ($key, $fallback) {
119119
return $fallback(...[$key, &$dependencies]);
120120
});
@@ -135,7 +135,7 @@ public function bulkLoad(array $keys, callable $fallback = NULL): array
135135
return $fallback(...[$key, &$dependencies]);
136136
});
137137
} else {
138-
$result[$key] = NULL;
138+
$result[$key] = null;
139139
}
140140
}
141141
return $result;
@@ -158,7 +158,7 @@ public function bulkLoad(array $keys, callable $fallback = NULL): array
158158
* @return mixed value itself
159159
* @throws Nette\InvalidArgumentException
160160
*/
161-
public function save($key, $data, array $dependencies = NULL)
161+
public function save($key, $data, array $dependencies = null)
162162
{
163163
$key = $this->generateKey($key);
164164

@@ -172,7 +172,7 @@ public function save($key, $data, array $dependencies = NULL)
172172
}
173173
}
174174

175-
if ($data === NULL) {
175+
if ($data === null) {
176176
$this->storage->remove($key);
177177
} else {
178178
$dependencies = $this->completeDependencies($dependencies);
@@ -201,7 +201,7 @@ private function completeDependencies(?array $dp): array
201201
// convert FILES into CALLBACKS
202202
if (isset($dp[self::FILES])) {
203203
foreach (array_unique((array) $dp[self::FILES]) as $item) {
204-
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item) ?: NULL]; // @ - stat may fail
204+
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item) ?: null]; // @ - stat may fail
205205
}
206206
unset($dp[self::FILES]);
207207
}
@@ -232,7 +232,7 @@ private function completeDependencies(?array $dp): array
232232
*/
233233
public function remove($key): void
234234
{
235-
$this->save($key, NULL);
235+
$this->save($key, null);
236236
}
237237

238238

@@ -241,9 +241,9 @@ public function remove($key): void
241241
* Conditions are:
242242
* - Cache::PRIORITY => (int) priority
243243
* - Cache::TAGS => (array) tags
244-
* - Cache::ALL => TRUE
244+
* - Cache::ALL => true
245245
*/
246-
public function clean(array $conditions = NULL): void
246+
public function clean(array $conditions = null): void
247247
{
248248
$conditions = (array) $conditions;
249249
if (isset($conditions[self::TAGS])) {
@@ -274,15 +274,15 @@ public function call($function)
274274
* Caches results of function/method calls.
275275
* @param mixed
276276
*/
277-
public function wrap($function, array $dependencies = NULL): \Closure
277+
public function wrap($function, array $dependencies = null): \Closure
278278
{
279279
return function () use ($function, $dependencies) {
280280
$key = [$function, func_get_args()];
281281
if (is_array($function) && is_object($function[0])) {
282282
$key[0][0] = get_class($function[0]);
283283
}
284284
$data = $this->load($key);
285-
if ($data === NULL) {
285+
if ($data === null) {
286286
$data = $this->save($key, Callback::invokeArgs($function, $key[1]), $dependencies);
287287
}
288288
return $data;
@@ -297,11 +297,11 @@ public function wrap($function, array $dependencies = NULL): \Closure
297297
public function start($key): ?OutputHelper
298298
{
299299
$data = $this->load($key);
300-
if ($data === NULL) {
300+
if ($data === null) {
301301
return new OutputHelper($this, $key);
302302
}
303303
echo $data;
304-
return NULL;
304+
return null;
305305
}
306306

307307

@@ -324,10 +324,10 @@ public static function checkCallbacks(array $callbacks): bool
324324
{
325325
foreach ($callbacks as $callback) {
326326
if (!array_shift($callback)(...$callback)) {
327-
return FALSE;
327+
return false;
328328
}
329329
}
330-
return TRUE;
330+
return true;
331331
}
332332

333333

src/Caching/OutputHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public function __construct(Cache $cache, $key)
4040
/**
4141
* Stops and saves the cache.
4242
*/
43-
public function end(array $dependencies = NULL): void
43+
public function end(array $dependencies = null): void
4444
{
45-
if ($this->cache === NULL) {
45+
if ($this->cache === null) {
4646
throw new Nette\InvalidStateException('Output cache has already been saved.');
4747
}
4848
$this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
49-
$this->cache = NULL;
49+
$this->cache = null;
5050
}
5151
}

src/Caching/Storages/FileStorage.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FileStorage implements Nette\Caching\IStorage
5252
public static $gcProbability = 0.001;
5353

5454
/** @deprecated */
55-
public static $useDirectories = TRUE;
55+
public static $useDirectories = true;
5656

5757
/** @var string */
5858
private $dir;
@@ -64,7 +64,7 @@ class FileStorage implements Nette\Caching\IStorage
6464
private $locks;
6565

6666

67-
public function __construct($dir, IJournal $journal = NULL)
67+
public function __construct($dir, IJournal $journal = null)
6868
{
6969
if (!is_dir($dir)) {
7070
throw new Nette\DirectoryNotFoundException("Directory '$dir' not found.");
@@ -90,7 +90,7 @@ public function read(string $key)
9090
return $this->readData($meta); // calls fclose()
9191

9292
} else {
93-
return NULL;
93+
return null;
9494
}
9595
}
9696

@@ -125,11 +125,11 @@ private function verify(array $meta): bool
125125
}
126126
}
127127

128-
return TRUE;
129-
} while (FALSE);
128+
return true;
129+
} while (false);
130130

131131
$this->delete($meta[self::FILE], $meta[self::HANDLE]); // meta[handle] & meta[file] was added by readMetaAndLock()
132-
return FALSE;
132+
return false;
133133
}
134134

135135

@@ -171,7 +171,7 @@ public function write(string $key, $data, array $dp): void
171171
foreach ($dp[Cache::ITEMS] as $item) {
172172
$depFile = $this->getCacheFile($item);
173173
$m = $this->readMetaAndLock($depFile, LOCK_SH);
174-
$meta[self::META_ITEMS][$depFile] = $m[self::META_TIME]; // may be NULL
174+
$meta[self::META_ITEMS][$depFile] = $m[self::META_TIME]; // may be null
175175
unset($m);
176176
}
177177
}
@@ -202,7 +202,7 @@ public function write(string $key, $data, array $dp): void
202202

203203
if (!is_string($data)) {
204204
$data = serialize($data);
205-
$meta[self::META_SERIALIZED] = TRUE;
205+
$meta[self::META_SERIALIZED] = true;
206206
}
207207

208208
$head = serialize($meta) . '?>';
@@ -226,7 +226,7 @@ public function write(string $key, $data, array $dp): void
226226
flock($handle, LOCK_UN);
227227
fclose($handle);
228228
return;
229-
} while (FALSE);
229+
} while (false);
230230

231231
$this->delete($cacheFile, $handle);
232232
}
@@ -304,7 +304,7 @@ protected function readMetaAndLock(string $file, int $lock): ?array
304304
{
305305
$handle = @fopen($file, 'r+b'); // @ - file may not exist
306306
if (!$handle) {
307-
return NULL;
307+
return null;
308308
}
309309

310310
flock($handle, $lock);
@@ -321,7 +321,7 @@ protected function readMetaAndLock(string $file, int $lock): ?array
321321

322322
flock($handle, LOCK_UN);
323323
fclose($handle);
324-
return NULL;
324+
return null;
325325
}
326326

327327

@@ -360,7 +360,7 @@ protected function getCacheFile(string $key): string
360360
* Deletes and closes file.
361361
* @param resource $handle
362362
*/
363-
private static function delete(string $file, $handle = NULL): void
363+
private static function delete(string $file, $handle = null): void
364364
{
365365
if (@unlink($file)) { // @ - file may not already exist
366366
if ($handle) {

src/Caching/Storages/IJournal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function write(string $key, array $dependencies): void;
2323

2424
/**
2525
* Cleans entries from journal.
26-
* @return array|NULL of removed items or NULL when performing a full cleanup
26+
* @return array|null of removed items or null when performing a full cleanup
2727
*/
2828
function clean(array $conditions): ?array;
2929
}

src/Caching/Storages/MemoryStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MemoryStorage implements Nette\Caching\IStorage
2929
*/
3030
public function read(string $key)
3131
{
32-
return $this->data[$key] ?? NULL;
32+
return $this->data[$key] ?? null;
3333
}
3434

3535

0 commit comments

Comments
 (0)