Skip to content

Commit 11c1d29

Browse files
committed
coding style
1 parent b67f7a4 commit 11c1d29

16 files changed

+96
-52
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ public function setConstants(array $consts): self
365365
{
366366
$this->consts = [];
367367
foreach ($consts as $k => $v) {
368-
$const = $v instanceof Constant ? $v : (new Constant($k))->setValue($v);
368+
$const = $v instanceof Constant
369+
? $v
370+
: (new Constant($k))->setValue($v);
369371
$this->consts[$const->getName()] = $const;
370372
}
371373
return $this;

src/PhpGenerator/Dumper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
100100
$hideKeys = is_int(($tmp = array_keys($var))[0]) && $tmp === range($tmp[0], $tmp[0] + count($var) - 1);
101101

102102
foreach ($var as $k => &$v) {
103-
$keyPart = $hideKeys && $k === $counter ? '' : $this->dumpVar($k) . ' => ';
103+
$keyPart = $hideKeys && $k === $counter
104+
? ''
105+
: $this->dumpVar($k) . ' => ';
104106
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
105107
$outInline .= ($outInline === '' ? '' : ', ') . $keyPart;
106108
$outInline .= $this->dumpVar($v, $parents, 0, $column + strlen($outInline));
@@ -161,7 +163,7 @@ private function dumpObject(&$var, array $parents, int $level): string
161163
$out .= $space;
162164
return $class === \stdClass::class
163165
? "(object) [$out]"
164-
: '\\' . __CLASS__ . "::createObject('$class', [$out])";
166+
: '\\' . self::class . "::createObject('$class', [$out])";
165167
}
166168

167169

src/PhpGenerator/Factory.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
8080
$method->setParameters(array_map([$this, 'fromParameterReflection'], $from->getParameters()));
8181
$method->setStatic($from->isStatic());
8282
$isInterface = $from->getDeclaringClass()->isInterface();
83-
$method->setVisibility($from->isPrivate()
84-
? ClassType::VISIBILITY_PRIVATE
85-
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ($isInterface ? null : ClassType::VISIBILITY_PUBLIC))
83+
$method->setVisibility(
84+
$from->isPrivate()
85+
? ClassType::VISIBILITY_PRIVATE
86+
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ($isInterface ? null : ClassType::VISIBILITY_PUBLIC))
8687
);
8788
$method->setFinal($from->isFinal());
8889
$method->setAbstract($from->isAbstract() && !$isInterface);
@@ -147,9 +148,10 @@ public function fromConstantReflection(\ReflectionClassConstant $from): Constant
147148
{
148149
$const = new Constant($from->name);
149150
$const->setValue($from->getValue());
150-
$const->setVisibility($from->isPrivate()
151-
? ClassType::VISIBILITY_PRIVATE
152-
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC)
151+
$const->setVisibility(
152+
$from->isPrivate()
153+
? ClassType::VISIBILITY_PRIVATE
154+
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC)
153155
);
154156
$const->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
155157
return $const;
@@ -162,9 +164,10 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
162164
$prop = new Property($from->name);
163165
$prop->setValue($defaults[$prop->getName()] ?? null);
164166
$prop->setStatic($from->isStatic());
165-
$prop->setVisibility($from->isPrivate()
166-
? ClassType::VISIBILITY_PRIVATE
167-
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC)
167+
$prop->setVisibility(
168+
$from->isPrivate()
169+
? ClassType::VISIBILITY_PRIVATE
170+
: ($from->isProtected() ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC)
168171
);
169172
if (PHP_VERSION_ID >= 70400 && ($from->getType() instanceof \ReflectionNamedType)) {
170173
$prop->setType($from->getType()->getName());

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public static function extractNamespace(string $name): string
8888

8989
public static function extractShortName(string $name): string
9090
{
91-
return ($pos = strrpos($name, '\\')) === false ? $name : substr($name, $pos + 1);
91+
return ($pos = strrpos($name, '\\')) === false
92+
? $name
93+
: substr($name, $pos + 1);
9294
}
9395

9496

src/PhpGenerator/Method.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public function __toString(): string
6464
/** @return static */
6565
public function setBody(?string $code, array $args = null): self
6666
{
67-
$this->body = $args === null || $code === null ? $code : (new Dumper)->format($code, ...$args);
67+
$this->body = $args === null || $code === null
68+
? $code
69+
: (new Dumper)->format($code, ...$args);
6870
return $this;
6971
}
7072

src/PhpGenerator/Printer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public function printMethod(Method $method, PhpNamespace $namespace = null): str
108108
public function printClass(ClassType $class, PhpNamespace $namespace = null): string
109109
{
110110
$class->validate();
111-
$resolver = $this->resolveTypes && $namespace ? [$namespace, 'unresolveName'] : function ($s) { return $s; };
111+
$resolver = $this->resolveTypes && $namespace
112+
? [$namespace, 'unresolveName']
113+
: function ($s) { return $s; };
112114

113115
$traits = [];
114116
foreach ($class->getTraitResolutions() as $trait => $resolutions) {
@@ -233,11 +235,9 @@ protected function printUses(PhpNamespace $namespace): string
233235
$uses = [];
234236
foreach ($namespace->getUses() as $alias => $original) {
235237
if ($original !== ($name ? $name . '\\' . $alias : $alias)) {
236-
if ($alias === $original || substr($original, -(strlen($alias) + 1)) === '\\' . $alias) {
237-
$uses[] = "use $original;";
238-
} else {
239-
$uses[] = "use $original as $alias;";
240-
}
238+
$uses[] = $alias === $original || substr($original, -(strlen($alias) + 1)) === '\\' . $alias
239+
? "use $original;"
240+
: "use $original as $alias;";
241241
}
242242
}
243243
return implode("\n", $uses);

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ trait FunctionLike
4141
/** @return static */
4242
public function setBody(string $code, array $args = null): self
4343
{
44-
$this->body = $args === null ? $code : (new Dumper)->format($code, ...$args);
44+
$this->body = $args === null
45+
? $code
46+
: (new Dumper)->format($code, ...$args);
4547
return $this;
4648
}
4749

tests/PhpGenerator/Closure.long.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for ($name = 'abcde'; $name < 'abcdu'; $name++) {
1717
}
1818

1919
same(
20-
'function (
20+
'function (
2121
$abcde,
2222
$abcdf,
2323
$abcdg,
@@ -53,4 +53,6 @@ same(
5353
$abcdt
5454
) {
5555
return null;
56-
}', (string) $function);
56+
}',
57+
(string) $function
58+
);

tests/PhpGenerator/Closure.phpt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ $function->addUse('vars')
2121
->setReference(true);
2222

2323
same(
24-
'function &($a, $b) use ($this, &$vars) {
24+
'function &($a, $b) use ($this, &$vars) {
2525
return $a + $b;
26-
}', (string) $function);
26+
}',
27+
(string) $function
28+
);
2729

