Skip to content

Commit

Permalink
improve phpdoc (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Oct 17, 2020
1 parent 4614f4b commit ceaaa39
Show file tree
Hide file tree
Showing 58 changed files with 130 additions and 115 deletions.
22 changes: 13 additions & 9 deletions src/Psalm/Codebase.php
Expand Up @@ -527,7 +527,7 @@ public function createFileStorageForPath(string $file_path): FileStorage
}

/**
* @return \Psalm\CodeLocation[]
* @return array<int, CodeLocation>
*/
public function findReferencesToSymbol(string $symbol): array
{
Expand All @@ -547,15 +547,15 @@ public function findReferencesToSymbol(string $symbol): array
}

/**
* @return \Psalm\CodeLocation[]
* @return array<int, CodeLocation>
*/
public function findReferencesToMethod(string $method_id): array
{
return $this->file_reference_provider->getClassMethodLocations(strtolower($method_id));
}

/**
* @return \Psalm\CodeLocation[]
* @return array<int, CodeLocation>
*/
public function findReferencesToProperty(string $property_id): array
{
Expand All @@ -567,7 +567,9 @@ public function findReferencesToProperty(string $property_id): array
}

/**
* @return \Psalm\CodeLocation[]
* @return CodeLocation[]
*
* @psalm-return array<int, CodeLocation>
*/
public function findReferencesToClassLike(string $fq_class_name): array
{
Expand All @@ -581,7 +583,7 @@ public function findReferencesToClassLike(string $fq_class_name): array
return $locations;
}

