Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions bin/generate-changelog.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php declare(strict_types = 1);

use Httpful\Request;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

(function () {
(function (): void {
require_once __DIR__ . '/../vendor/autoload.php';

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

protected function configure()
protected function configure(): void
{
$this->setName('run');
$this->addArgument('fromCommit', InputArgument::REQUIRED);
Expand All @@ -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));

Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -79,28 +80,24 @@ 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;
}

};

$application = new \Symfony\Component\Console\Application();
$application = new Application();
$application->add($command);
$application->setDefaultCommand('run', true);
$application->run();

})();
31 changes: 18 additions & 13 deletions bin/generate-function-metadata.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php declare(strict_types = 1);

use JetBrains\PhpStorm\Pure;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\NodeVisitor\NodeConnectingVisitor;
use PhpParser\NodeVisitorAbstract;
use PhpParser\ParserFactory;
use PHPStan\File\FileReader;
use PHPStan\File\FileWriter;
use PHPStan\ShouldNotHappenException;

(function () {
(function (): void {
require_once __DIR__ . '/../vendor/autoload.php';

$parser = (new ParserFactory())->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;
}
Expand All @@ -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;
}
Expand All @@ -53,6 +58,7 @@ public function enterNode(Node $node)

return null;
}

};

foreach ($finder as $stubFile) {
Expand All @@ -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)),
);
}

Expand All @@ -79,7 +85,7 @@ public function enterNode(Node $node)
], true)) {
continue;
}
throw new \PHPStan\ShouldNotHappenException($functionName);
throw new ShouldNotHappenException($functionName);
}
}
$metadata[$functionName] = ['hasSideEffects' => false];
Expand All @@ -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];
Expand Down Expand Up @@ -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));
})();
31 changes: 16 additions & 15 deletions bin/generate-rule-error-classes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php declare(strict_types = 1);

use PHPStan\Rules\RuleErrorBuilder;

(function () {
(static function (): void {
require_once __DIR__ . '/../vendor/autoload.php';

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

php;
;

$ruleErrorTypes = \PHPStan\Rules\RuleErrorBuilder::getRuleErrorTypes();
$ruleErrorTypes = RuleErrorBuilder::getRuleErrorTypes();
$maxTypeNumber = array_sum(array_keys($ruleErrorTypes));
foreach (range(1, $maxTypeNumber) as $typeCombination) {
if (($typeCombination & 1) !== 1) {
Expand All @@ -33,24 +34,24 @@ class RuleError%s implements %s
$properties = [];
$interfaces = [];
foreach ($ruleErrorTypes as $typeNumber => [$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);
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<arg name="cache" value="tmp/cache/phpcs"/>
<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"/>
<arg value="sp"/>
<file>bin</file>
<file>src</file>
<file>tests</file>
<file>compiler/src</file>
Expand Down