Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing commas #8927

Merged
merged 1 commit into from Dec 18, 2022
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions bin/generate_testsuites.php
Expand Up @@ -17,12 +17,12 @@
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
'tests',
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS,
),
RecursiveIteratorIterator::LEAVES_ONLY
RecursiveIteratorIterator::LEAVES_ONLY,
),
'/.*Test.php$/'
)
'/.*Test.php$/',
),
);

mt_srand(4); // chosen by fair dice roll.
Expand All @@ -31,7 +31,7 @@

$order = array_map(
fn(): int => mt_rand(),
$files
$files,
);
array_multisort($order, $files);

Expand Down
2 changes: 1 addition & 1 deletion bin/max_used_shortcode.php
Expand Up @@ -13,7 +13,7 @@ function ($issue_type): int {
/** @var int */
return $issue_class::SHORTCODE;
},
$issue_types
$issue_types,
);

echo 'Max used shortcode: ' . max($shortcodes) . PHP_EOL;
14 changes: 7 additions & 7 deletions bin/update-property-map.php
Expand Up @@ -25,7 +25,7 @@
$lexer = new PhpParser\Lexer\Emulative();
$parser = (new PhpParser\ParserFactory)->create(
PhpParser\ParserFactory::PREFER_PHP7,
$lexer
$lexer,
);
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
Expand All @@ -48,7 +48,7 @@ function extractClassesFromStatements(array $statements): array
$stubbedClasses = [];
foreach (new RecursiveDirectoryIterator(
__DIR__ . '/../stubs',
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS,
) as $file) {
if (is_dir($file)) {
continue;
Expand All @@ -72,11 +72,11 @@ function extractClassesFromStatements(array $statements): array
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$docDir,
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS
FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS,
),
RecursiveIteratorIterator::LEAVES_ONLY
RecursiveIteratorIterator::LEAVES_ONLY,
),
'/.*.xml$/'
'/.*.xml$/',
);

$classes = require_once dirname(__DIR__) . '/dictionaries/ManualPropertyMap.php';
Expand All @@ -100,7 +100,7 @@ function extractClassesFromStatements(array $statements): array
$file,
get_class($exception),
$exception->getMessage(),
implode("\n", array_map(fn(LibXMLError $error): string => $error->message, libxml_get_errors()))
implode("\n", array_map(fn(LibXMLError $error): string => $error->message, libxml_get_errors())),
);
libxml_clear_errors();
continue;
Expand Down Expand Up @@ -186,5 +186,5 @@ function serializeArray(array $array, string $prefix): string

return $serialized;

EOF
EOF,
);
19 changes: 13 additions & 6 deletions examples/TemplateChecker.php
@@ -1,4 +1,5 @@
<?php

namespace Psalm\Examples\Template;

use InvalidArgumentException;
Expand All @@ -13,14 +14,21 @@
use Psalm\Internal\Analyzer\ClassLikeNameOptions;
use Psalm\Internal\Analyzer\MethodAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\MethodIdentifier;
use Psalm\Internal\Provider\NodeDataProvider;
use Psalm\Node\Stmt\VirtualClass;
use Psalm\Node\Stmt\VirtualClassMethod;
use Psalm\Storage\MethodStorage;
use Psalm\Type;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Union;
use Psalm\Internal\MethodIdentifier;

use function explode;
use function preg_match;
use function preg_replace;
use function str_replace;
use function strtolower;
use function trim;

class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer
{
Expand Down Expand Up @@ -92,7 +100,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,
null,
null,
[],
new ClassLikeNameOptions(true)
new ClassLikeNameOptions(true),
) === false
) {
return false;
Expand All @@ -109,7 +117,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,
new MethodIdentifier($method_id->fq_class_name, '__construct'),
$this_context,
$this->getRootFilePath(),
$this->getRootFileName()
$this->getRootFileName(),
);

$this_context->vars_in_scope['$this'] = new Union([new TNamedObject($class_storage->name)]);
Expand All @@ -119,7 +127,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,
$method_id,
$this_context,
$this->getRootFilePath(),
$this->getRootFileName()
$this->getRootFileName(),
);

$view_context = new Context();
Expand All @@ -139,7 +147,6 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,

