Skip to content

Commit b1c0643

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent 4b76760 commit b1c0643

21 files changed

+141
-141
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Anonymous class
185185
---------------
186186

187187
```php
188-
$class = new Nette\PhpGenerator\ClassType(NULL);
188+
$class = new Nette\PhpGenerator\ClassType(null);
189189
$class->addMethod('__construct')
190190
->addParameter('foo');
191191

@@ -336,6 +336,6 @@ $class = Nette\PhpGenerator\ClassType::from(PDO::class);
336336
$function = Nette\PhpGenerator\GlobalFunction::from('trim');
337337

338338
$closure = Nette\PhpGenerator\Closure::from(
339-
function (stdClass $a, $b = NULL) {}
339+
function (stdClass $a, $b = null) {}
340340
);
341341
```

src/PhpGenerator/ClassType.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class ClassType
2626
const TYPE_INTERFACE = 'interface';
2727
const TYPE_TRAIT = 'trait';
2828

29-
/** @var PhpNamespace|NULL */
29+
/** @var PhpNamespace|null */
3030
private $namespace;
3131

32-
/** @var string|NULL */
32+
/** @var string|null */
3333
private $name;
3434

3535
/** @var string class|interface|trait */
3636
private $type = 'class';
3737

3838
/** @var bool */
39-
private $final = FALSE;
39+
private $final = false;
4040

4141
/** @var bool */
42-
private $abstract = FALSE;
42+
private $abstract = false;
4343

4444
/** @var string|string[] */
4545
private $extends = [];
@@ -73,9 +73,9 @@ public static function from($class)
7373

7474

7575
/**
76-
* @param string|NULL
76+
* @param string|null
7777
*/
78-
public function __construct($name = NULL, PhpNamespace $namespace = NULL)
78+
public function __construct($name = null, PhpNamespace $namespace = null)
7979
{
8080
$this->setName($name);
8181
$this->namespace = $namespace;
@@ -104,7 +104,7 @@ public function __toString()
104104
foreach ($this->properties as $property) {
105105
$properties[] = Helpers::formatDocComment($property->getComment())
106106
. ($property->getVisibility() ?: 'public') . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName()
107-
. ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value))
107+
. ($property->value === null ? '' : ' = ' . Helpers::dump($property->value))
108108
. ';';
109109
}
110110

@@ -131,7 +131,7 @@ public function __toString()
131131

132132

