Skip to content

Commit

Permalink
cs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 3, 2022
1 parent 55e6804 commit 3857785
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 28 deletions.
Expand Up @@ -131,7 +131,10 @@ public static function checkArgumentsMatch(
$new []= $closure_type;
}

$statements_analyzer->node_data->setType($closure_arg->value, $closure_arg_type->getBuilder()->setTypes($new)->freeze());
$statements_analyzer->node_data->setType(
$closure_arg->value,
$closure_arg_type->getBuilder()->setTypes($new)->freeze()
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Psalm/Internal/Type/TypeExpander.php
Expand Up @@ -898,7 +898,10 @@ private static function expandPropertiesOf(
): array {
if ($self_class) {
$return_type = $return_type->replaceClassLike('self', $self_class);
$return_type = $return_type->replaceClassLike('static', is_string($static_class_type) ? $static_class_type : $self_class);
$return_type = $return_type->replaceClassLike(
'static',
is_string($static_class_type) ? $static_class_type : $self_class
);
}

$class_storage = null;
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Type/TypeParser.php
Expand Up @@ -705,7 +705,8 @@ private static function getTypeFromGenericTree(
}
if ($template_param->getIntersectionTypes()) {
throw new TypeParseTreeException(
$generic_type_value . '<' . $param_name . '> must be a TTemplateParam with no intersection types.'
$generic_type_value . '<' . $param_name . '> must be a TTemplateParam'
. ' with no intersection types.'
);
}

Expand Down
8 changes: 6 additions & 2 deletions src/Psalm/Type/Atomic/TAnonymousClassInstance.php
Expand Up @@ -16,8 +16,12 @@ final class TAnonymousClassInstance extends TNamedObject
* @param string $value the name of the object
* @param array<string, TNamedObject|TTemplateParam|TIterable|TObjectWithProperties> $extra_types
*/
public function __construct(string $value, bool $is_static = false, ?string $extends = null, array $extra_types = [])
{
public function __construct(
string $value,
bool $is_static = false,
?string $extends = null,
array $extra_types = []
) {
parent::__construct($value, $is_static, false, $extra_types);

$this->extends = $extends;
Expand Down
14 changes: 12 additions & 2 deletions src/Psalm/Type/Atomic/TArray.php
Expand Up @@ -115,8 +115,18 @@ public function replaceClassLike(string $old, string $new): self
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$type_params = $this->replaceTypeParamsTemplateTypesWithStandins(
$template_result,
$codebase,
Expand Down
27 changes: 24 additions & 3 deletions src/Psalm/Type/Atomic/TCallable.php
Expand Up @@ -55,9 +55,30 @@ public function replaceTemplateTypesWithArgTypes(TemplateResult $template_result
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
$replaced = $this->replaceCallableTemplateTypesWithStandins($template_result, $codebase, $statements_analyzer, $input_type, $input_arg_offset, $calling_class, $calling_function, $replace, $add_lower_bound, $depth);
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$replaced = $this->replaceCallableTemplateTypesWithStandins(
$template_result,
$codebase,
$statements_analyzer,
$input_type,
$input_arg_offset,
$calling_class,
$calling_function,
$replace,
$add_lower_bound,
$depth
);
if (!$replaced) {
return $this;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Psalm/Type/Atomic/TClassString.php
Expand Up @@ -42,8 +42,13 @@ class TClassString extends TString
/** @var bool */
public $is_enum = false;

public function __construct(string $as = 'object', ?TNamedObject $as_type = null, bool $is_loaded = false, bool $is_interface = false, bool $is_enum = false)
{
public function __construct(
string $as = 'object',
?TNamedObject $as_type = null,
bool $is_loaded = false,
bool $is_interface = false,
bool $is_enum = false
) {
$this->as = $as;
$this->as_type = $as_type;
$this->is_loaded = $is_loaded;
Expand Down
27 changes: 24 additions & 3 deletions src/Psalm/Type/Atomic/TClosure.php
Expand Up @@ -94,9 +94,30 @@ public function replaceTemplateTypesWithArgTypes(
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
$replaced = $this->replaceCallableTemplateTypesWithStandins($template_result, $codebase, $statements_analyzer, $input_type, $input_arg_offset, $calling_class, $calling_function, $replace, $add_lower_bound, $depth);
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$replaced = $this->replaceCallableTemplateTypesWithStandins(
$template_result,
$codebase,
$statements_analyzer,
$input_type,
$input_arg_offset,
$calling_class,
$calling_function,
$replace,
$add_lower_bound,
$depth
);
$intersection = $this->replaceIntersectionTemplateTypesWithStandins(
$template_result,
$codebase,
Expand Down
23 changes: 19 additions & 4 deletions src/Psalm/Type/Atomic/TGenericObject.php
Expand Up @@ -33,8 +33,13 @@ final class TGenericObject extends TNamedObject
* @param non-empty-list<Union> $type_params
* @param array<string, TNamedObject|TTemplateParam|TIterable|TObjectWithProperties> $extra_types
*/
public function __construct(string $value, array $type_params, bool $remapped_params = false, bool $is_static = false, array $extra_types = [])
{
public function __construct(
string $value,
array $type_params,
bool $remapped_params = false,
bool $is_static = false,
array $extra_types = []
) {
if ($value[0] === '\\') {
$value = substr($value, 1);
}
Expand Down Expand Up @@ -136,8 +141,18 @@ public function replaceClassLike(string $old, string $new): self
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$types = $this->replaceTypeParamsTemplateTypesWithStandins(
$template_result,
$codebase,
Expand Down
14 changes: 12 additions & 2 deletions src/Psalm/Type/Atomic/TIterable.php
Expand Up @@ -165,8 +165,18 @@ public function replaceTemplateTypesWithArgTypes(TemplateResult $template_result
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$types = $this->replaceTypeParamsTemplateTypesWithStandins(
$template_result,
$codebase,
Expand Down
22 changes: 18 additions & 4 deletions src/Psalm/Type/Atomic/TNamedObject.php
Expand Up @@ -42,8 +42,12 @@ class TNamedObject extends Atomic
* @param string $value the name of the object
* @param array<string, TNamedObject|TTemplateParam|TIterable|TObjectWithProperties> $extra_types
*/
public function __construct(string $value, bool $is_static = false, bool $definite_class = false, array $extra_types = [])
{
public function __construct(
string $value,
bool $is_static = false,
bool $definite_class = false,
array $extra_types = []
) {
if ($value[0] === '\\') {
$value = substr($value, 1);
}
Expand Down Expand Up @@ -175,8 +179,18 @@ public function replaceTemplateTypesWithArgTypes(
/**
* @return static
*/
public function replaceTemplateTypesWithStandins(TemplateResult $template_result, Codebase $codebase, ?StatementsAnalyzer $statements_analyzer = null, ?Atomic $input_type = null, ?int $input_arg_offset = null, ?string $calling_class = null, ?string $calling_function = null, bool $replace = true, bool $add_lower_bound = false, int $depth = 0): self
{
public function replaceTemplateTypesWithStandins(
TemplateResult $template_result,
Codebase $codebase,
?StatementsAnalyzer $statements_analyzer = null,
?Atomic $input_type = null,
?int $input_arg_offset = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_lower_bound = false,
int $depth = 0
): self {
$intersection = $this->replaceIntersectionTemplateTypesWithStandins(
$template_result,
$codebase,
Expand Down
8 changes: 6 additions & 2 deletions src/Psalm/Type/Atomic/TNonEmptyArray.php
Expand Up @@ -30,8 +30,12 @@ class TNonEmptyArray extends TArray
* @param positive-int|null $count
* @param positive-int|null $min_count
*/
public function __construct(array $type_params, ?int $count = null, ?int $min_count = null, string $value = 'non-empty-array')
{
public function __construct(
array $type_params,
?int $count = null,
?int $min_count = null,
string $value = 'non-empty-array'
) {
$this->type_params = $type_params;
$this->count = $count;
$this->min_count = $min_count;
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Type/Union.php
Expand Up @@ -238,5 +238,4 @@ public function replaceClassLike(string $old, string $new): self
}
return $types === $this->types ? $this : $this->getBuilder()->setTypes($types)->freeze();
}

}
1 change: 1 addition & 0 deletions tests/Internal/Codebase/InternalCallMapHandlerTest.php
Expand Up @@ -754,6 +754,7 @@ private function assertParameter(array $normalizedEntry, ReflectionParameter $pa
}
}

/** @psalm-suppress UndefinedMethod */
public function assertEntryReturnType(ReflectionFunction $function, string $entryReturnType): void
{
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
Expand Down

0 comments on commit 3857785

Please sign in to comment.