Documentation

Codebase
in package

FinalYes

Table of Contents

Properties

$all_constants_global  : bool
$all_functions_global  : bool
$allow_backwards_incompatible_changes  : bool
$alter_code  : bool
$analysis_php_version_id  : int
$analyzer  : Analyzer
$call_transforms  : array<lowercase-string, string>
$class_constant_transforms  : array<string, string>
$class_constants_to_move  : array<string, string>
$class_constants_to_rename  : array<string, string>
$class_transforms  : array<lowercase-string, string>
$classes_to_move  : array<lowercase-string, string>
$classlike_storage_provider  : ClassLikeStorageProvider
$classlikes  : ClassLikes
$collect_locations  : bool
$collect_references  : bool
$config  : Config
$diff_methods  : bool
$diff_run  : bool
whether or not we only checked a part of the codebase
$file_provider  : FileProvider
$file_reference_provider  : FileReferenceProvider
$file_storage_provider  : FileStorageProvider
$find_unused_code  : null|"always"|"auto"
$find_unused_variables  : bool
$functions  : Functions
$infer_types_from_usage  : bool
Whether or not to infer types from usage. Computationally expensive, so turned off by default
$literal_array_key_check  : bool
$methods  : Methods
$methods_to_move  : array<lowercase-string, string>
$methods_to_rename  : array<lowercase-string, string>
$php_version_source  : "cli"|"config"|"composer"|"tests"|"runtime"
$populator  : Populator
$properties  : Properties
$properties_to_move  : array<string, string>
$properties_to_rename  : array<string, string>
$property_transforms  : array<string, string>
$register_autoload_files  : bool
Whether to register autoloaded information
$register_stub_files  : bool
Whether to log functions just at the file level or globally (for stubs)
$scanner  : Scanner
$server_mode  : bool
$statements_provider  : StatementsProvider
$store_node_types  : bool
$taint_flow_graph  : TaintFlowGraph|null
$track_unused_suppressions  : bool
$use_referencing_locations  : array<lowercase-string, array<int, CodeLocation>>
A map of fully-qualified use declarations to the files that reference them (keyed by filename)
$progress  : Progress
$stubbed_constants  : array<string, Union>

Methods

