Skip to content

Commit 9a2d6a8

Browse files
committed
used native PHP 8 functions
1 parent 9b3e3af commit 9a2d6a8

File tree

7 files changed

+16
-30
lines changed

7 files changed

+16
-30
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function removeConstant(string $name): static
410410
*/
411411
public function setCases(array $cases): static
412412
{
413-
(function (EnumCase ...$cases) {})(...array_values($cases));
413+
(function (EnumCase ...$cases) {})(...$cases);
414414
$this->cases = [];
415415
foreach ($cases as $case) {
416416
$this->cases[$case->getName()] = $case;
@@ -447,7 +447,7 @@ public function removeCase(string $name): static
447447
*/
448448
public function setProperties(array $props): static
449449
{
450-
(function (Property ...$props) {})(...array_values($props));
450+
(function (Property ...$props) {})(...$props);
451451
$this->properties = [];
452452
foreach ($props as $v) {
453453
$this->properties[$v->getName()] = $v;
@@ -506,7 +506,7 @@ public function hasProperty(string $name): bool
506506
*/
507507
public function setMethods(array $methods): static
508508
{
509-
(function (Method ...$methods) {})(...array_values($methods));
509+
(function (Method ...$methods) {})(...$methods);
510510
$this->methods = [];
511511
foreach ($methods as $m) {
512512
$this->methods[strtolower($m->getName())] = $m;

src/PhpGenerator/Dumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
125125
}
126126

127127
array_pop($parents);
128-
$wrap = strpos($outInline, "\n") !== false || $level * self::INDENT_LENGTH + $column + strlen($outInline) + 3 > $this->wrapLength; // 3 = [],
128+
$wrap = str_contains($outInline, "\n") || $level * self::INDENT_LENGTH + $column + strlen($outInline) + 3 > $this->wrapLength; // 3 = [],
129129
return '[' . ($wrap ? $outWrapped : $outInline) . ']';
130130
}
131131

@@ -251,7 +251,7 @@ private function dumpArguments(array &$var, int $column, bool $named): string
251251
. $this->indentation . $k . $this->dumpVar($v, [$var], 1);
252252
}
253253

254-
return count($var) > 1 && (strpos($outInline, "\n") !== false || $column + strlen($outInline) > $this->wrapLength)
254+
return count($var) > 1 && (str_contains($outInline, "\n") || $column + strlen($outInline) > $this->wrapLength)
255255
? $outWrapped . "\n"
256256
: $outInline;
257257
}

src/PhpGenerator/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(string $code)
4242

4343
private function parseCode(string $code): void
4444
{
45-
if (substr($code, 0, 5) !== '<?php') {
45+
if (!str_starts_with($code, '<?php')) {
4646
throw new Nette\InvalidStateException('The input string is not a PHP code.');
4747
}
4848

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public static function formatDocComment(string $content): string
7575
$s = str_replace('*/', '* /', $s);
7676
if ($s === '') {
7777
return '';
78-
} elseif (strpos($content, "\n") === false) {
79-
return "/** $s */\n";
80-
} else {
78+
} elseif (str_contains($content, "\n")) {
8179
return str_replace("\n", "\n * ", "/**\n$s") . "\n */\n";
80+
} else {
81+
return "/** $s */\n";
8282
}
8383
}
8484

src/PhpGenerator/Printer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
119119
. $returnType
120120
. ($method->isAbstract() || $isInterface
121121
? ";\n"
122-
: (strpos($params, "\n") === false ? "\n" : ' ')
122+
: (str_contains($params, "\n") ? ' ' : "\n")
123123
. "{\n"
124124
. $this->indent(ltrim(rtrim($body) . "\n"))
125125
. "}\n");
@@ -154,7 +154,7 @@ public function printClass(ClassType $class, ?PhpNamespace $namespace = null): s
154154
}
155155

156156
$enumType = isset($case) && $case->getValue() !== null
157-
? $this->returnTypeColon . Type::getType($case->getValue())
157+
? $this->returnTypeColon . get_debug_type($case->getValue())
158158
: '';
159159

160160
$consts = [];
@@ -332,9 +332,9 @@ protected function printType(?string $type, bool $nullable): string
332332
}
333333

334334
if ($nullable && strcasecmp($type, 'mixed')) {
335-
$type = strpos($type, '|') === false
336-
? '?' . $type
337-
: $type . '|null';
335+
$type = str_contains($type, '|')
336+
? $type . '|null'
337+
: '?' . $type;
338338
}
339339

340340
return $type;

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function addBody(string $code, ?array $args = null): static
5757
*/
5858
public function setParameters(array $val): static
5959
{
60-
(function (Parameter ...$val) {})(...array_values($val));
60+
(function (Parameter ...$val) {})(...$val);
6161
$this->parameters = [];
6262
foreach ($val as $v) {
6363
$this->parameters[$v->getName()] = $v;

src/PhpGenerator/Type.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ public static function intersection(string ...$types): string
5454

5555
public static function getType($value): ?string
5656
{
57-
if (is_object($value)) {
58-
return $value::class;
59-
} elseif (is_int($value)) {
60-
return self::INT;
61-
} elseif (is_float($value)) {
62-
return self::FLOAT;
63-
} elseif (is_string($value)) {
64-
return self::STRING;
65-
} elseif (is_bool($value)) {
66-
return self::BOOL;
67-
} elseif (is_array($value)) {
68-
return self::ARRAY;
69-
} else {
70-
return null;
71-
}
57+
return is_resource($value) ? null : get_debug_type($value);
7258
}
7359
}

0 commit comments

Comments
 (0)