Skip to content

Commit 2072d9b

Browse files
committed
cs whitespace
1 parent 4f2d215 commit 2072d9b

16 files changed

+97
-3
lines changed

src/PhpGenerator/Attribute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct(string $name, array $args)
3131
if (!Helpers::isNamespaceIdentifier($name)) {
3232
throw new Nette\InvalidArgumentException("Value '$name' is not valid attribute name.");
3333
}
34+
3435
$this->name = $name;
3536
$this->args = $args;
3637
}

src/PhpGenerator/ClassType.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public function __toString(): string
138138
if (PHP_VERSION_ID >= 70400) {
139139
throw $e;
140140
}
141+
141142
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
142143
return '';
143144
}
@@ -157,6 +158,7 @@ public function setName(?string $name): self
157158
if ($name !== null && (!Helpers::isIdentifier($name) || isset(Helpers::KEYWORDS[strtolower($name)]))) {
158159
throw new Nette\InvalidArgumentException("Value '$name' is not valid class name.");
159160
}
161+
160162
$this->name = $name;
161163
return $this;
162164
}
@@ -222,6 +224,7 @@ public function setType(string $type): self
222224
if (!in_array($type, [self::TYPE_CLASS, self::TYPE_INTERFACE, self::TYPE_TRAIT, self::TYPE_ENUM], true)) {
223225
throw new Nette\InvalidArgumentException('Argument must be class|interface|trait|enum.');
224226
}
227+
225228
$this->type = $type;
226229
return $this;
227230
}
@@ -270,6 +273,7 @@ public function setExtends($names): self
270273
if (!is_string($names) && !is_array($names)) {
271274
throw new Nette\InvalidArgumentException('Argument must be string or string[].');
272275
}
276+
273277
$this->validateNames((array) $names);
274278
$this->extends = $names;
275279
return $this;
@@ -340,8 +344,10 @@ public function setTraits(array $traits): self
340344
if (!$trait instanceof TraitUse) {
341345
$trait = new TraitUse($trait);
342346
}
347+
343348
$this->traits[$trait->getName()] = $trait;
344349
}
350+
345351
return $this;
346352
}
347353

@@ -370,6 +376,7 @@ public function addTrait(string $name, $resolutions = [])
370376
if ($resolutions === true) {
371377
return $trait;
372378
}
379+
373380
array_map(function ($item) use ($trait) {
374381
$trait->addResolution($item);
375382
}, $resolutions);
@@ -395,6 +402,7 @@ public function addMember($member): self
395402
if ($this->isInterface()) {
396403
$member->setBody(null);
397404
}
405+
398406
$this->methods[strtolower($member->getName())] = $member;
399407

400408
} elseif ($member instanceof Property) {
@@ -428,8 +436,10 @@ public function setConstants(array $consts): self
428436
if (!$const instanceof Constant) {
429437
$const = (new Constant($k))->setValue($const)->setPublic();
430438
}
439+
431440
$this->consts[$const->getName()] = $const;
432441
}
442+
433443
return $this;
434444
}
435445

@@ -469,6 +479,7 @@ public function setCases(array $cases): self
469479
foreach ($cases as $case) {
470480
$this->cases[$case->getName()] = $case;
471481
}
482+
472483
return $this;
473484
}
474485

@@ -507,6 +518,7 @@ public function setProperties(array $props): self
507518
foreach ($props as $v) {
508519
$this->properties[$v->getName()] = $v;
509520
}
521+
510522
return $this;
511523
}
512524

@@ -523,6 +535,7 @@ public function getProperty(string $name): Property
523535
if (!isset($this->properties[$name])) {
524536
throw new Nette\InvalidArgumentException("Property '$name' not found.");
525537
}
538+
526539
return $this->properties[$name];
527540
}
528541

@@ -566,6 +579,7 @@ public function setMethods(array $methods): self
566579
foreach ($methods as $m) {
567580
$this->methods[strtolower($m->getName())] = $m;
568581
}
582+
569583
return $this;
570584
}
571585

@@ -577,6 +591,7 @@ public function getMethods(): array
577591
foreach ($this->methods as $m) {
578592
$res[$m->getName()] = $m;
579593
}
594+
580595
return $res;
581596
}
582597