addFilesToAnalyze()  : void
addGlobalConstantType()  : void
addGlobalConstantTypes()  : void
addTaintSink()  : void
addTaintSource()  : Union
addTemporaryFileChanges()  : void
cacheClassLikeStorage()  : void
canTypeBeContainedByType()  : bool
Checks if type has any part that is a subtype of other
classExists()  : bool
Determine whether or not a given class exists
classExtends()  : bool
Determine whether or not a class extends a parent
classExtendsOrImplements()  : bool
classHasCorrectCasing()  : bool
Determine whether or not a class has the correct casing
classImplements()  : bool
Check whether a class implements an interface
classOrInterfaceExists()  : bool
Check whether a class/interface exists
classOrInterfaceOrEnumExists()  : bool
Check whether a class/interface exists
collectLocations()  : void
createClassLikeStorage()  : ClassLikeStorage
createFileStorageForPath()  : FileStorage
enterServerMode()  : void
exhumeClassLikeStorage()  : void
fileExists()  : bool
filterCompletionItemsByBeginLiteralPart()  : array<int, CompletionItem>
findReferencesToClassLike()  : array<string|int, CodeLocation>
findReferencesToMethod()  : array<int, CodeLocation>
findReferencesToProperty()  : array<int, CodeLocation>
findReferencesToSymbol()  : array<int, CodeLocation>
getAllStubbedConstants()  : array<string, Union>
getAppearingMethodId()  : string|null
Get the class this method appears in (vs is declared in, which could give a trait)
getBeginedLiteralPart()  : string
getCasedMethodId()  : string
getClosureStorage()  : FunctionStorage
getCompletionDataAtPosition()  : array{0: string, 1: "->"|"::"|"["|"symbol", 2: int}|null
getCompletionItemsForArrayKeys()  : array<int, CompletionItem>
getCompletionItemsForClassishThing()  : array<int, CompletionItem>
getCompletionItemsForPartialSymbol()  : array<int, CompletionItem>
getCompletionItemsForType()  : array<int, CompletionItem>
getDeclaringMethodId()  : string|null
getFileContents()  : string
getFunctionArgumentAtPosition()  : Range}|null
getFunctionLikeStorage()  : FunctionStorage|MethodStorage
Given a function id, return the function like storage for a method, closure, or function.
getFunctionStorageForSymbol()  : FunctionLikeStorage|null
getKeyValueParamsForTraversableObject()  : Union}
Extracts key and value types from a traversable object (or iterable)
getMajorAnalysisPhpVersion()  : int
getMarkupContentForSymbolByReference()  : PHPMarkdownContent|null
Get Markup content from Reference
getMethodParams()  : array<int, FunctionLikeParameter>
getMethodReturnsByRef()  : bool
getMethodReturnType()  : Union|null
getMethodReturnTypeLocation()  : CodeLocation|null
getMinorAnalysisPhpVersion()  : int
getOverriddenMethodIds()  : array<string, MethodIdentifier>
getParentInterfaces()  : array<string, string>
getPsalmTypeFromReflection()  : Union
getReferenceAtPosition()  : Range}|null
getReferenceAtPositionAsReference()  : Reference|null
Get Reference from Position
getSignatureInformation()  : SignatureInformation|null
getStatementsForFile()  : array<int, Stmt>
getStubbedConstantType()  : Union|null
getSymbolLocationByReference()  : CodeLocation|null
getTypeContextAtPosition()  : Union|null
interfaceExists()  : bool
interfaceExtends()  : bool
interfaceHasCorrectCasing()  : bool
invalidateInformationForFile()  : void
isTypeContainedByType()  : bool
Checks if type is a subtype of other
isVariadic()  : bool
methodExists()  : bool
Whether or not a given method exists
queueClassLikeForScanning()  : void
reloadFiles()  : void
removeTemporaryFileChanges()  : void
reportUnusedCode()  : void
reportUnusedVariables()  : void
scanFiles()  : void
Scans all files their related files
traitHasCorrectCasing()  : bool
transformPhpVersionId()  : int
getPositionFromOffset()  : Position
loadAnalyzer()  : void

Properties

$all_constants_global

public bool $all_constants_global = false

$all_functions_global

public bool $all_functions_global = false

$allow_backwards_incompatible_changes

public bool $allow_backwards_incompatible_changes = true

$alter_code

public bool $alter_code = false

$analysis_php_version_id

public int $analysis_php_version_id = \PHP_VERSION_ID

$call_transforms

public array<lowercase-string, string> $call_transforms = []

$class_constant_transforms

public array<string, string> $class_constant_transforms = []

$class_constants_to_move

public array<string, string> $class_constants_to_move = []

$class_constants_to_rename

public array<string, string> $class_constants_to_rename = []

$class_transforms

public array<lowercase-string, string> $class_transforms = []

$classes_to_move

public array<lowercase-string, string> $classes_to_move = []

$classlike_storage_provider

public ClassLikeStorageProvider $classlike_storage_provider

$classlikes

public ClassLikes $classlikes

$collect_locations

public bool $collect_locations = false

$collect_references

public bool $collect_references = false

$diff_methods

public bool $diff_methods = false

$diff_run

whether or not we only checked a part of the codebase

public bool $diff_run = false

$file_provider

public FileProvider $file_provider

$file_reference_provider

public FileReferenceProvider $file_reference_provider

$file_storage_provider

public FileStorageProvider $file_storage_provider

$find_unused_code

public null|"always"|"auto" $find_unused_code = null

$find_unused_variables

public bool $find_unused_variables = false

$infer_types_from_usage

Whether or not to infer types from usage. Computationally expensive, so turned off by default

public bool $infer_types_from_usage = false

$literal_array_key_check

public bool $literal_array_key_check = false

$methods_to_move

public array<lowercase-string, string> $methods_to_move = []

$methods_to_rename

public array<lowercase-string, string> $methods_to_rename = []

$php_version_source

public "cli"|"config"|"composer"|"tests"|"runtime" $php_version_source = 'runtime'

$properties

public Properties $properties

$properties_to_move

