Skip to content

Commit 562d411

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent 962e0c3 commit 562d411

31 files changed

+108
-108
lines changed

readme.md

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

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

4141
```php
4242
$value = $cache->load($key);
43-
if ($value === NULL) ...
43+
if ($value === null) ...
4444
```
4545

4646
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.
@@ -52,10 +52,10 @@ $value = $cache->load($key, function(& $dependencies) {
5252
});
5353
```
5454

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

5757
```php
58-
$cache->save($key, NULL);
58+
$cache->save($key, null);
5959
// or
6060
$cache->remove($key);
6161
```
@@ -99,7 +99,7 @@ if ($block = $cache->start($key)) {
9999
}
100100
```
101101

102-
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
102+
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
103103
returns the `$block` object using which we finally save the data to the cache.
104104

105105

@@ -118,13 +118,13 @@ $cache->save($key, $data, array(
118118
```
119119

120120
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
121-
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().
121+
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().
122122
If we want to extend the validity period with each reading, it can be achieved this way:
123123

124124
```php
125125
$cache->save($key, $data, array(
126126
Cache::EXPIRE => '20 minutes',
127-
Cache::SLIDING => TRUE,
127+
Cache::SLIDING => true,
128128
));
129129
```
130130

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function loadConfiguration()
4747
public function afterCompile(Nette\PhpGenerator\ClassType $class)
4848
{
4949
if (!$this->checkTempDir($this->tempDir . '/cache')) {
50-
$class->getMethod('initialize')->addBody('Nette\Caching\Storages\FileStorage::$useDirectories = FALSE;');
50+
$class->getMethod('initialize')->addBody('Nette\Caching\Storages\FileStorage::$useDirectories = false;');
5151
}
5252
}
5353

@@ -57,13 +57,13 @@ private function checkTempDir($dir)
5757
@mkdir($dir); // @ - directory may exists
5858

5959
// checks whether directory is writable
60-
$uniq = uniqid('_', TRUE);
60+
$uniq = uniqid('_', true);
6161
if (!@mkdir("$dir/$uniq")) { // @ - is escalated to exception
6262
throw new Nette\InvalidStateException("Unable to write to directory '$dir'. Make this directory writable.");
6363
}
6464

6565
// checks whether subdirectory is writable
66-
$isWritable = @file_put_contents("$dir/$uniq/_", '') !== FALSE; // @ - error is expected
66+
$isWritable = @file_put_contents("$dir/$uniq/_", '') !== false; // @ - error is expected
6767
if ($isWritable) {
6868
unlink("$dir/$uniq/_");
6969
}

src/Bridges/CacheLatte/CacheMacro.php

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

3535

@@ -54,8 +54,8 @@ public function nodeOpened(Latte\MacroNode $node)
5454
if ($node->modifiers) {
5555
throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
5656
}
57-
$this->used = TRUE;
58-
$node->empty = FALSE;
57+
$this->used = true;
58+
$node->empty = false;
5959
$node->openingCode = Latte\PhpWriter::using($node)
6060
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>',
6161
Nette\Utils\Random::generate()
@@ -99,7 +99,7 @@ public static function initRuntime(Latte\Runtime\Template $template)
9999
* @param array
100100
* @return Nette\Caching\OutputHelper|\stdClass
101101
*/
102-
public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &$parents, array $args = NULL)
102+
public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &$parents, array $args = null)
103103
{
104104
if ($args) {
105105
if (array_key_exists('if', $args) && !$args['if']) {
@@ -124,7 +124,7 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &
124124
* @param Nette\Caching\OutputHelper[]
125125
* @return void
126126
*/
127-
public static function endCache(&$parents, array $args = NULL)
127+
public static function endCache(&$parents, array $args = null)
128128
{
129129
$helper = array_pop($parents);
130130
if ($helper instanceof Nette\Caching\OutputHelper) {
@@ -134,7 +134,7 @@ public static function endCache(&$parents, array $args = NULL)
134134
if (isset($args['expire'])) {
135135
$args['expiration'] = $args['expire']; // back compatibility
136136
}
137-
$helper->dependencies[Cache::TAGS] = isset($args['tags']) ? $args['tags'] : NULL;
137+
$helper->dependencies[Cache::TAGS] = isset($args['tags']) ? $args['tags'] : null;
138138
$helper->dependencies[Cache::EXPIRATION] = isset($args['expiration']) ? $args['expiration'] : '+ 7 days';
139139
$helper->end();
140140
}

src/Caching/Cache.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Cache
4040
private $namespace;
4141

4242

43-
public function __construct(IStorage $storage, $namespace = NULL)
43+
public function __construct(IStorage $storage, $namespace = null)
4444
{
4545
$this->storage = $storage;
4646
$this->namespace = $namespace . self::NAMESPACE_SEPARATOR;
@@ -85,10 +85,10 @@ public function derive($namespace)
8585
* @param callable
8686
* @return mixed
8787
*/
88-
public function load($key, $fallback = NULL)
88+
public function load($key, $fallback = null)
8989
{
9090
$data = $this->storage->read($this->generateKey($key));
91-
if ($data === NULL && $fallback) {
91+
if ($data === null && $fallback) {
9292
return $this->save($key, function (&$dependencies) use ($fallback) {
9393
return call_user_func_array($fallback, [&$dependencies]);
9494
});
@@ -103,7 +103,7 @@ public function load($key, $fallback = NULL)
103103
* @param callable
104104
* @return array
105105
*/
106-
public function bulkLoad(array $keys, $fallback = NULL)
106+
public function bulkLoad(array $keys, $fallback = null)
107107
{
108108
if (count($keys) === 0) {
109109
return [];
@@ -116,9 +116,9 @@ public function bulkLoad(array $keys, $fallback = NULL)
116116
$storageKeys = array_map([$this, 'generateKey'], $keys);
117117
if (!$this->storage instanceof IBulkReader) {
118118
$result = array_combine($keys, array_map([$this->storage, 'read'], $storageKeys));
119-
if ($fallback !== NULL) {
119+
if ($fallback !== null) {
120120
foreach ($result as $key => $value) {
121-
if ($value === NULL) {
121+
if ($value === null) {
122122
$result[$key] = $this->save($key, function (&$dependencies) use ($key, $fallback) {
123123
return call_user_func_array($fallback, [$key, &$dependencies]);
124124
});
@@ -139,7 +139,7 @@ public function bulkLoad(array $keys, $fallback = NULL)
139139
return call_user_func_array($fallback, [$key, &$dependencies]);
140140
});
141141
} else {
142-
$result[$key] = NULL;
142+
$result[$key] = null;
143143
}
144144
}
145145
return $result;
@@ -162,7 +162,7 @@ public function bulkLoad(array $keys, $fallback = NULL)
162162
* @return mixed value itself
163163
* @throws Nette\InvalidArgumentException
164164
*/
165-
public function save($key, $data, array $dependencies = NULL)
165+
public function save($key, $data, array $dependencies = null)
166166
{
167167
$key = $this->generateKey($key);
168168

@@ -182,7 +182,7 @@ public function save($key, $data, array $dependencies = NULL)
182182
}
183183
}
184184

185-
if ($data === NULL) {
185+
if ($data === null) {
186186
$this->storage->remove($key);
187187
} else {
188188
$dependencies = $this->completeDependencies($dependencies);
@@ -211,7 +211,7 @@ private function completeDependencies($dp)
211211
// convert FILES into CALLBACKS
212212
if (isset($dp[self::FILES])) {
213213
foreach (array_unique((array) $dp[self::FILES]) as $item) {
214-
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item) ?: NULL]; // @ - stat may fail
214+
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item) ?: null]; // @ - stat may fail
215215
}
216216
unset($dp[self::FILES]);
217217
}
@@ -243,7 +243,7 @@ private function completeDependencies($dp)
243243
*/
244244
public function remove($key)
245245
{
246-
$this->save($key, NULL);
246+
$this->save($key, null);
247247
}
248248

249249

@@ -252,10 +252,10 @@ public function remove($key)
252252
* Conditions are:
253253
* - Cache::PRIORITY => (int) priority
254254
* - Cache::TAGS => (array) tags
255-
* - Cache::ALL => TRUE
255+
* - Cache::ALL => true
256256
* @return void
257257
*/
258-
public function clean(array $conditions = NULL)
258+
public function clean(array $conditions = null)
259259
{
260260
$conditions = (array) $conditions;
261261
if (isset($conditions[self::TAGS])) {
@@ -287,15 +287,15 @@ public function call($function)
287287
* @param mixed
288288
* @return \Closure
289289
*/
290-
public function wrap($function, array $dependencies = NULL)
290+
public function wrap($function, array $dependencies = null)
291291
{
292292
return function () use ($function, $dependencies) {
293293
$key = [$function, func_get_args()];
294294
if (is_array($function) && is_object($function[0])) {
295295
$key[0][0] = get_class($function[0]);
296296
}
297297
$data = $this->load($key);
298-
if ($data === NULL) {
298+
if ($data === null) {
299299
$data = $this->save($key, Callback::invokeArgs($function, $key[1]), $dependencies);
300300
}
301301
return $data;
@@ -306,12 +306,12 @@ public function wrap($function, array $dependencies = NULL)
306306
/**
307307
* Starts the output cache.
308308
* @param mixed
309-
* @return OutputHelper|NULL
309+
* @return OutputHelper|null
310310
*/
311311
public function start($key)
312312
{
313313
$data = $this->load($key);
314-
if ($data === NULL) {
314+
if ($data === null) {
315315
return new OutputHelper($this, $key);
316316
}
317317
echo $data;
@@ -341,10 +341,10 @@ public static function checkCallbacks($callbacks)
341341
{
342342
foreach ($callbacks as $callback) {
343343
if (!call_user_func_array(array_shift($callback), $callback)) {
344-
return FALSE;
344+
return false;
345345
}
346346
}
347-
return TRUE;
347+
return true;
348348
}
349349

350350

@@ -363,7 +363,7 @@ private static function checkConst($const, $value)
363363
/**
364364
* Checks FILES dependency.
365365
* @param string
366-
* @param int|NULL
366+
* @param int|null
367367
* @return bool
368368
*/
369369
private static function checkFile($file, $time)

src/Caching/OutputHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function __construct(Cache $cache, $key)
3939
* Stops and saves the cache.
4040
* @return void
4141
*/
42-
public function end(array $dependencies = NULL)
42+
public function end(array $dependencies = null)
4343
{
44-
if ($this->cache === NULL) {
44+
if ($this->cache === null) {
4545
throw new Nette\InvalidStateException('Output cache has already been saved.');
4646
}
4747
$this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
48-
$this->cache = NULL;
48+
$this->cache = null;
4949
}
5050
}

src/Caching/Storages/FileStorage.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class FileStorage implements Nette\Caching\IStorage
4848
public static $gcProbability = 0.001;
4949

5050
/** @var bool */
51-
public static $useDirectories = TRUE;
51+
public static $useDirectories = true;
5252

5353
/** @var string */
5454
private $dir;
@@ -63,7 +63,7 @@ class FileStorage implements Nette\Caching\IStorage
6363
private $locks;
6464

6565

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

9393
} else {
94-
return NULL;
94+
return null;
9595
}
9696
}
9797

@@ -128,11 +128,11 @@ private function verify($meta)
128128
}
129129
}
130130

131-
return TRUE;
132-
} while (FALSE);
131+
return true;
132+
} while (false);
133133

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

138138

@@ -179,7 +179,7 @@ public function write($key, $data, array $dp)
179179
foreach ((array) $dp[Cache::ITEMS] as $item) {
180180
$depFile = $this->getCacheFile($item);
181181
$m = $this->readMetaAndLock($depFile, LOCK_SH);
182-
$meta[self::META_ITEMS][$depFile] = $m[self::META_TIME]; // may be NULL
182+
$meta[self::META_ITEMS][$depFile] = $m[self::META_TIME]; // may be null
183183
unset($m);
184184
}
185185
}
@@ -210,7 +210,7 @@ public function write($key, $data, array $dp)
210210

211211
if (!is_string($data)) {
212212
$data = serialize($data);
213-
$meta[self::META_SERIALIZED] = TRUE;
213+
$meta[self::META_SERIALIZED] = true;
214214
}
215215

216216
$head = serialize($meta) . '?>';
@@ -234,7 +234,7 @@ public function write($key, $data, array $dp)
234234
flock($handle, LOCK_UN);
235235
fclose($handle);
236236
return;
237-
} while (FALSE);
237+
} while (false);
238238

239239
$this->delete($cacheFile, $handle);
240240
}
@@ -311,13 +311,13 @@ public function clean(array $conditions)
311311
* Reads cache data from disk.
312312
* @param string file path
313313
* @param int lock mode
314-
* @return array|NULL
314+
* @return array|null
315315
*/
316316
protected function readMetaAndLock($file, $lock)
317317
{
318318
$handle = @fopen($file, 'r+b'); // @ - file may not exist
319319
if (!$handle) {
320-
return NULL;
320+
return null;
321321
}
322322

323323
flock($handle, $lock);
@@ -334,7 +334,7 @@ protected function readMetaAndLock($file, $lock)
334334

335335
flock($handle, LOCK_UN);
336336
fclose($handle);
337-
return NULL;
337+
return null;
338338
}
339339

340340

@@ -378,7 +378,7 @@ protected function getCacheFile($key)
378378
* @param resource
379379
* @return void
380380
*/
381-
private static function delete($file, $handle = NULL)
381+
private static function delete($file, $handle = null)
382382
{
383383
if (@unlink($file)) { // @ - file may not already exist
384384
if ($handle) {

0 commit comments

Comments
 (0)