2830

2931
$uses = $function->getUses();
@@ -34,9 +36,11 @@ Assert::type(Nette\PhpGenerator\Parameter::class, $uses[1]);
3436
$uses = $function->setUses([$uses[0]]);
3537

3638
same(
37-
'function &($a, $b) use ($this) {
39+
'function &($a, $b) use ($this) {
3840
return $a + $b;
39-
}', (string) $function);
41+
}',
42+
(string) $function
43+
);
4044

4145

4246

@@ -54,14 +58,18 @@ $function
5458
->addUse('this');
5559

5660
same(
57-
'function () use ($this): array {
61+
'function () use ($this): array {
5862
return [];
59-
}', (string) $function);
63+
}',
64+
(string) $function
65+
);
6066

6167

6268

6369
$closure = function (stdClass $a, $b = null) {};
6470
$function = Closure::from($closure);
6571
same(
66-
'function (stdClass $a, $b = null) {
67-
}', (string) $function);
72+
'function (stdClass $a, $b = null) {
73+
}',
74+
(string) $function
75+
);

tests/PhpGenerator/Dumper.dump().wrap.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ require __DIR__ . '/../bootstrap.php';
1515

1616
$dumper = new Dumper;
1717
$dumper->wrapLength = 21;
18-
same("[
18+
same(
19+
"[
1920
'a' => [1, 2, 3],
2021
'aaaaaaaaa' => [
2122
1,
@@ -29,7 +30,8 @@ same("[
2930
])
3031
);
3132

32-
same("[
33+
same(
34+
"[
3335
'single' => 1 + 2,
3436
'multi' => [
3537
1,
@@ -41,7 +43,8 @@ same("[
4143
])
4244
);
4345

44-
same("(object) [
46+
same(
47+
"(object) [
4548
'a' => [1, 2, 3],
4649
'aaaaaaaaa' => [
4750
1,

0 commit comments

Comments
 (0)