@@ -587,6 +602,7 @@ public function getMethod(string $name): Method
587602
if (!$m) {
588603
throw new Nette\InvalidArgumentException("Method '$name' not found.");
589604
}
605+
590606
return $m;
591607
}
592608

@@ -599,6 +615,7 @@ public function addMethod(string $name): Method
599615
} else {
600616
$method->setPublic();
601617
}
618+
602619
return $this->methods[strtolower($name)] = $method;
603620
}
604621

src/PhpGenerator/Closure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function __toString(): string
4141
if (PHP_VERSION_ID >= 70400) {
4242
throw $e;
4343
}
44+
4445
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
4546
return '';
4647
}

src/PhpGenerator/Dumper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private function dumpObject($var, array $parents, int $level): string
155155
? '\Closure::fromCallable(' . $this->dump($inner) . ')'
156156
: implode('::', (array) $inner) . '(...)';
157157
}
158+
158159
throw new Nette\InvalidArgumentException('Cannot dump closure.');
159160
}
160161

@@ -227,19 +228,23 @@ public function format(string $statement, ...$args): string
227228
if (!is_array($arg)) {
228229
throw new Nette\InvalidArgumentException('Argument must be an array.');
229230
}
231+
230232
$res .= $this->dumpArguments($arg, strlen($res) - strrpos($res, "\n"), $token === '...?:');
231233

232234
} else { // $ -> ::
233235
$arg = array_shift($args);
234236
if ($arg instanceof Literal || !Helpers::isIdentifier($arg)) {
235237
$arg = '{' . $this->dumpVar($arg) . '}';
236238
}
239+
237240
$res .= substr($token, 0, -1) . $arg;
238241
}
239242
}
243+
240244
if ($args) {
241245
throw new Nette\InvalidArgumentException('Insufficient number of placeholders.');
242246
}
247+
243248
return $res;
244249
}
245250

src/PhpGenerator/Extractor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(string $code)
3434
if (!class_exists(ParserFactory::class)) {
3535
throw new Nette\NotSupportedException("PHP-Parser is required to load method bodies, install package 'nikic/php-parser' 4.7 or newer.");
3636
}
37+
3738
$this->printer = new PhpParser\PrettyPrinter\Standard;
3839
$this->parseCode($code);
3940
}
@@ -44,6 +45,7 @@ private function parseCode(string $code): void
4445
if (substr($code, 0, 5) !== '<?php') {
4546
throw new Nette\InvalidStateException('The input string is not a PHP code.');
4647
}
48+
4749
$this->code = str_replace("\r\n", "\n", $code);
4850
$lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => ['startFilePos', 'endFilePos', 'comments']]);
4951
$parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7, $lexer);
@@ -71,6 +73,7 @@ public function extractMethodBodies(string $className): array
7173
$res[$methodNode->name->toString()] = $this->getReformattedContents($methodNode->stmts, 2);
7274
}
7375
}
76+
7477
return $res;
7578
}
7679