public array<string, string> $properties_to_move = []

$properties_to_rename

public array<string, string> $properties_to_rename = []

$property_transforms

public array<string, string> $property_transforms = []

$register_autoload_files

Whether to register autoloaded information

public bool $register_autoload_files = false

$register_stub_files

Whether to log functions just at the file level or globally (for stubs)

public bool $register_stub_files = false

$server_mode

public bool $server_mode = false

$statements_provider

public StatementsProvider $statements_provider

$store_node_types

public bool $store_node_types = false

$taint_flow_graph

public TaintFlowGraph|null $taint_flow_graph = null

$track_unused_suppressions

public bool $track_unused_suppressions = false

$use_referencing_locations

A map of fully-qualified use declarations to the files that reference them (keyed by filename)

public array<lowercase-string, array<int, CodeLocation>> $use_referencing_locations = []

$stubbed_constants

private static array<string, Union> $stubbed_constants = []

Methods

addFilesToAnalyze()

public addFilesToAnalyze(array<string, string> $files_to_analyze) : void
Parameters
$files_to_analyze : array<string, string>

addGlobalConstantType()

public addGlobalConstantType(string $const_id, Union $type) : void
Parameters
$const_id : string
$type : Union

addGlobalConstantTypes()

public addGlobalConstantTypes(array<string, Union$stubs) : void
Parameters
$stubs : array<string, Union>

addTemporaryFileChanges()

public addTemporaryFileChanges(string $file_path, string $new_content[, int|null $version = null ]) : void
Parameters
$file_path : string
$new_content : string
$version : int|null = null

canTypeBeContainedByType()

Checks if type has any part that is a subtype of other

public canTypeBeContainedByType(Union $input_type, Union $container_type) : bool

Given two types, checks if any part of $input_type is a subtype of $container_type. If you consider Union as a set of types, this will tell you if intersection of $input_type with $container_type is not empty.

$input_type ∩ $container_type ≠ ∅ , e.g. they are not disjoint.

Useful for emitting issues like PossiblyInvalidArgument, where argument at the call site should be a subtype of the function parameter type, but it's has some types that are not a subtype of the required type.

Parameters
$input_type : Union
$container_type : Union
Return values
bool

classExists()

Determine whether or not a given class exists

public classExists(string $fq_class_name[, CodeLocation|null $code_location = null ][, string|null $calling_fq_class_name = null ][, string|null $calling_method_id = null ]) : bool
Parameters
$fq_class_name : string
$code_location : CodeLocation|null = null
$calling_fq_class_name : string|null = null
$calling_method_id : string|null = null
Return values
bool

classExtends()

Determine whether or not a class extends a parent

public classExtends(string $fq_class_name, string $possible_parent) : bool
Parameters
$fq_class_name : string
$possible_parent : string
Tags
throws
UnpopulatedClasslikeException

when called on unpopulated class

throws
InvalidArgumentException

when class does not exist

Return values
bool

classExtendsOrImplements()

public classExtendsOrImplements(string $fq_class_name, string $possible_parent) : bool
Parameters
$fq_class_name : string
$possible_parent : string
Tags
psalm-mutation-free
Return values
bool

classHasCorrectCasing()

Determine whether or not a class has the correct casing

public classHasCorrectCasing(string $fq_class_name) : bool
Parameters
$fq_class_name : string
Return values
bool

classImplements()

Check whether a class implements an interface

public classImplements(string $fq_class_name, string $interface) : bool
Parameters
$fq_class_name : string
$interface : string
Return values
bool

classOrInterfaceExists()

Check whether a class/interface exists

public classOrInterfaceExists(string $fq_class_name[, CodeLocation|null $code_location = null ][, string|null $calling_fq_class_name = null ][, string|null $calling_method_id = null ]) : bool
Parameters
$fq_class_name : string
$code_location : CodeLocation|null = null
$calling_fq_class_name : string|null = null
$calling_method_id : string|null = null
Return values
bool

classOrInterfaceOrEnumExists()

Check whether a class/interface exists

