diff --git a/bin/generate-changelog.php b/bin/generate-changelog.php
index ae1c865a47..d96a146399 100755
--- a/bin/generate-changelog.php
+++ b/bin/generate-changelog.php
@@ -1,17 +1,18 @@
#!/usr/bin/env php
-setName('run');
$this->addArgument('fromCommit', InputArgument::REQUIRED);
@@ -21,12 +22,12 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$commitLines = $this->exec(['git', 'log', sprintf('%s..%s', $input->getArgument('fromCommit'), $input->getArgument('toCommit')), '--reverse', '--pretty=%H %s']);
- $commits = array_map(function (string $line): array {
+ $commits = array_map(static function (string $line): array {
[$hash, $message] = explode(' ', $line, 2);
return [
'hash' => $hash,
- 'message' => $message
+ 'message' => $message,
];
}, explode("\n", $commitLines));
@@ -39,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->send();
if ($searchPullRequestsResponse->code !== 200) {
$output->writeln(var_export($searchPullRequestsResponse->body, true));
- throw new \InvalidArgumentException((string) $searchPullRequestsResponse->code);
+ throw new InvalidArgumentException((string) $searchPullRequestsResponse->code);
}
$searchPullRequestsResponse = $searchPullRequestsResponse->body;
@@ -49,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->send();
if ($searchIssuesResponse->code !== 200) {
$output->writeln(var_export($searchIssuesResponse->body, true));
- throw new \InvalidArgumentException((string) $searchIssuesResponse->code);
+ throw new InvalidArgumentException((string) $searchIssuesResponse->code);
}
$searchIssuesResponse = $searchIssuesResponse->body;
$items = array_merge($searchPullRequestsResponse->items, $searchIssuesResponse->items);
@@ -79,18 +80,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @param string[] $commandParts
- * @return string
*/
private function exec(array $commandParts): string
{
- $command = implode(' ', array_map(function (string $part): string {
- return escapeshellarg($part);
- }, $commandParts));
+ $command = implode(' ', array_map(static fn (string $part): string => escapeshellarg($part), $commandParts));
exec($command, $outputLines, $statusCode);
$output = implode("\n", $outputLines);
if ($statusCode !== 0) {
- throw new \InvalidArgumentException(sprintf('Command %s failed: %s', $command, $output));
+ throw new InvalidArgumentException(sprintf('Command %s failed: %s', $command, $output));
}
return $output;
@@ -98,9 +96,8 @@ private function exec(array $commandParts): string
};
- $application = new \Symfony\Component\Console\Application();
+ $application = new Application();
$application->add($command);
$application->setDefaultCommand('run', true);
$application->run();
-
})();
diff --git a/bin/generate-function-metadata.php b/bin/generate-function-metadata.php
index 400fd11a2a..4adbb1d038 100755
--- a/bin/generate-function-metadata.php
+++ b/bin/generate-function-metadata.php
@@ -1,33 +1,38 @@
#!/usr/bin/env php
-create(ParserFactory::ONLY_PHP7);
$finder = new Symfony\Component\Finder\Finder();
$finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->files()->name('*.php');
- $visitor = new class() extends \PhpParser\NodeVisitorAbstract {
+ $visitor = new class() extends NodeVisitorAbstract {
/** @var string[] */
- public $functions = [];
+ public array $functions = [];
/** @var string[] */
- public $methods = [];
+ public array $methods = [];
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Function_) {
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
- if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
+ if ($attr->name->toString() === Pure::class) {
$this->functions[] = $node->namespacedName->toLowerString();
break 2;
}
@@ -38,12 +43,12 @@ public function enterNode(Node $node)
if ($node instanceof Node\Stmt\ClassMethod) {
$class = $node->getAttribute('parent');
if (!$class instanceof Node\Stmt\ClassLike) {
- throw new \PHPStan\ShouldNotHappenException($node->name->toString());
+ throw new ShouldNotHappenException($node->name->toString());
}
$className = $class->namespacedName->toString();
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
- if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
+ if ($attr->name->toString() === Pure::class) {
$this->methods[] = sprintf('%s::%s', $className, $node->name->toString());
break 2;
}
@@ -53,6 +58,7 @@ public function enterNode(Node $node)
return null;
}
+
};
foreach ($finder as $stubFile) {
@@ -63,7 +69,7 @@ public function enterNode(Node $node)
$traverser->addVisitor($visitor);
$traverser->traverse(
- $parser->parse(\PHPStan\File\FileReader::read($path))
+ $parser->parse(FileReader::read($path)),
);
}
@@ -79,7 +85,7 @@ public function enterNode(Node $node)
], true)) {
continue;
}
- throw new \PHPStan\ShouldNotHappenException($functionName);
+ throw new ShouldNotHappenException($functionName);
}
}
$metadata[$functionName] = ['hasSideEffects' => false];
@@ -88,7 +94,7 @@ public function enterNode(Node $node)
foreach ($visitor->methods as $methodName) {
if (array_key_exists($methodName, $metadata)) {
if ($metadata[$methodName]['hasSideEffects']) {
- throw new \PHPStan\ShouldNotHappenException($methodName);
+ throw new ShouldNotHappenException($methodName);
}
}
$metadata[$methodName] = ['hasSideEffects' => false];
@@ -127,6 +133,5 @@ public function enterNode(Node $node)
);
}
- \PHPStan\File\FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content));
-
+ FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content));
})();
diff --git a/bin/generate-rule-error-classes.php b/bin/generate-rule-error-classes.php
index 116910ee86..991f72503b 100755
--- a/bin/generate-rule-error-classes.php
+++ b/bin/generate-rule-error-classes.php
@@ -1,7 +1,9 @@
#!/usr/bin/env php
- [$interface, $propertyName, $nativePropertyType, $phpDocPropertyType]) {
- if (($typeCombination & $typeNumber) === $typeNumber) {
- $interfaces[] = '\\' . $interface;
- if ($propertyName !== null && $nativePropertyType !== null && $phpDocPropertyType !== null) {
- $properties[] = [$propertyName, $nativePropertyType, $phpDocPropertyType];
- }
+ if (!(($typeCombination & $typeNumber) === $typeNumber)) {
+ continue;
}
+
+ $interfaces[] = '\\' . $interface;
+ if ($propertyName === null || $nativePropertyType === null || $phpDocPropertyType === null) {
+ continue;
+ }
+
+ $properties[] = [$propertyName, $nativePropertyType, $phpDocPropertyType];
}
$phpClass = sprintf(
$template,
$typeCombination,
implode(', ', $interfaces),
- implode("\n\n\t", array_map(function (array $property): string {
- return sprintf("%spublic %s $%s;", $property[2] !== $property[1] ? sprintf("/** @var %s */\n\t", $property[2]) : '', $property[1], $property[0]);
- }, $properties)),
- implode("\n\n\t", array_map(function (array $property): string {
- 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]);
- }, $properties))
+ 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)),
+ 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)),
);
file_put_contents(__DIR__ . '/../src/Rules/RuleErrors/RuleError' . $typeCombination . '.php', $phpClass);
diff --git a/phpcs.xml b/phpcs.xml
index d692bde751..5525e3efc1 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -8,6 +8,7 @@
+ bin
src
tests
compiler/src