public function getClosureStorage(string $file_path, string $closure_id): FunctionLikeStorage
public function getClosureStorage(string $file_path, string $closure_id): Storage\FunctionStorage
{
$file_storage = $this->file_storage_provider->get($file_path);

Expand Down Expand Up @@ -697,7 +699,7 @@ public function interfaceExtends(string $interface_name, string $possible_parent
}

/**
* @return array<string> all interfaces extended by $interface_name
* @return array<string, string> all interfaces extended by $interface_name
*/
public function getParentInterfaces(string $fq_interface_name): array
{
Expand Down Expand Up @@ -729,6 +731,8 @@ public function traitHasCorrectCase(string $fq_trait_name): bool
* a method, closure, or function.
*
* @param non-empty-string $function_id
*
* @return Storage\FunctionStorage|Storage\MethodStorage
*/
public function getFunctionLikeStorage(
StatementsAnalyzer $statements_analyzer,
Expand Down Expand Up @@ -857,7 +861,7 @@ public function getAppearingMethodId($method_id): ?string
/**
* @param string|\Psalm\Internal\MethodIdentifier $method_id
*
* @return array<string>
* @return array<string, Internal\MethodIdentifier>
*/
public function getOverriddenMethodIds($method_id): array
{
Expand Down Expand Up @@ -1285,7 +1289,7 @@ public function getCompletionDataAtPosition(string $file_path, Position $positio
}

/**
* @return array<int, \LanguageServerProtocol\CompletionItem>
* @return list<\LanguageServerProtocol\CompletionItem>
*/
public function getCompletionItemsForClassishThing(string $type_string, string $gap) : array
{
Expand Down Expand Up @@ -1376,7 +1380,7 @@ public function getCompletionItemsForClassishThing(string $type_string, string $
}

/**
* @return array<int, \LanguageServerProtocol\CompletionItem>
* @return list<\LanguageServerProtocol\CompletionItem>
*/
public function getCompletionItemsForPartialSymbol(
string $type_string,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Config.php
Expand Up @@ -1631,7 +1631,7 @@ public function useStrictTypesForFile(string $file_path): bool
}

/**
* @return array<string>
* @return array<int, string>
*/
public function getFileExtensions(): array
{
Expand Down
3 changes: 1 addition & 2 deletions src/Psalm/Config/IssueHandler.php
Expand Up @@ -130,8 +130,7 @@ public function getReportingLevelForVariable(string $var_name): ?string
}

/**
* @return string[]
* @psalm-return array<string>
* @return array<int, string>
*/
public static function getAllIssueTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Context.php
Expand Up @@ -475,7 +475,7 @@ public function getRedefinedVars(array $new_vars_in_scope, bool $include_new_var
}

/**
* @return array<int, string>
* @return list<string>
*/
public static function getNewOrUpdatedVarIds(Context $original_context, Context $new_context): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/ErrorBaseline.php
Expand Up @@ -66,7 +66,7 @@ public static function create(
}

/**
* @return array<string,array<string,array{o:int, s:array<int, string>}>>
* @return array<string,array<string,array{o:int, s: list<string>}>>
*
* @throws Exception\ConfigException
*/
Expand Down Expand Up @@ -124,7 +124,7 @@ public static function read(FileProvider $fileProvider, string $baselineFile): a
/**
* @param array<string, list<IssueData>> $issues
*
* @return array<string,array<string,array{o:int, s:array<int, string>}>>
* @return array<string, array<string, array{o: int, s: list<string>}>>
*
* @throws Exception\ConfigException
*/
Expand Down Expand Up @@ -286,8 +286,8 @@ function (string $extension) : string {
$xml = preg_replace_callback(
'/<files (psalm-version="[^"]+") (?:php-version="(.+)"(\/?>)\n)/',
/**
* @param array<int, string> $matches
*/
* @param array<int, string> $matches
*/
function (array $matches) : string {
return
'<files' .
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php
Expand Up @@ -25,8 +25,8 @@ class AlgebraAnalyzer
* if ($a) { }
* elseif ($a) { }
*
* @param array<int, Clause> $formula_1
* @param array<int, Clause> $formula_2
* @param list<Clause> $formula_1
* @param list<Clause> $formula_2
* @param array<string, bool> $new_assigned_var_ids
*/
public static function checkForParadox(
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Expand Up @@ -183,7 +183,7 @@ public function getMethodMutations(
}
}

public function getFunctionLikeAnalyzer(string $method_name) : ?FunctionLikeAnalyzer
public function getFunctionLikeAnalyzer(string $method_name) : ?MethodAnalyzer
{
foreach ($this->class->stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod &&
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Expand Up @@ -54,7 +54,7 @@ class CommentAnalyzer
*
* @throws DocblockParseException if there was a problem parsing the docblock
*
* @return VarDocblockComment[]
* @return list<VarDocblockComment>
*/
public static function getTypeFromComment(
PhpParser\Comment\Doc $comment,
Expand All @@ -79,7 +79,7 @@ public static function getTypeFromComment(
* @param array<string, array<string, array{Type\Union}>>|null $template_type_map
* @param array<string, TypeAlias> $type_aliases
*
* @return VarDocblockComment[]
* @return list<VarDocblockComment>
*
* @throws DocblockParseException if there was a problem parsing the docblock
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Analyzer/FileAnalyzer.php
Expand Up @@ -283,7 +283,7 @@ public function analyze(
/**
* @param array<int, PhpParser\Node\Stmt> $stmts
*
* @return array<int, PhpParser\Node\Stmt>
* @return list<PhpParser\Node\Stmt>
*/
public function populateCheckers(array $stmts): array
{
Expand Down Expand Up @@ -430,7 +430,7 @@ public function getMethodMutations(
}
}

public function getFunctionLikeAnalyzer(\Psalm\Internal\MethodIdentifier $method_id) : ?FunctionLikeAnalyzer
public function getFunctionLikeAnalyzer(\Psalm\Internal\MethodIdentifier $method_id) : ?MethodAnalyzer
{
$fq_class_name = $method_id->fq_class_name;
$method_name = $method_id->method_name;
Expand Down Expand Up @@ -536,15 +536,15 @@ public function hasAlreadyRequiredFilePath(string $file_path): bool
}

/**
* @return array<int, string>
* @return list<string>
*/
public function getRequiredFilePaths(): array
{
return array_keys($this->required_file_paths);
}

/**
* @return array<int, string>
* @return list<string>
*/
public function getParentFilePaths(): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -351,7 +351,7 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged() : void

/**
* @param array<string> $report_file_paths
* @return array<ReportOptions>
* @return list<ReportOptions>
*/
public static function getFileReportOptions(array $report_file_paths, bool $show_info = true): array
{
Expand Down Expand Up @@ -1019,7 +1019,7 @@ private function checkDirWithConfig(string $dir_name, Config $config, bool $allo
}

/**
* @return array<int, string>
* @return list<string>
*/
private function getAllFiles(Config $config): array
{
Expand Down Expand Up @@ -1051,7 +1051,7 @@ public function addExtraFile(string $file_path) : void
}

/**
* @return array<string>
* @return list<string>
*/
protected function getDiffFilesInDir(string $dir_name, Config $config): array
{
Expand Down Expand Up @@ -1472,7 +1472,7 @@ public static function getCpuCount(): int
}

/**
* @return array<string>
* @return array<int, string>
*
* @psalm-pure
*/
Expand Down
6 changes: 2 additions & 4 deletions src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php
Expand Up @@ -31,8 +31,6 @@ class LoopAnalyzer
* @param array<PhpParser\Node\Stmt> $stmts
* @param PhpParser\Node\Expr[] $pre_conditions
* @param PhpParser\Node\Expr[] $post_expressions
* @param Context loop_scope->loop_context
* @param Context $loop_scope->loop_parent_context
*
* @return false|null
*/
Expand Down Expand Up @@ -600,9 +598,9 @@ private static function updateLoopScopeContexts(
}

/**
* @param array<int, Clause> $pre_condition_clauses
* @param list<Clause> $pre_condition_clauses
*
* @return string[]
* @return list<string>
*/
private static function applyPreConditionToLoopContext(
StatementsAnalyzer $statements_analyzer,
Expand Down
Expand Up @@ -288,7 +288,7 @@ public static function analyze(
/**
* @param string $fq_catch_class
*/
function ($fq_catch_class) use ($codebase): Type\Atomic {
function ($fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject {
$catch_class_type = new TNamedObject($fq_catch_class);

if (version_compare(PHP_VERSION, '7.0.0dev', '>=')
Expand Down
Expand Up @@ -16,7 +16,7 @@ class AtomicCallContext
/** @var NodeDataProvider */
public $node_data;

/** @param array<int, PhpParser\Node\Arg> $args */
/** @param list<PhpParser\Node\Arg> $args */
public function __construct(MethodIdentifier $method_id, array $args, NodeDataProvider $node_data)
{
$this->method_id = $method_id;
Expand Down
Expand Up @@ -424,7 +424,7 @@ public static function getTemplateTypesForCall(
* @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat
* $callable_arg
*
* @return non-empty-string[]
* @return list<non-empty-string>
*
* @psalm-suppress LessSpecificReturnStatement
* @psalm-suppress MoreSpecificReturnType
Expand Down
5 changes: 4 additions & 1 deletion src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Expand Up @@ -308,7 +308,7 @@ private static function hoistConstants(
}

/**
* @psalm-return false|null
* @return false|null
*/
private static function analyzeStatement(
StatementsAnalyzer $statements_analyzer,
Expand Down Expand Up @@ -946,6 +946,9 @@ public function setFQCLN(string $fake_this_class) : void
$this->fake_this_class = $fake_this_class;
}

/**
* @return \Psalm\Internal\Provider\NodeDataProvider
*/
public function getNodeTypeProvider() : \Psalm\NodeTypeProvider
{
return $this->node_data;
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Internal/Codebase/Analyzer.php
Expand Up @@ -330,6 +330,9 @@ private function doAnalysis(ProjectAnalyzer $project_analyzer, int $pool_size) :
$filetype_analyzers = $this->config->getFiletypeAnalyzers();

$analysis_worker =
/**
* @return list<\Psalm\Internal\Analyzer\IssueData>
*/
function (int $_, string $file_path) use ($project_analyzer, $filetype_analyzers): array {
$file_analyzer = $this->getFileAnalyzer($project_analyzer, $file_path, $filetype_analyzers);

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/ClassLikes.php
Expand Up @@ -227,7 +227,7 @@ public function addFullyQualifiedClassLikeName(string $fq_class_name_lc, ?string
}

/**
* @return string[]
* @return list<string>
*/
public function getMatchingClassLikeNames(string $stub) : array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/InternalCallMapHandler.php
Expand Up @@ -215,7 +215,7 @@ public static function getMatchingCallableFromCallMapOptions(
}

/**
* @psalm-return array<int, TCallable>|null
* @return array<int, TCallable>|null
*/
public static function getCallablesFromCallMap(string $function_id): ?array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/Methods.php
Expand Up @@ -931,7 +931,7 @@ public function getAppearingMethodId(
}

/**
* @return array<MethodIdentifier>
* @return array<string, MethodIdentifier>
*/
public function getOverriddenMethodIds(MethodIdentifier $method_id): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Internal/Codebase/ReferenceMapGenerator.php
Expand Up @@ -3,6 +3,9 @@

class ReferenceMapGenerator
{
/**
* @return array<string, string>
*/
public static function getReferenceMap(
\Psalm\Internal\Provider\ClassLikeStorageProvider $classlike_storage_provider,
array $expected_references
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Codebase/TaintFlowGraph.php
Expand Up @@ -186,7 +186,7 @@ public function connectSinksAndSources() : void
/**
* @param array<string> $source_taints
* @param array<DataFlowNode> $sinks
* @return array<DataFlowNode>
* @return array<string, DataFlowNode>
*/
private function getChildNodes(
DataFlowNode $generated_source,
Expand Down Expand Up @@ -270,7 +270,7 @@ private function getChildNodes(
return $new_sources;
}

/** @return array<DataFlowNode> */
/** @return array<int, DataFlowNode> */
private function getSpecializedSources(DataFlowNode $source) : array
{
$generated_sources = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/VariableUseGraph.php
Expand Up @@ -47,7 +47,7 @@ public function isVariableUsed(DataFlowNode $assignment_node) : bool

/**
* @param array<string, bool> $visited_source_ids
* @return ?array<DataFlowNode>
* @return array<string, DataFlowNode>|null
*/
private function getChildNodes(
DataFlowNode $generated_source,
Expand Down

0 comments on commit ceaaa39

Please sign in to comment.