public classOrInterfaceOrEnumExists(string $fq_class_name[, CodeLocation|null $code_location = null ][, string|null $calling_fq_class_name = null ][, string|null $calling_method_id = null ]) : bool
Parameters
$fq_class_name : string
$code_location : CodeLocation|null = null
$calling_fq_class_name : string|null = null
$calling_method_id : string|null = null
Tags
psalm-assert-if-true

class-string|interface-string|enum-string $fq_class_name

Return values
bool

collectLocations()

public collectLocations() : void

createFileStorageForPath()

public createFileStorageForPath(string $file_path) : FileStorage
Parameters
$file_path : string
Return values
FileStorage

enterServerMode()

public enterServerMode() : void

exhumeClassLikeStorage()

public exhumeClassLikeStorage(string $fq_classlike_name, string $file_path) : void
Parameters
$fq_classlike_name : string
$file_path : string

fileExists()

public fileExists(string $file_path) : bool
Parameters
$file_path : string
Return values
bool

filterCompletionItemsByBeginLiteralPart()

public filterCompletionItemsByBeginLiteralPart(array<int, CompletionItem$items, string $literal_part) : array<int, CompletionItem>
APIYes

to be removed in Psalm 6

Parameters
$items : array<int, CompletionItem>
$literal_part : string
Return values
array<int, CompletionItem>

findReferencesToClassLike()

public findReferencesToClassLike(string $fq_class_name) : array<string|int, CodeLocation>
Parameters
$fq_class_name : string
Tags
psalm-return

array<int, CodeLocation>

Return values
array<string|int, CodeLocation>

findReferencesToMethod()

public findReferencesToMethod(string $method_id) : array<int, CodeLocation>
Parameters
$method_id : string
Return values
array<int, CodeLocation>

findReferencesToProperty()

public findReferencesToProperty(string $property_id) : array<int, CodeLocation>
Parameters
$property_id : string
Return values
array<int, CodeLocation>

findReferencesToSymbol()

public findReferencesToSymbol(string $symbol) : array<int, CodeLocation>
Parameters
$symbol : string
Return values
array<int, CodeLocation>

getAllStubbedConstants()

public getAllStubbedConstants() : array<string, Union>
Return values
array<string, Union>

getAppearingMethodId()

Get the class this method appears in (vs is declared in, which could give a trait)

public getAppearingMethodId(string|MethodIdentifier $method_id) : string|null
Parameters
$method_id : string|MethodIdentifier
Return values
string|null

getBeginedLiteralPart()

public getBeginedLiteralPart(string $file_path, Position $position) : string
Parameters
$file_path : string
$position : Position
Return values
string

getCasedMethodId()

public getCasedMethodId(string|MethodIdentifier $method_id) : string
Parameters
$method_id : string|MethodIdentifier
Return values
string

getCompletionDataAtPosition()

public getCompletionDataAtPosition(string $file_path, Position $position) : array{0: string, 1: "->"|"::"|"["|"symbol", 2: int}|null
Parameters
$file_path : string
$position : Position
Return values
array{0: string, 1: "->"|"::"|"["|"symbol", 2: int}|null

getCompletionItemsForArrayKeys()

public getCompletionItemsForArrayKeys(string $type_string) : array<int, CompletionItem>
Parameters
$type_string : string
Return values
array<int, CompletionItem>

getCompletionItemsForClassishThing()

public getCompletionItemsForClassishThing(string $type_string, string $gap[, bool $snippets_supported = false ][, array<int, int> $allow_visibilities = null ][, array<int, string> $ignore_fq_class_names = [] ]) : array<int, CompletionItem>
Parameters
$type_string : string
$gap : string
$snippets_supported : bool = false
$allow_visibilities : array<int, int> = null
$ignore_fq_class_names : array<int, string> = []
Return values
array<int, CompletionItem>

getCompletionItemsForPartialSymbol()

public getCompletionItemsForPartialSymbol(string $type_string, int $offset, string $file_path) : array<int, CompletionItem>
Parameters
$type_string : string
$offset : int
$file_path : string
Return values
array<int, CompletionItem>

getDeclaringMethodId()

public getDeclaringMethodId(string|MethodIdentifier $method_id) : string|null
Parameters
$method_id : string|MethodIdentifier
Return values
string|null

getFileContents()

