Skip to content

Commit

Permalink
Short list syntax (#4102)
Browse files Browse the repository at this point in the history
* Short list syntax

* revert unrelated CS
  • Loading branch information
orklah committed Sep 2, 2020
1 parent 6f92846 commit 73f6fcd
Show file tree
Hide file tree
Showing 46 changed files with 100 additions and 99 deletions.
2 changes: 1 addition & 1 deletion examples/TemplateScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function scan(
throw new \InvalidArgumentException('Could not interpret doc comment correctly');
}

list($fq_class_name) = explode('::', $matches[1]);
[$fq_class_name] = explode('::', $matches[1]);

$codebase->scanner->queueClassLikeForScanning(
$fq_class_name,
Expand Down
22 changes: 11 additions & 11 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public function findReferencesToMethod($method_id)
*/
public function findReferencesToProperty(string $property_id)
{
list($fq_class_name, $property_name) = explode('::', $property_id);
[$fq_class_name, $property_name] = explode('::', $property_id);

return $this->file_reference_provider->getClassPropertyLocations(
strtolower($fq_class_name) . '::' . $property_name
Expand Down Expand Up @@ -1055,15 +1055,15 @@ public function getSymbolInformation(string $file_path, string $symbol)
return '<?php ' . $storage->getSignature(true);
}

list(, $symbol_name) = explode('::', $symbol);
[, $symbol_name] = explode('::', $symbol);

if (strpos($symbol, '$') !== false) {
$storage = $this->properties->getStorage($symbol);

return '<?php ' . $storage->getInfo() . ' ' . $symbol_name;
}

list($fq_classlike_name, $const_name) = explode('::', $symbol);
[$fq_classlike_name, $const_name] = explode('::', $symbol);

$class_constants = $this->classlikes->getConstantsForClass(
$fq_classlike_name,
Expand Down Expand Up @@ -1149,7 +1149,7 @@ public function getSymbolLocation(string $file_path, string $symbol)
return $storage->location;
}

list($fq_classlike_name, $const_name) = explode('::', $symbol);
[$fq_classlike_name, $const_name] = explode('::', $symbol);

$class_constants = $this->classlikes->getConstantsForClass(
$fq_classlike_name,
Expand Down Expand Up @@ -1209,7 +1209,7 @@ public function getReferenceAtPosition(string $file_path, Position $position)

$offset = $position->toOffset($file_contents);

list($reference_map, $type_map) = $this->analyzer->getMapsForFile($file_path);
[$reference_map, $type_map] = $this->analyzer->getMapsForFile($file_path);

$reference = null;

Expand All @@ -1222,7 +1222,7 @@ public function getReferenceAtPosition(string $file_path, Position $position)

ksort($reference_map);

foreach ($reference_map as $start_pos => list($end_pos, $possible_reference)) {
foreach ($reference_map as $start_pos => [$end_pos, $possible_reference]) {
if ($offset < $start_pos) {
break;
}
Expand Down Expand Up @@ -1262,7 +1262,7 @@ public function getFunctionArgumentAtPosition(string $file_path, Position $posit

$offset = $position->toOffset($file_contents);

list(, , $argument_map) = $this->analyzer->getMapsForFile($file_path);
[, , $argument_map] = $this->analyzer->getMapsForFile($file_path);

$reference = null;
$argument_number = null;
Expand All @@ -1276,7 +1276,7 @@ public function getFunctionArgumentAtPosition(string $file_path, Position $posit

ksort($argument_map);

foreach ($argument_map as $start_pos => list($end_pos, $possible_reference, $possible_argument_number)) {
foreach ($argument_map as $start_pos => [$end_pos, $possible_reference, $possible_argument_number]) {
if ($offset < $start_pos) {
break;
}
Expand Down Expand Up @@ -1377,15 +1377,15 @@ public function getCompletionDataAtPosition(string $file_path, Position $positio

$offset = $position->toOffset($file_contents);

list($reference_map, $type_map) = $this->analyzer->getMapsForFile($file_path);
[$reference_map, $type_map] = $this->analyzer->getMapsForFile($file_path);

if (!$reference_map && !$type_map) {
return null;
}

krsort($type_map);

foreach ($type_map as $start_pos => list($end_pos_excluding_whitespace, $possible_type)) {
foreach ($type_map as $start_pos => [$end_pos_excluding_whitespace, $possible_type]) {
if ($offset < $start_pos) {
continue;
}
Expand All @@ -1411,7 +1411,7 @@ public function getCompletionDataAtPosition(string $file_path, Position $positio
}
}

foreach ($reference_map as $start_pos => list($end_pos, $possible_reference)) {
foreach ($reference_map as $start_pos => [$end_pos, $possible_reference]) {
if ($offset < $start_pos || $possible_reference[0] !== '*') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/DocComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function parse($docblock, $line_number = null, $preserve_format =
if ($preserve_format) {
foreach ($lines as $m => $line) {
if (preg_match('/^\s?@([\w\-:]+)[\t ]*(.*)$/sm', $line, $matches)) {
list($full_match, $type, $data) = $matches;
[$full_match, $type, $data] = $matches;

$docblock = str_replace($full_match, '', $docblock);

Expand All @@ -121,7 +121,7 @@ public static function parse($docblock, $line_number = null, $preserve_format =
$docblock = preg_replace('/^\s?@([\w\-:]+)\s*([^\n]*)/m', '', $docblock);
/** @var string[] $match */
foreach ($matches as $m => $match) {
list($_, $type, $data) = $match;
[$_, $type, $data] = $match;

if (empty($special[$type])) {
$special[$type] = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public static function addContextProperties(

if (isset($storage->overridden_property_ids[$property_name])) {
foreach ($storage->overridden_property_ids[$property_name] as $overridden_property_id) {
list($guide_class_name) = explode('::$', $overridden_property_id);
[$guide_class_name] = explode('::$', $overridden_property_id);
$guide_class_storage = $codebase->classlike_storage_provider->get($guide_class_name);
$guide_property_storage = $guide_class_storage->properties[$property_name];

Expand Down Expand Up @@ -1226,7 +1226,7 @@ private function checkPropertyInitialization(
}

if ($codebase->diff_methods && $method_already_analyzed && $property->location) {
list($start, $end) = $property->location->getSelectionBounds();
[$start, $end] = $property->location->getSelectionBounds();

$existing_issues = $codebase->analyzer->getExistingIssuesForFile(
$this->getFilePath(),
Expand Down Expand Up @@ -1396,7 +1396,7 @@ function (FunctionLikeParameter $param) : PhpParser\Node\Arg {
);

foreach ($uninitialized_properties as $property_id => $property_storage) {
list(,$property_name) = explode('::$', $property_id);
[, $property_name] = explode('::$', $property_id);

if (!isset($method_context->vars_in_scope['$this->' . $property_name])) {
$end_type = Type::getVoid();
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public static function checkPropertyVisibility(
array $suppressed_issues,
$emit_issues = true
) {
list($fq_class_name, $property_name) = explode('::$', (string)$property_id);
[$fq_class_name, $property_name] = explode('::$', (string)$property_id);

$codebase = $source->getCodebase();

Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function (FunctionLikeParameter $p) {
}

if ($storage->signature_return_type && $storage->signature_return_type_location) {
list($start, $end) = $storage->signature_return_type_location->getSelectionBounds();
[$start, $end] = $storage->signature_return_type_location->getSelectionBounds();

$codebase->analyzer->addOffsetReference(
$this->getFilePath(),
Expand Down Expand Up @@ -951,7 +951,7 @@ private function checkParamReferences(

$unused_params = [];

foreach ($statements_analyzer->getUnusedVarLocations() as list($var_name, $original_location)) {
foreach ($statements_analyzer->getUnusedVarLocations() as [$var_name, $original_location]) {
if (!array_key_exists(substr($var_name, 1), $storage->param_lookup)) {
continue;
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ private function processParams(
$referenced_type = clone $referenced_type;
$referenced_type->removeType('null');
}
list($start, $end) = $signature_type_location->getSelectionBounds();
[$start, $end] = $signature_type_location->getSelectionBounds();
$codebase->analyzer->addOffsetReference(
$this->getFilePath(),
$start,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ public function setPhpVersion(string $version)
throw new \UnexpectedValueException('Expecting a version number in the format x.y');
}

list($php_major_version, $php_minor_version) = explode('.', $version);
[$php_major_version, $php_minor_version] = explode('.', $version);

$php_major_version = (int) $php_major_version;
$php_minor_version = (int) $php_minor_version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public static function analyze(
if (!$moved_class) {
foreach ($codebase->property_transforms as $original_pattern => $transformation) {
if ($declaring_property_id === $original_pattern) {
list($old_declaring_fq_class_name) = explode('::$', $declaring_property_id);
list($new_fq_class_name, $new_property_name) = explode('::$', $transformation);
[$old_declaring_fq_class_name] = explode('::$', $declaring_property_id);
[$new_fq_class_name, $new_property_name] = explode('::$', $transformation);

$file_manipulations = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public static function verifyType(
$has_valid_method = false;

foreach ($function_id_parts as $function_id_part) {
list($callable_fq_class_name, $method_name) = explode('::', $function_id_part);
[$callable_fq_class_name, $method_name] = explode('::', $function_id_part);

switch ($callable_fq_class_name) {
case 'self':
Expand Down Expand Up @@ -1212,7 +1212,7 @@ private static function processTaintedness(
);

if (strpos($cased_method_id, '::')) {
list($fq_classlike_name, $cased_method_name) = explode('::', $cased_method_id);
[$fq_classlike_name, $cased_method_name] = explode('::', $cased_method_id);
$method_name = strtolower($cased_method_name);
$class_storage = $codebase->classlike_storage_provider->get($fq_classlike_name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ private static function checkClosureType(
$function_id_parts = explode('&', $function_id);

foreach ($function_id_parts as $function_id_part) {
list($callable_fq_class_name, $method_name) = explode('::', $function_id_part);
[$callable_fq_class_name, $method_name] = explode('::', $function_id_part);

switch ($callable_fq_class_name) {
case 'self':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static function collect(
}

foreach ($template_types as $type_name => $type_map) {
foreach ($type_map as list($type)) {
foreach ($type_map as [$type]) {
foreach ($candidate_class_storages as $candidate_class_storage) {
if ($candidate_class_storage !== $static_class_storage
&& isset($e[$candidate_class_storage->name][$type_name])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function analyze(
$byref_uses = [];

if ($function_name instanceof PhpParser\Node\Expr) {
list($expr_function_exists, $expr_function_name, $expr_function_params, $byref_uses)
[$expr_function_exists, $expr_function_name, $expr_function_params, $byref_uses]
= self::getAnalyzeNamedExpression(
$statements_analyzer,
$codebase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public static function analyze(
}

if ($context->collect_initializations && $context->calling_method_id) {
list($calling_method_class) = explode('::', $context->calling_method_id);
[$calling_method_class] = explode('::', $context->calling_method_id);
$codebase->file_reference_provider->addMethodReferenceToClassMember(
$calling_method_class . '::__construct',
strtolower((string) $method_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
) {
$new_method_id = substr($transformation, 0, -4);
$old_declaring_fq_class_name = $declaring_method_id->fq_class_name;
list($new_fq_class_name, $new_method_name) = explode('::', $new_method_id);
[$new_fq_class_name, $new_method_name] = explode('::', $new_method_id);

if ($codebase->classlikes->handleClassLikeReferenceInMigration(
$codebase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static function getTemplateTypesForCall(
}
} elseif ($declaring_class_storage->template_types) {
foreach ($declaring_class_storage->template_types as $template_name => $type_map) {
foreach ($type_map as $key => list($type)) {
foreach ($type_map as $key => [$type]) {
$template_types[$template_name][$key] = [$type];
}
}
Expand Down Expand Up @@ -762,7 +762,7 @@ protected static function applyAssertionsToContext(

if ($type_assertions) {
foreach (($statements_analyzer->getTemplateTypeMap() ?: []) as $template_name => $map) {
foreach ($map as $ref => list($type)) {
foreach ($map as $ref => [$type]) {
$template_type_map[$template_name][$ref] = [
new Type\Union([
new Type\Atomic\TTemplateParam(
Expand Down Expand Up @@ -844,7 +844,7 @@ public static function checkTemplateResult(
) : void {
if ($template_result->upper_bounds && $template_result->lower_bounds) {
foreach ($template_result->lower_bounds as $template_name => $defining_map) {
foreach ($defining_map as $defining_id => list($lower_bound_type)) {
foreach ($defining_map as $defining_id => [$lower_bound_type]) {
if (isset($template_result->upper_bounds[$template_name][$defining_id])) {
$upper_bound_type = $template_result->upper_bounds[$template_name][$defining_id][0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static function analyze(
if ($codebase->alter_code && !$moved_class) {
foreach ($codebase->class_constant_transforms as $original_pattern => $transformation) {
if ($declaring_const_id === $original_pattern) {
list($new_fq_class_name, $new_const_name) = explode('::', $transformation);
[$new_fq_class_name, $new_const_name] = explode('::', $transformation);

$file_manipulations = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ public static function analyze(
if (!$moved_class) {
foreach ($codebase->property_transforms as $original_pattern => $transformation) {
if ($declaring_property_id === $original_pattern) {
list($old_declaring_fq_class_name) = explode('::$', $declaring_property_id);
list($new_fq_class_name, $new_property_name) = explode('::$', $transformation);
[$old_declaring_fq_class_name] = explode('::$', $declaring_property_id);
[$new_fq_class_name, $new_property_name] = explode('::$', $transformation);

$file_manipulations = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static function analyze(
);

if ($storage instanceof \Psalm\Storage\MethodStorage) {
list($fq_class_name, $method_name) = explode('::', $cased_method_id);
[$fq_class_name, $method_name] = explode('::', $cased_method_id);

$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ public function checkUnreferencedVars(array $stmts)

$unused_var_remover = new Statements\UnusedAssignmentRemover();

foreach ($this->unused_var_locations as $hash => list($var_id, $original_location)) {
foreach ($this->unused_var_locations as $hash => [$var_id, $original_location]) {
if (substr($var_id, 0, 2) === '$_' || isset($this->used_var_locations[$hash])) {
continue;
}
Expand Down

0 comments on commit 73f6fcd

Please sign in to comment.