@@ -111,7 +114,6 @@ private function prepareReplacements(array $statements): array
111114
Helpers::tagName($node->toCodeString(), $of),
112115
];
113116
}
114-
115117
} elseif ($node instanceof Node\Scalar\String_ || $node instanceof Node\Scalar\EncapsedStringPart) {
116118
// multi-line strings => singleline
117119
$token = $this->getNodeContents($node);
@@ -123,7 +125,6 @@ private function prepareReplacements(array $statements): array
123125
$quote . addcslashes($node->value, "\x00..\x1F") . $quote,
124126
];
125127
}
126-
127128
} elseif ($node instanceof Node\Scalar\Encapsed) {
128129
// HEREDOC => "string"
129130
if ($node->getAttribute('kind') === Node\Scalar\String_::KIND_HEREDOC) {
@@ -153,6 +154,7 @@ private function performReplacements(string $s, array $replacements): string
153154
foreach ($replacements as [$start, $end, $replacement]) {
154155
$s = substr_replace($s, $replacement, $start, $end - $start + 1);
155156
}
157+
156158
return $s;
157159
}
158160

@@ -179,6 +181,7 @@ public function enterNode(Node $node)
179181
if (!$node->name) {
180182
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
181183
}
184+
182185
$class = $this->addClassToFile($phpFile, $node);
183186
} elseif ($node instanceof Node\Stmt\Interface_) {
184187
$class = $this->addInterfaceToFile($phpFile, $node);
@@ -199,6 +202,7 @@ public function enterNode(Node $node)
199202
} elseif ($node instanceof Node\Stmt\EnumCase) {
200203
$this->addEnumCaseToClass($class, $node);
201204
}
205+
202206
if ($node instanceof Node\FunctionLike) {
203207
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
204208
}
@@ -230,9 +234,11 @@ private function addClassToFile(PhpFile $phpFile, Node\Stmt\Class_ $node): Class
230234
if ($node->extends) {
231235
$class->setExtends($node->extends->toString());
232236
}
237+
233238
foreach ($node->implements as $item) {
234239
$class->addImplement($item->toString());
235240
}
241+
236242
$class->setFinal($node->isFinal());
237243
$class->setAbstract($node->isAbstract());
238244
$this->addCommentAndAttributes($class, $node);
@@ -246,6 +252,7 @@ private function addInterfaceToFile(PhpFile $phpFile, Node\Stmt\Interface_ $node
246252
foreach ($node->extends as $item) {
247253
$class->addExtend($item->toString());
248254
}
255+
249256
$this->addCommentAndAttributes($class, $node);
250257
return $class;
251258
}
@@ -265,6 +272,7 @@ private function addEnumToFile(PhpFile $phpFile, Node\Stmt\Enum_ $node): ClassTy
265272
foreach ($node->implements as $item) {
266273
$class->addImplement($item->toString());
267274
}
275+
268276
$this->addCommentAndAttributes($class, $node);
269277
return $class;
270278
}
@@ -282,9 +290,11 @@ private function addTraitToClass(ClassType $class, Node\Stmt\TraitUse $node): vo
282290
foreach ($node->traits as $item) {
283291
$trait = $class->addTrait($item->toString(), true);
284292
}
293+
285294
foreach ($node->adaptations as $item) {
286295
$trait->addResolution(trim($this->toPhp($item), ';'));
287296
}
297+
288298
$this->addCommentAndAttributes($trait, $node);
289299
}
290300

@@ -299,10 +309,12 @@ private function addPropertyToClass(ClassType $class, Node\Stmt\Property $node):
299309
} elseif ($node->isProtected()) {
300310
$prop->setProtected();
301311
}
312+
302313
$prop->setType($node->type ? $this->toPhp($node->type) : null);
303314
if ($item->default) {
304315
$prop->setValue(new Literal($this->getReformattedContents([$item->default], 1)));
305316
}
317+
306318
$prop->setReadOnly(method_exists($node, 'isReadonly') && $node->isReadonly());
307319
$this->addCommentAndAttributes($prop, $node);
308320
}
@@ -320,6 +332,7 @@ private function addMethodToClass(ClassType $class, Node\Stmt\ClassMethod $node)
320332
} elseif ($node->isProtected()) {
321333
$method->setProtected();
322334
}
335+
323336
$this->setupFunction($method, $node);
324337
}
325338

@@ -334,6 +347,7 @@ private function addConstantToClass(ClassType $class, Node\Stmt\ClassConst $node
334347
} elseif ($node->isProtected()) {
335348
$const->setProtected();
336349
}
350+
337351
$const->setFinal(method_exists($node, 'isFinal') && $node->isFinal());
338352
$this->addCommentAndAttributes($const, $node);
339353
}
@@ -366,6 +380,7 @@ private function addCommentAndAttributes($element, Node $node): void
366380
$args[] = $value;
367381
}
368382
}
383+
369384
$element->addAttribute($attribute->name->toString(), $args);
370385
}
371386
}
@@ -387,8 +402,10 @@ private function setupFunction($function, Node\FunctionLike $node): void
387402
if ($item->default) {
388403
$param->setDefaultValue(new Literal($this->getReformattedContents([$item->default], 2)));
389404
}
405+
390406
$this->addCommentAndAttributes($param, $item);
391407
}
408+
392409
$this->addCommentAndAttributes($function, $node);
393410
if ($node->stmts) {
394411
$function->setBody($this->getReformattedContents($node->stmts, 2));

0 commit comments

Comments
 (0)