public getFileContents(string $file_path) : string
Parameters
$file_path : string
Return values
string

getFunctionArgumentAtPosition()

public getFunctionArgumentAtPosition(string $file_path, Position $position) : Range}|null
Parameters
$file_path : string
$position : Position
Return values
Range}|null

getFunctionLikeStorage()

Given a function id, return the function like storage for a method, closure, or function.

public getFunctionLikeStorage(StatementsAnalyzer $statements_analyzer, non-empty-string $function_id) : FunctionStorage|MethodStorage
Parameters
$statements_analyzer : StatementsAnalyzer
$function_id : non-empty-string
Return values
FunctionStorage|MethodStorage

getKeyValueParamsForTraversableObject()

Extracts key and value types from a traversable object (or iterable)

public getKeyValueParamsForTraversableObject(Atomic $type) : Union}

Given an iterable type (but not TArray) returns a tuple of it's key/value types. First element of the tuple holds key type, second has the value type.

Example:

$codebase->getKeyValueParamsForTraversableObject(Type::parseString('iterable<int,string>'))
//  returns [Union(TInt), Union(TString)]
Parameters
$type : Atomic
Return values
Union}

getMajorAnalysisPhpVersion()

public getMajorAnalysisPhpVersion() : int
Return values
int

getMarkupContentForSymbolByReference()

Get Markup content from Reference

public getMarkupContentForSymbolByReference(Reference $reference) : PHPMarkdownContent|null
Parameters
$reference : Reference
Return values
PHPMarkdownContent|null

getMethodReturnsByRef()

public getMethodReturnsByRef(string|MethodIdentifier $method_id) : bool
Parameters
$method_id : string|MethodIdentifier
Return values
bool

getMethodReturnType()

public getMethodReturnType(string|MethodIdentifier $method_id, string|null &$self_class[, array<int, Arg$call_args = [] ]) : Union|null
Parameters
$method_id : string|MethodIdentifier
$self_class : string|null
$call_args : array<int, Arg> = []
Return values
Union|null

getMethodReturnTypeLocation()

public getMethodReturnTypeLocation(string|MethodIdentifier $method_id[, CodeLocation|null &$defined_location = null ]) : CodeLocation|null
Parameters
$method_id : string|MethodIdentifier
$defined_location : CodeLocation|null = null
Return values
CodeLocation|null

getMinorAnalysisPhpVersion()

public getMinorAnalysisPhpVersion() : int
Return values
int

getOverriddenMethodIds()

public getOverriddenMethodIds(string|MethodIdentifier $method_id) : array<string, MethodIdentifier>
Parameters
$method_id : string|MethodIdentifier
Return values
array<string, MethodIdentifier>

getParentInterfaces()

public getParentInterfaces(string $fq_interface_name) : array<string, string>
Parameters
$fq_interface_name : string
Return values
array<string, string>

all interfaces extended by $interface_name

getPsalmTypeFromReflection()

public static getPsalmTypeFromReflection(ReflectionType|null $type) : Union
Parameters
$type : ReflectionType|null
Return values
Union

getReferenceAtPosition()

public getReferenceAtPosition(string $file_path, Position $position) : Range}|null
Parameters
$file_path : string
$position : Position
Return values
Range}|null

getReferenceAtPositionAsReference()

Get Reference from Position

public getReferenceAtPositionAsReference(string $file_path, Position $position) : Reference|null
Parameters
$file_path : string
$position : Position
Return values
Reference|null

getSignatureInformation()

public getSignatureInformation(non-empty-string $function_symbol[, string|null $file_path = null ]) : SignatureInformation|null
Parameters
$function_symbol : non-empty-string
$file_path : string|null = null
Return values
SignatureInformation|null

getStatementsForFile()

public getStatementsForFile(string $file_path) : array<int, Stmt>
Parameters
$file_path : string
Return values
array<int, Stmt>

getStubbedConstantType()

public getStubbedConstantType(string $const_id) : Union|null
Parameters
$const_id : string
Return values
Union|null

getSymbolLocationByReference()

public getSymbolLocationByReference(Reference $reference) : CodeLocation|null
Parameters
$reference : Reference
Return values
CodeLocation|null