/**
* @param array<PhpParser\Node\Stmt> $stmts
*
*/
protected function checkWithViewClass(Context $context, array $stmts): void
{
Expand Down Expand Up @@ -169,7 +176,7 @@ protected function checkWithViewClass(Context $context, array $stmts): void

$statements_source = new StatementsAnalyzer(
$view_method_analyzer,
new NodeDataProvider()
new NodeDataProvider(),
);

$statements_source->analyze($pseudo_method_stmts, $context);
Expand Down
15 changes: 8 additions & 7 deletions examples/TemplateScanner.php
@@ -1,32 +1,33 @@
<?php

namespace Psalm\Examples\Template;

use InvalidArgumentException;
use PhpParser;
use Psalm;
use Psalm\Checker\CommentChecker;
use Psalm\Codebase;
use Psalm\DocComment;
use Psalm\Progress\Progress;
use Psalm\Storage\FileStorage;

use function explode;
use function preg_match;
use function trim;

class TemplateScanner extends Psalm\Internal\Scanner\FileScanner
{
const VIEW_CLASS = 'Your\\View\\Class';

/**
* @param bool $storage_from_cache
*/
public function scan(
Codebase $codebase,
FileStorage $file_storage,
$storage_from_cache = false,
bool $storage_from_cache = false,
?Progress $progress = null
): void {
$stmts = $codebase->statements_provider->getStatementsForFile(
$file_storage->file_path,
7_04_00,
$progress
$progress,
);

if ($stmts === []) {
Expand All @@ -53,7 +54,7 @@ public function scan(

$codebase->scanner->queueClassLikeForScanning(
$fq_class_name,
true
true,
);
}
}
Expand Down
10 changes: 6 additions & 4 deletions examples/plugins/ClassUnqualifier.php
@@ -1,14 +1,16 @@
<?php

namespace Psalm\Example\Plugin;

use Psalm\FileManipulation;
use Psalm\Internal\Type\TypeTokenizer;
use Psalm\Plugin\EventHandler\AfterClassLikeExistenceCheckInterface;
use Psalm\Plugin\EventHandler\Event\AfterClassLikeExistenceCheckEvent;

use function array_map;
use function implode;
use function strpos;
use function strtolower;
use function implode;
use function array_map;

class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface
{
Expand Down Expand Up @@ -43,8 +45,8 @@ public static function afterClassLikeExistenceCheck(
'',
array_map(
fn($f) => $f[0],
$type_tokens
)
$type_tokens,
),
);

if ($new_candidate_type !== $candidate_type) {
Expand Down
16 changes: 8 additions & 8 deletions examples/plugins/FunctionCasingChecker.php
Expand Up @@ -5,18 +5,18 @@
use Exception;
use PhpParser;
use Psalm\CodeLocation;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\MethodIdentifier;
use Psalm\Issue\PluginIssue;
use Psalm\IssueBuffer;
use Psalm\Plugin\EventHandler\AfterFunctionCallAnalysisInterface;
use Psalm\Plugin\EventHandler\AfterMethodCallAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterFunctionCallAnalysisEvent;
use Psalm\Plugin\EventHandler\Event\AfterMethodCallAnalysisEvent;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\MethodIdentifier;

use function end;
use function explode;
use function strtolower;
use function end;

/**
* Checks that functions and methods are correctly-cased
Expand Down Expand Up @@ -50,9 +50,9 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
IssueBuffer::maybeAdd(
new IncorrectFunctionCasing(
'Function is incorrectly cased, expecting ' . $function_storage->cased_name,
new CodeLocation($statements_source, $expr->name)
new CodeLocation($statements_source, $expr->name),
),
$statements_source->getSuppressedIssues()
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
Expand All @@ -75,7 +75,7 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent
$statements_source instanceof StatementsAnalyzer
? $statements_source
: null,
strtolower($function_id)
strtolower($function_id),
);

if (!$function_storage->cased_name) {
Expand All @@ -88,9 +88,9 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent
IssueBuffer::maybeAdd(
new IncorrectFunctionCasing(
'Function is incorrectly cased, expecting ' . $function_storage->cased_name,
new CodeLocation($statements_source, $expr->name)
new CodeLocation($statements_source, $expr->name),
),
$statements_source->getSuppressedIssues()
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
Expand Down
8 changes: 4 additions & 4 deletions examples/plugins/InternalChecker.php
Expand Up @@ -15,7 +15,7 @@
class InternalChecker implements AfterClassLikeAnalysisInterface
{
/** @return null|false */
public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event)
public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event): ?bool
{
$storage = $event->getClasslikeStorage();
if (!$storage->internal
Expand All @@ -26,10 +26,10 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
new InternalClass(
"Class $storage->name must be marked @internal",
$storage->location,
$storage->name
$storage->name,
),
$event->getStatementsSource()->getSuppressedIssues(),
true
true,
);

if (!$event->getCodebase()->alter_code) {
Expand All @@ -50,7 +50,7 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
$parsed_docblock->tags['internal'] = [''];
$new_docblock_content = $parsed_docblock->render('');
$event->setFileReplacements([
new FileManipulation($docblock_start, $docblock_end, $new_docblock_content)
new FileManipulation($docblock_start, $docblock_end, $new_docblock_content),
]);
}
return null;
Expand Down
10 changes: 6 additions & 4 deletions examples/plugins/PreventFloatAssignmentChecker.php
Expand Up @@ -19,7 +19,8 @@ class PreventFloatAssignmentChecker implements AfterExpressionAnalysisInterface
*
* @return null
*/
public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $event): ?bool {
public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $event): ?bool
{
$expr = $event->getExpr();
$statements_source = $event->getStatementsSource();
if ($expr instanceof PhpParser\Node\Expr\Assign
Expand All @@ -29,15 +30,16 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve
IssueBuffer::maybeAdd(
new NoFloatAssignment(
'Don’t assign to floats',
new CodeLocation($statements_source, $expr)
new CodeLocation($statements_source, $expr),
),
$statements_source->getSuppressedIssues()
$statements_source->getSuppressedIssues(),
);
}

return null;
}
}

class NoFloatAssignment extends PluginIssue {
class NoFloatAssignment extends PluginIssue
{
}
4 changes: 3 additions & 1 deletion examples/plugins/SafeArrayKeyChecker.php
@@ -1,4 +1,5 @@
<?php

namespace Psalm\Example\Plugin;

use PhpParser\Node\Expr\ArrayItem;
Expand All @@ -13,7 +14,8 @@ class SafeArrayKeyChecker implements RemoveTaintsInterface
*
* @return list<string>
*/
public static function removeTaints(AddRemoveTaintsEvent $event): array {
public static function removeTaints(AddRemoveTaintsEvent $event): array
{
$item = $event->getExpr();
$statements_analyzer = $event->getStatementsSource();
if (!($item instanceof ArrayItem) || !($statements_analyzer instanceof StatementsAnalyzer)) {
Expand Down