Skip to content

Commit 2ef9a53

Browse files
sasezakiondrejmirtes
authored andcommitted
Added <file>bin</file> into phpcs.xml. and applied it.
1 parent 0bc75d9 commit 2ef9a53

4 files changed

+46
-42
lines changed

bin/generate-changelog.php

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php declare(strict_types = 1);
33

44
use Httpful\Request;
5+
use Symfony\Component\Console\Application;
56
use Symfony\Component\Console\Input\InputArgument;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89

9-
(function () {
10+
(function (): void {
1011
require_once __DIR__ . '/../vendor/autoload.php';
1112

1213
$command = new class() extends Symfony\Component\Console\Command\Command {
1314

14-
protected function configure()
15+
protected function configure(): void
1516
{
1617
$this->setName('run');
1718
$this->addArgument('fromCommit', InputArgument::REQUIRED);
@@ -21,12 +22,12 @@ protected function configure()
2122
protected function execute(InputInterface $input, OutputInterface $output)
2223
{
2324
$commitLines = $this->exec(['git', 'log', sprintf('%s..%s', $input->getArgument('fromCommit'), $input->getArgument('toCommit')), '--reverse', '--pretty=%H %s']);
24-
$commits = array_map(function (string $line): array {
25+
$commits = array_map(static function (string $line): array {
2526
[$hash, $message] = explode(' ', $line, 2);
2627

2728
return [
2829
'hash' => $hash,
29-
'message' => $message
30+
'message' => $message,
3031
];
3132
}, explode("\n", $commitLines));
3233

@@ -39,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3940
->send();
4041
if ($searchPullRequestsResponse->code !== 200) {
4142
$output->writeln(var_export($searchPullRequestsResponse->body, true));
42-
throw new \InvalidArgumentException((string) $searchPullRequestsResponse->code);
43+
throw new InvalidArgumentException((string) $searchPullRequestsResponse->code);
4344
}
4445
$searchPullRequestsResponse = $searchPullRequestsResponse->body;
4546

@@ -49,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4950
->send();
5051
if ($searchIssuesResponse->code !== 200) {
5152
$output->writeln(var_export($searchIssuesResponse->body, true));
52-
throw new \InvalidArgumentException((string) $searchIssuesResponse->code);
53+
throw new InvalidArgumentException((string) $searchIssuesResponse->code);
5354
}
5455
$searchIssuesResponse = $searchIssuesResponse->body;
5556
$items = array_merge($searchPullRequestsResponse->items, $searchIssuesResponse->items);
@@ -79,28 +80,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
7980

8081
/**
8182
* @param string[] $commandParts
82-
* @return string
8383
*/
8484
private function exec(array $commandParts): string
8585
{
86-
$command = implode(' ', array_map(function (string $part): string {
87-
return escapeshellarg($part);
88-
}, $commandParts));
86+
$command = implode(' ', array_map(static fn (string $part): string => escapeshellarg($part), $commandParts));
8987

9088
exec($command, $outputLines, $statusCode);
9189
$output = implode("\n", $outputLines);
9290
if ($statusCode !== 0) {
93-
throw new \InvalidArgumentException(sprintf('Command %s failed: %s', $command, $output));
91+
throw new InvalidArgumentException(sprintf('Command %s failed: %s', $command, $output));
9492
}
9593

9694
return $output;
9795
}
9896

9997
};
10098

101-
$application = new \Symfony\Component\Console\Application();
99+
$application = new Application();
102100
$application->add($command);
103101
$application->setDefaultCommand('run', true);
104102
$application->run();
105-
106103
})();

bin/generate-function-metadata.php

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php declare(strict_types = 1);
33

4+
use JetBrains\PhpStorm\Pure;
45
use PhpParser\Node;
56
use PhpParser\NodeTraverser;
67
use PhpParser\NodeVisitor\NameResolver;
78
use PhpParser\NodeVisitor\NodeConnectingVisitor;
9+
use PhpParser\NodeVisitorAbstract;
810
use PhpParser\ParserFactory;
11+
use PHPStan\File\FileReader;
12+
use PHPStan\File\FileWriter;
13+
use PHPStan\ShouldNotHappenException;
914

10-
(function () {
15+
(function (): void {
1116
require_once __DIR__ . '/../vendor/autoload.php';
1217

1318
$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
1419
$finder = new Symfony\Component\Finder\Finder();
1520
$finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->files()->name('*.php');
1621

17-
$visitor = new class() extends \PhpParser\NodeVisitorAbstract {
22+
$visitor = new class() extends NodeVisitorAbstract {
1823

1924
/** @var string[] */
20-
public $functions = [];
25+
public array $functions = [];
2126

2227
/** @var string[] */
23-
public $methods = [];
28+
public array $methods = [];
2429

2530
public function enterNode(Node $node)
2631
{
2732
if ($node instanceof Node\Stmt\Function_) {
2833
foreach ($node->attrGroups as $attrGroup) {
2934
foreach ($attrGroup->attrs as $attr) {
30-
if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
35+
if ($attr->name->toString() === Pure::class) {
3136
$this->functions[] = $node->namespacedName->toLowerString();
3237
break 2;
3338
}
@@ -38,12 +43,12 @@ public function enterNode(Node $node)
3843
if ($node instanceof Node\Stmt\ClassMethod) {
3944
$class = $node->getAttribute('parent');
4045
if (!$class instanceof Node\Stmt\ClassLike) {
41-
throw new \PHPStan\ShouldNotHappenException($node->name->toString());
46+
throw new ShouldNotHappenException($node->name->toString());
4247
}
4348
$className = $class->namespacedName->toString();
4449
foreach ($node->attrGroups as $attrGroup) {
4550
foreach ($attrGroup->attrs as $attr) {
46-
if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
51+
if ($attr->name->toString() === Pure::class) {
4752
$this->methods[] = sprintf('%s::%s', $className, $node->name->toString());
4853
break 2;
4954
}
@@ -53,6 +58,7 @@ public function enterNode(Node $node)
5358

5459
return null;
5560
}
61+
5662
};
5763

5864
foreach ($finder as $stubFile) {
@@ -63,7 +69,7 @@ public function enterNode(Node $node)
6369
$traverser->addVisitor($visitor);
6470

6571
$traverser->traverse(
66-
$parser->parse(\PHPStan\File\FileReader::read($path))
72+
$parser->parse(FileReader::read($path)),
6773
);
6874
}
6975

@@ -79,7 +85,7 @@ public function enterNode(Node $node)
7985
], true)) {
8086
continue;
8187
}
82-
throw new \PHPStan\ShouldNotHappenException($functionName);
88+
throw new ShouldNotHappenException($functionName);
8389
}
8490
}
8591
$metadata[$functionName] = ['hasSideEffects' => false];
@@ -88,7 +94,7 @@ public function enterNode(Node $node)
8894
foreach ($visitor->methods as $methodName) {
8995
if (array_key_exists($methodName, $metadata)) {
9096
if ($metadata[$methodName]['hasSideEffects']) {
91-
throw new \PHPStan\ShouldNotHappenException($methodName);
97+
throw new ShouldNotHappenException($methodName);
9298
}
9399
}
94100
$metadata[$methodName] = ['hasSideEffects' => false];
@@ -127,6 +133,5 @@ public function enterNode(Node $node)
127133
);
128134
}
129135

130-
\PHPStan\File\FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content));
131-
136+
FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content));
132137
})();

bin/generate-rule-error-classes.php

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env php
2-
<?php declare(strict_types=1);
2+
<?php declare(strict_types = 1);
3+
4+
use PHPStan\Rules\RuleErrorBuilder;
35

4-
(function () {
6+
(static function (): void {
57
require_once __DIR__ . '/../vendor/autoload.php';
68

79
$template = <<<'php'
@@ -22,9 +24,8 @@ class RuleError%s implements %s
2224
}
2325

2426
php;
25-
;
2627

27-
$ruleErrorTypes = \PHPStan\Rules\RuleErrorBuilder::getRuleErrorTypes();
28+
$ruleErrorTypes = RuleErrorBuilder::getRuleErrorTypes();
2829
$maxTypeNumber = array_sum(array_keys($ruleErrorTypes));
2930
foreach (range(1, $maxTypeNumber) as $typeCombination) {
3031
if (($typeCombination & 1) !== 1) {
@@ -33,24 +34,24 @@ class RuleError%s implements %s
3334
$properties = [];
3435
$interfaces = [];
3536
foreach ($ruleErrorTypes as $typeNumber => [$interface, $propertyName, $nativePropertyType, $phpDocPropertyType]) {
36-
if (($typeCombination & $typeNumber) === $typeNumber) {
37-
$interfaces[] = '\\' . $interface;
38-
if ($propertyName !== null && $nativePropertyType !== null && $phpDocPropertyType !== null) {
39-
$properties[] = [$propertyName, $nativePropertyType, $phpDocPropertyType];
40-
}
37+
if (!(($typeCombination & $typeNumber) === $typeNumber)) {
38+
continue;
4139
}
40+
41+
$interfaces[] = '\\' . $interface;
42+
if ($propertyName === null || $nativePropertyType === null || $phpDocPropertyType === null) {
43+
continue;
44+
}
45+
46+
$properties[] = [$propertyName, $nativePropertyType, $phpDocPropertyType];
4247
}
4348

4449
$phpClass = sprintf(
4550
$template,
4651
$typeCombination,
4752
implode(', ', $interfaces),
48-
implode("\n\n\t", array_map(function (array $property): string {
49-
return sprintf("%spublic %s $%s;", $property[2] !== $property[1] ? sprintf("/** @var %s */\n\t", $property[2]) : '', $property[1], $property[0]);
50-
}, $properties)),
51-
implode("\n\n\t", array_map(function (array $property): string {
52-
return sprintf("%spublic function get%s(): %s\n\t{\n\t\treturn \$this->%s;\n\t}", $property[2] !== $property[1] ? sprintf("/**\n\t * @return %s\n\t */\n\t", $property[2]) : '', ucfirst($property[0]), $property[1], $property[0]);
53-
}, $properties))
53+
implode("\n\n\t", array_map(static fn (array $property): string => sprintf('%spublic %s $%s;', $property[2] !== $property[1] ? sprintf("/** @var %s */\n\t", $property[2]) : '', $property[1], $property[0]), $properties)),
54+
implode("\n\n\t", array_map(static fn (array $property): string => sprintf("%spublic function get%s(): %s\n\t{\n\t\treturn \$this->%s;\n\t}", $property[2] !== $property[1] ? sprintf("/**\n\t * @return %s\n\t */\n\t", $property[2]) : '', ucfirst($property[0]), $property[1], $property[0]), $properties)),
5455
);
5556

5657
file_put_contents(__DIR__ . '/../src/Rules/RuleErrors/RuleError' . $typeCombination . '.php', $phpClass);

phpcs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<arg name="cache" value="tmp/cache/phpcs"/>
99
<arg name="ignore" value="compiler/tests/*/data,tests/*/data,tests/*/traits,tests/notAutoloaded,tests/*/cache,src/Reflection/SignatureMap/functionMap.php,tests/e2e/magic-setter,tests/e2e/anon-class"/>
1010
<arg value="sp"/>
11+
<file>bin</file>
1112
<file>src</file>
1213
<file>tests</file>
1314
<file>compiler/src</file>

0 commit comments

Comments
 (0)