getTypeContextAtPosition()

public getTypeContextAtPosition(string $file_path, Position $position) : Union|null
Parameters
$file_path : string
$position : Position
Return values
Union|null

interfaceExists()

public interfaceExists(string $fq_interface_name[, CodeLocation|null $code_location = null ][, string|null $calling_fq_class_name = null ][, string|null $calling_method_id = null ]) : bool
Parameters
$fq_interface_name : string
$code_location : CodeLocation|null = null
$calling_fq_class_name : string|null = null
$calling_method_id : string|null = null
Return values
bool

interfaceExtends()

public interfaceExtends(string $interface_name, string $possible_parent) : bool
Parameters
$interface_name : string
$possible_parent : string
Return values
bool

interfaceHasCorrectCasing()

public interfaceHasCorrectCasing(string $fq_interface_name) : bool
Parameters
$fq_interface_name : string
Return values
bool

invalidateInformationForFile()

public invalidateInformationForFile(string $file_path) : void
Parameters
$file_path : string

isTypeContainedByType()

Checks if type is a subtype of other

public isTypeContainedByType(Union $input_type, Union $container_type[, bool $ignore_null = false ][, bool $ignore_false = false ][, bool $allow_interface_equality = false ][, bool $allow_float_int_equality = true ]) : bool

Given two types, checks if $input_type is a subtype of $container_type. If you consider Union as a set of types, this will tell you if $input_type is fully contained in $container_type,

$input_type ⊆ $container_type

Useful for emitting issues like InvalidArgument, where argument at the call site should be a subset of the function parameter type.

Parameters
$input_type : Union
$container_type : Union
$ignore_null : bool = false
$ignore_false : bool = false
$allow_interface_equality : bool = false
$allow_float_int_equality : bool = true
Return values
bool

isVariadic()

public isVariadic(string|MethodIdentifier $method_id) : bool
Parameters
$method_id : string|MethodIdentifier
Return values
bool

methodExists()

Whether or not a given method exists

public methodExists(string|MethodIdentifier $method_id[, CodeLocation|null $code_location = null ][, string|MethodIdentifier|null $calling_method_id = null ][, string|null $file_path = null ][, bool $is_used = true ]) : bool
Parameters
$method_id : string|MethodIdentifier
$code_location : CodeLocation|null = null
$calling_method_id : string|MethodIdentifier|null = null
$file_path : string|null = null
$is_used : bool = true
Return values
bool

queueClassLikeForScanning()

public queueClassLikeForScanning(string $fq_classlike_name[, bool $analyze_too = false ][, bool $store_failure = true ][, array<string, mixed> $phantom_classes = [] ]) : void
Parameters
$fq_classlike_name : string
$analyze_too : bool = false
$store_failure : bool = true
$phantom_classes : array<string, mixed> = []

reloadFiles()

public reloadFiles(ProjectAnalyzer $project_analyzer, array<string|int, string> $candidate_files[, bool $force = false ]) : void
Parameters
$project_analyzer : ProjectAnalyzer
$candidate_files : array<string|int, string>
$force : bool = false

removeTemporaryFileChanges()

public removeTemporaryFileChanges(string $file_path) : void
Parameters
$file_path : string

reportUnusedCode()

public reportUnusedCode(["always"|"auto" $find_unused_code = 'auto' ]) : void
Parameters
$find_unused_code : "always"|"auto" = 'auto'

reportUnusedVariables()

public reportUnusedVariables() : void

scanFiles()

Scans all files their related files

public scanFiles([int $threads = 1 ]) : void
Parameters
$threads : int = 1

traitHasCorrectCasing()

public traitHasCorrectCasing(string $fq_trait_name) : bool
Parameters
$fq_trait_name : string
Return values
bool

transformPhpVersionId()

public static transformPhpVersionId(int $php_version_id, int $div) : int
Parameters
$php_version_id : int
$div : int
Return values
int

getPositionFromOffset()

private static getPositionFromOffset(int $offset, string $file_contents) : Position
Parameters
$offset : int
$file_contents : string
Return values
Position

loadAnalyzer()

private loadAnalyzer() : void

        
On this page

Search results