133133
/**
134-
* @return PhpNamespace|NULL
134+
* @return PhpNamespace|null
135135
*/
136136
public function getNamespace()
137137
{
@@ -140,12 +140,12 @@ public function getNamespace()
140140

141141

142142
/**
143-
* @param string|NULL
143+
* @param string|null
144144
* @return static
145145
*/
146146
public function setName($name)
147147
{
148-
if ($name !== NULL && !Helpers::isIdentifier($name)) {
148+
if ($name !== null && !Helpers::isIdentifier($name)) {
149149
throw new Nette\InvalidArgumentException("Value '$name' is not valid class name.");
150150
}
151151
$this->name = $name;
@@ -154,7 +154,7 @@ public function setName($name)
154154

155155

156156
/**
157-
* @return string|NULL
157+
* @return string|null
158158
*/
159159
public function getName()
160160
{
@@ -168,7 +168,7 @@ public function getName()
168168
*/
169169
public function setType($type)
170170
{
171-
if (!in_array($type, ['class', 'interface', 'trait'], TRUE)) {
171+
if (!in_array($type, ['class', 'interface', 'trait'], true)) {
172172
throw new Nette\InvalidArgumentException('Argument must be class|interface|trait.');
173173
}
174174
$this->type = $type;
@@ -189,7 +189,7 @@ public function getType()
189189
* @param bool
190190
* @return static
191191
*/
192-
public function setFinal($state = TRUE)
192+
public function setFinal($state = true)
193193
{
194194
$this->final = (bool) $state;
195195
return $this;
@@ -209,7 +209,7 @@ public function isFinal()
209209
* @param bool
210210
* @return static
211211
*/
212-
public function setAbstract($state = TRUE)
212+
public function setAbstract($state = true)
213213
{
214214
$this->abstract = (bool) $state;
215215
return $this;
@@ -439,7 +439,7 @@ public function getProperty($name)
439439
* @param mixed
440440
* @return Property
441441
*/
442-
public function addProperty($name, $value = NULL)
442+
public function addProperty($name, $value = null)
443443
{
444444
return $this->properties[$name] = (new Property($name))->setValue($value);
445445
}
@@ -491,7 +491,7 @@ public function addMethod($name)
491491
{
492492
$method = (new Method($name))->setNamespace($this->namespace);
493493
if ($this->type === 'interface') {
494-
$method->setBody(FALSE);
494+
$method->setBody(false);
495495
} else {
496496
$method->setVisibility('public');
497497
}
@@ -502,7 +502,7 @@ public function addMethod($name)
502502
private function validate(array $names)
503503
{
504504
foreach ($names as $name) {
505-
if (!Helpers::isNamespaceIdentifier($name, TRUE)) {
505+
if (!Helpers::isNamespaceIdentifier($name, true)) {
506506
throw new Nette\InvalidArgumentException("Value '$name' is not valid class name.");
507507
}
508508
}

src/PhpGenerator/Factory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function fromMethodReflection(\ReflectionMethod $from)
6262
$method->setParameters(array_map([$this, 'fromParameterReflection'], $from->getParameters()));
6363
$method->setStatic($from->isStatic());
6464
$isInterface = $from->getDeclaringClass()->isInterface();
65-
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? NULL : 'public')));
65+
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? null : 'public')));
6666
$method->setFinal($from->isFinal());
6767
$method->setAbstract($from->isAbstract() && !$isInterface);
68-
$method->setBody($from->isAbstract() ? FALSE : '');
68+
$method->setBody($from->isAbstract() ? false : '');
6969
$method->setReturnReference($from->returnsReference());
7070
$method->setVariadic($from->isVariadic());
7171
$method->setComment(Helpers::unformatDocComment($from->getDocComment()));
@@ -105,13 +105,13 @@ public function fromParameterReflection(\ReflectionParameter $from)
105105
$param = new Parameter($from->getName());
106106
$param->setReference($from->isPassedByReference());
107107
if (PHP_VERSION_ID >= 70000) {
108-
$param->setTypeHint($from->hasType() ? (string) $from->getType() : NULL);
108+
$param->setTypeHint($from->hasType() ? (string) $from->getType() : null);
109109
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
110110
} elseif ($from->isArray() || $from->isCallable()) {
111111
$param->setTypeHint($from->isArray() ? 'array' : 'callable');
112112
} else {
113113
try {
114-
$param->setTypeHint($from->getClass() ? $from->getClass()->getName() : NULL);
114+
$param->setTypeHint($from->getClass() ? $from->getClass()->getName() : null);
115115
} catch (\ReflectionException $e) {
116116
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
117117
$param->setTypeHint($m[1]);
@@ -121,11 +121,11 @@ public function fromParameterReflection(\ReflectionParameter $from)
121121
}
122122
}
123123
if ($from->isDefaultValueAvailable()) {
124-
$param->setOptional(TRUE);
124+
$param->setOptional(true);
125125
$param->setDefaultValue($from->isDefaultValueConstant()
126126
? new PhpLiteral($from->getDefaultValueConstantName())
127127
: $from->getDefaultValue());
128-
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== NULL);
128+
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== null);
129129
}
130130
return $param;
131131
}
@@ -138,7 +138,7 @@ public function fromPropertyReflection(\ReflectionProperty $from)
138138
{
139139
$prop = new Property($from->getName());
140140
$defaults = $from->getDeclaringClass()->getDefaultProperties();
141-
$prop->setValue(isset($defaults[$prop->getName()]) ? $defaults[$prop->getName()] : NULL);
141+
$prop->setValue(isset($defaults[$prop->getName()]) ? $defaults[$prop->getName()] : null);
142142
$prop->setStatic($from->isStatic());
143143
$prop->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public'));
144144
$prop->setComment(Helpers::unformatDocComment($from->getDocComment()));

src/PhpGenerator/Helpers.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ private static function _dump(&$var, $level = 0)
3939

4040
} elseif (is_float($var)) {
4141
if (is_finite($var)) {
42-
$var = var_export($var, TRUE);
43-
return strpos($var, '.') === FALSE ? $var . '.0' : $var; // workaround for PHP < 7.0.2
42+
$var = var_export($var, true);
43+
return strpos($var, '.') === false ? $var . '.0' : $var; // workaround for PHP < 7.0.2
4444
}
45-
return str_replace('.0', '', var_export($var, TRUE)); // workaround for PHP 7.0.2
45+
return str_replace('.0', '', var_export($var, true)); // workaround for PHP 7.0.2
4646

4747
} elseif (is_bool($var)) {
4848
return $var ? 'TRUE' : 'FALSE';
4949

5050
} elseif (is_string($var) && (preg_match('#[^\x09\x20-\x7E\xA0-\x{10FFFF}]#u', $var) || preg_last_error())) {
5151
static $table;
52-
if ($table === NULL) {
52+
if ($table === null) {
5353
foreach (array_merge(range("\x00", "\x1F"), range("\x7F", "\xFF")) as $ch) {
5454
$table[$ch] = '\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT);
5555
}
@@ -69,8 +69,8 @@ private static function _dump(&$var, $level = 0)
6969
$space = str_repeat("\t", $level);
7070

7171
static $marker;
72-
if ($marker === NULL) {
73-
$marker = uniqid("\x00", TRUE);
72+
if ($marker === null) {
73+
$marker = uniqid("\x00", true);
7474
}
7575
if (empty($var)) {
7676
$out = '';
@@ -81,7 +81,7 @@ private static function _dump(&$var, $level = 0)
8181
} else {
8282
$out = '';
8383
$outAlt = "\n$space";
84-
$var[$marker] = TRUE;
84+
$var[$marker] = true;
8585
$counter = 0;
8686
foreach ($var as $k => &$v) {
8787
if ($k !== $marker) {
@@ -93,7 +93,7 @@ private static function _dump(&$var, $level = 0)
9393
}
9494
unset($var[$marker]);
9595
}
96-
return '[' . (strpos($out, "\n") === FALSE && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
96+
return '[' . (strpos($out, "\n") === false && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
9797

9898
} elseif ($var instanceof \Serializable) {
9999
$var = serialize($var);
@@ -107,23 +107,23 @@ private static function _dump(&$var, $level = 0)
107107
if (PHP_VERSION_ID >= 70000 && (new \ReflectionObject($var))->isAnonymous()) {
108108
throw new Nette\InvalidArgumentException('Cannot dump anonymous class.');
109109

110-
} elseif (in_array($class, ['DateTime', 'DateTimeImmutable'], TRUE)) {
110+
} elseif (in_array($class, ['DateTime', 'DateTimeImmutable'], true)) {
111111
return self::formatArgs("new $class(?, new DateTimeZone(?))", [$var->format('Y-m-d H:i:s.u'), $var->getTimeZone()->getName()]);
112112
}
113113

114114
$arr = (array) $var;
115115
$space = str_repeat("\t", $level);
116116

117117
static $list = [];
118-
if ($level > self::MAX_DEPTH || in_array($var, $list, TRUE)) {
118+
if ($level > self::MAX_DEPTH || in_array($var, $list, true)) {
119119
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
120120

121121
} else {
122122
$out = "\n";
123123
$list[] = $var;
124124
if (method_exists($var, '__sleep')) {
125125
foreach ($var->__sleep() as $v) {
126-
$props[$v] = $props["\x00*\x00$v"] = $props["\x00$class\x00$v"] = TRUE;
126+
$props[$v] = $props["\x00*\x00$v"] = $props["\x00$class\x00$v"] = true;
127127
}
128128
}
129129
foreach ($arr as $k => &$v) {
@@ -142,7 +142,7 @@ private static function _dump(&$var, $level = 0)
142142
throw new Nette\InvalidArgumentException('Cannot dump resource.');
143143

144144
} else {
145-
return var_export($var, TRUE);
145+
return var_export($var, true);
146146
}
147147
}
148148

@@ -214,7 +214,7 @@ public static function formatDocComment($content)
214214
{
215215
if (($s = trim($content)) === '') {
216216
return '';
217-
} elseif (strpos($content, "\n") === FALSE) {
217+
} elseif (strpos($content, "\n") === false) {
218218
return "/** $s */\n";
219219
} else {
220220
return str_replace("\n", "\n * ", "/**\n$s") . "\n */\n";
@@ -244,7 +244,7 @@ public static function isIdentifier($value)
244244
/**
245245
* @return bool
246246
*/
247-
public static function isNamespaceIdentifier($value, $allowLeadingSlash = FALSE)
247+
public static function isNamespaceIdentifier($value, $allowLeadingSlash = false)
248248
{
249249
$re = '#^' . ($allowLeadingSlash ? '\\\\?' : '') . Helpers::PHP_IDENT . '(\\\\' . Helpers::PHP_IDENT . ')*\z#';
250250
return is_string($value) && preg_match($re, $value);
@@ -278,6 +278,6 @@ public static function extractNamespace($name)
278278
*/
279279
public static function extractShortName($name)
280280
{
281-
return ($pos = strrpos($name, '\\')) === FALSE ? $name : substr($name, $pos + 1);
281+
return ($pos = strrpos($name, '\\')) === false ? $name : substr($name, $pos + 1);
282282
}
283283
}

0 commit comments

Comments
 (0)