Skip to content

Commit 6303c62

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent f9fa340 commit 6303c62

20 files changed

+134
-134
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Anonymous class
188188
---------------
189189

190190
```php
191-
$class = new Nette\PhpGenerator\ClassType(NULL);
191+
$class = new Nette\PhpGenerator\ClassType(null);
192192
$class->addMethod('__construct')
193193
->addParameter('foo');
194194

@@ -339,6 +339,6 @@ $class = Nette\PhpGenerator\ClassType::from(PDO::class);
339339
$function = Nette\PhpGenerator\GlobalFunction::from('trim');
340340

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

src/PhpGenerator/ClassType.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ final class ClassType
2828
const TYPE_INTERFACE = 'interface';
2929
const TYPE_TRAIT = 'trait';
3030

31-
/** @var PhpNamespace|NULL */
31+
/** @var PhpNamespace|null */
3232
private $namespace;
3333

34-
/** @var string|NULL */
34+
/** @var string|null */
3535
private $name;
3636

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

4040
/** @var bool */
41-
private $final = FALSE;
41+
private $final = false;
4242

4343
/** @var bool */
44-
private $abstract = FALSE;
44+
private $abstract = false;
4545

4646
/** @var string|string[] */
4747
private $extends = [];
@@ -77,7 +77,7 @@ public static function from($class): self
7777
}
7878

7979

80-
public function __construct(string $name = NULL, PhpNamespace $namespace = NULL)
80+
public function __construct(string $name = null, PhpNamespace $namespace = null)
8181
{
8282
$this->setName($name);
8383
$this->namespace = $namespace;
@@ -103,7 +103,7 @@ public function __toString(): string
103103
foreach ($this->properties as $property) {
104104
$properties[] = Helpers::formatDocComment((string) $property->getComment())
105105
. ($property->getVisibility() ?: 'public') . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName()
106-
. ($property->getValue() === NULL ? '' : ' = ' . Helpers::dump($property->getValue()))
106+
. ($property->getValue() === null ? '' : ' = ' . Helpers::dump($property->getValue()))
107107
. ';';
108108
}
109109

@@ -130,7 +130,7 @@ public function __toString(): string
130130

131131

132132
/**
133-
* @return PhpNamespace|NULL
133+
* @return PhpNamespace|null
134134
*/
135135
public function getNamespace()
136136
{
@@ -139,12 +139,12 @@ public function getNamespace()
139139

140140

141141
/**
142-
* @param string|NULL
142+
* @param string|null
143143
* @return static
144144
*/
145145
public function setName($name): self
146146
{
147-
if ($name !== NULL && !Helpers::isIdentifier($name)) {
147+
if ($name !== null && !Helpers::isIdentifier($name)) {
148148
throw new Nette\InvalidArgumentException("Value '$name' is not valid class name.");
149149
}
150150
$this->name = $name;
@@ -153,7 +153,7 @@ public function setName($name): self
153153

154154

155155
/**
156-
* @return string|NULL
156+
* @return string|null
157157
*/
158158
public function getName()
159159
{
@@ -166,7 +166,7 @@ public function getName()
166166
*/
167167
public function setType(string $type): self
168168
{
169-
if (!in_array($type, ['class', 'interface', 'trait'], TRUE)) {
169+
if (!in_array($type, ['class', 'interface', 'trait'], true)) {
170170
throw new Nette\InvalidArgumentException('Argument must be class|interface|trait.');
171171
}
172172
$this->type = $type;
@@ -183,7 +183,7 @@ public function getType(): string
183183
/**
184184
* @return static
185185
*/
186-
public function setFinal(bool $state = TRUE): self
186+
public function setFinal(bool $state = true): self
187187
{
188188
$this->final = $state;
189189
return $this;
@@ -199,7 +199,7 @@ public function isFinal(): bool
199199
/**
200200
* @return static
201201
*/
202-
public function setAbstract(bool $state = TRUE): self
202+
public function setAbstract(bool $state = true): self
203203
{
204204
$this->abstract = $state;
205205
return $this;
@@ -413,7 +413,7 @@ public function getProperty($name): Property
413413
/**
414414
* @param string without $
415415
*/
416-
public function addProperty(string $name, $value = NULL): Property
416+
public function addProperty(string $name, $value = null): Property
417417
{
418418
return $this->properties[$name] = (new Property($name))->setValue($value);
419419
}
@@ -458,7 +458,7 @@ public function addMethod(string $name): Method
458458
{
459459
$method = (new Method($name))->setNamespace($this->namespace);
460460
if ($this->type === 'interface') {
461-
$method->setBody(NULL);
461+
$method->setBody(null);
462462
} else {
463463
$method->setVisibility('public');
464464
}
@@ -469,7 +469,7 @@ public function addMethod(string $name): Method
469469
private function validate(array $names)
470470
{
471471
foreach ($names as $name) {
472-
if (!Helpers::isNamespaceIdentifier($name, TRUE)) {
472+
if (!Helpers::isNamespaceIdentifier($name, true)) {
473473
throw new Nette\InvalidArgumentException("Value '$name' is not valid class name.");
474474
}
475475
}

src/PhpGenerator/Factory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
5757
$method->setParameters(array_map([$this, 'fromParameterReflection'], $from->getParameters()));
5858
$method->setStatic($from->isStatic());
5959
$isInterface = $from->getDeclaringClass()->isInterface();
60-
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? NULL : 'public')));
60+
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? null : 'public')));
6161
$method->setFinal($from->isFinal());
6262
$method->setAbstract($from->isAbstract() && !$isInterface);
63-
$method->setBody($from->isAbstract() ? NULL : '');
63+
$method->setBody($from->isAbstract() ? null : '');
6464
$method->setReturnReference($from->returnsReference());
6565
$method->setVariadic($from->isVariadic());
6666
$method->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
@@ -96,13 +96,13 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
9696
{
9797
$param = new Parameter($from->getName());
9898
$param->setReference($from->isPassedByReference());
99-
$param->setTypeHint($from->hasType() ? (string) $from->getType() : NULL);
99+
$param->setTypeHint($from->hasType() ? (string) $from->getType() : null);
100100
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
101101
if ($from->isDefaultValueAvailable()) {
102102
$param->setDefaultValue($from->isDefaultValueConstant()
103103
? new PhpLiteral($from->getDefaultValueConstantName())
104104
: $from->getDefaultValue());
105-
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== NULL);
105+
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== null);
106106
}
107107
return $param;
108108
}
@@ -111,7 +111,7 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
111111
public function fromPropertyReflection(\ReflectionProperty $from): Property
112112
{
113113
$prop = new Property($from->getName());
114-
$prop->setValue($from->getDeclaringClass()->getDefaultProperties()[$prop->getName()] ?? NULL);
114+
$prop->setValue($from->getDeclaringClass()->getDefaultProperties()[$prop->getName()] ?? null);
115115
$prop->setStatic($from->isStatic());
116116
$prop->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public'));
117117
$prop->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));

src/PhpGenerator/Helpers.php

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

4141
} elseif (is_float($var)) {
4242
if (is_finite($var)) {
43-
$var = var_export($var, TRUE);
44-
return strpos($var, '.') === FALSE ? $var . '.0' : $var; // workaround for PHP < 7.0.2
43+
$var = var_export($var, true);
44+
return strpos($var, '.') === false ? $var . '.0' : $var; // workaround for PHP < 7.0.2
4545
}
46-
return str_replace('.0', '', var_export($var, TRUE)); // workaround for PHP 7.0.2
46+
return str_replace('.0', '', var_export($var, true)); // workaround for PHP 7.0.2
4747

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

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

7272
static $marker;
73-
if ($marker === NULL) {
74-
$marker = uniqid("\x00", TRUE);
73+
if ($marker === null) {
74+
$marker = uniqid("\x00", true);
7575
}
7676
if (empty($var)) {
7777
$out = '';
@@ -82,7 +82,7 @@ private static function _dump(&$var, int $level = 0)
8282
} else {
8383
$out = '';
8484
$outAlt = "\n$space";
85-
$var[$marker] = TRUE;
85+
$var[$marker] = true;
8686
$counter = 0;
8787
foreach ($var as $k => &$v) {
8888
if ($k !== $marker) {
@@ -94,7 +94,7 @@ private static function _dump(&$var, int $level = 0)
9494
}
9595
unset($var[$marker]);
9696
}
97-
return '[' . (strpos($out, "\n") === FALSE && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
97+
return '[' . (strpos($out, "\n") === false && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
9898

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

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

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

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

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

145145
} else {
146-
return var_export($var, TRUE);
146+
return var_export($var, true);
147147
}
148148
}
149149

@@ -209,7 +209,7 @@ public static function formatDocComment(string $content): string
209209
{
210210
if (($s = trim($content)) === '') {
211211
return '';
212-
} elseif (strpos($content, "\n") === FALSE) {
212+
} elseif (strpos($content, "\n") === false) {
213213
return "/** $s */\n";
214214
} else {
215215
return str_replace("\n", "\n * ", "/**\n$s") . "\n */\n";
@@ -229,7 +229,7 @@ public static function isIdentifier($value): bool
229229
}
230230

231231

232-
public static function isNamespaceIdentifier($value, bool $allowLeadingSlash = FALSE): bool
232+
public static function isNamespaceIdentifier($value, bool $allowLeadingSlash = false): bool
233233
{
234234
$re = '#^' . ($allowLeadingSlash ? '\\\\?' : '') . Helpers::PHP_IDENT . '(\\\\' . Helpers::PHP_IDENT . ')*\z#';
235235
return is_string($value) && preg_match($re, $value);
@@ -254,6 +254,6 @@ public static function extractNamespace(string $name): string
254254

255255
public static function extractShortName(string $name): string
256256
{
257-
return ($pos = strrpos($name, '\\')) === FALSE ? $name : substr($name, $pos + 1);
257+
return ($pos = strrpos($name, '\\')) === false ? $name : substr($name, $pos + 1);
258258
}
259259
}

src/PhpGenerator/Method.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Class method.
1717
*
18-
* @property string|NULL $body
18+
* @property string|null $body
1919
*/
2020
final class Method
2121
{
@@ -25,17 +25,17 @@ final class Method
2525
use Traits\VisibilityAware;
2626
use Traits\CommentAware;
2727

28-
/** @var string|NULL */
28+
/** @var string|null */
2929
private $body = '';
3030

3131
/** @var bool */
32-
private $static = FALSE;
32+
private $static = false;
3333

3434
/** @var bool */
35-
private $final = FALSE;
35+
private $final = false;
3636

3737
/** @var bool */
38-
private $abstract = FALSE;
38+
private $abstract = false;
3939

4040

4141
/**
@@ -73,29 +73,29 @@ public function __toString(): string
7373
. $this->name
7474
. $this->parametersToString()
7575
. $this->returnTypeToString()
76-
. ($this->abstract || $this->body === NULL
76+
. ($this->abstract || $this->body === null
7777
? ';'
7878
: "\n{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
7979
}
8080

8181

8282
/**
83-
* @param string|NULL
83+
* @param string|null
8484
* @return static
8585
*/
86-
public function setBody($code, array $args = NULL): self
86+
public function setBody($code, array $args = null): self
8787
{
88-
if ($code === FALSE) {
89-
$code = NULL;
90-
trigger_error(__METHOD__ . '() use NULL instead of FALSE', E_USER_DEPRECATED);
88+
if ($code === false) {
89+
$code = null;
90+
trigger_error(__METHOD__ . '() use null instead of false', E_USER_DEPRECATED);
9191
}
92-
$this->body = $args === NULL ? $code : Helpers::formatArgs($code, $args);
92+
$this->body = $args === null ? $code : Helpers::formatArgs($code, $args);
9393
return $this;
9494
}
9595

9696

9797
/**
98-
* @return string|NULL
98+
* @return string|null
9999
*/
100100
public function getBody()
101101
{
@@ -106,7 +106,7 @@ public function getBody()
106106
/**
107107
* @return static
108108
*/
109-
public function setStatic(bool $state = TRUE): self
109+
public function setStatic(bool $state = true): self
110110
{
111111
$this->static = $state;
112112
return $this;
@@ -122,7 +122,7 @@ public function isStatic(): bool
122122
/**
123123
* @return static
124124
*/
125-
public function setFinal(bool $state = TRUE): self
125+
public function setFinal(bool $state = true): self
126126
{
127127
$this->final = $state;
128128
return $this;
@@ -138,7 +138,7 @@ public function isFinal(): bool
138138
/**
139139
* @return static
140140
*/
141-
public function setAbstract(bool $state = TRUE): self
141+
public function setAbstract(bool $state = true): self
142142
{
143143
$this->abstract = $state;
144144
return $this;

0 commit comments

Comments
 (0)