Skip to content

Commit

Permalink
Merge pull request #9406 from edsrzf/atomic-constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Mar 12, 2023
2 parents 47c4821 + 47f792e commit 902a019
Show file tree
Hide file tree
Showing 37 changed files with 78 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/CallableTrait.php
Expand Up @@ -38,6 +38,7 @@ trait CallableTrait
* Constructs a new instance of a generic type
*
* @param list<FunctionLikeParameter> $params
* @deprecated
*/
public function __construct(
string $value = 'callable',
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TArray.php
Expand Up @@ -41,7 +41,7 @@ class TArray extends Atomic
public function __construct(array $type_params, bool $from_docblock = false)
{
$this->type_params = $type_params;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
21 changes: 21 additions & 0 deletions src/Psalm/Type/Atomic/TCallable.php
Expand Up @@ -5,7 +5,9 @@
use Psalm\Codebase;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\Type\TemplateResult;
use Psalm\Storage\FunctionLikeParameter;
use Psalm\Type\Atomic;
use Psalm\Type\Union;

/**
* Denotes the `callable` type. Can result from an `is_callable` check.
Expand All @@ -21,6 +23,25 @@ final class TCallable extends Atomic
*/
public $value;

/**
* Constructs a new instance of a generic type
*
* @param list<FunctionLikeParameter> $params
*/
public function __construct(
string $value = 'callable',
?array $params = null,
?Union $return_type = null,
?bool $is_pure = null,
bool $from_docblock = false
) {
$this->value = $value;
$this->params = $params;
$this->return_type = $return_type;
$this->is_pure = $is_pure;
parent::__construct($from_docblock);
}

/**
* @param array<lowercase-string, string> $aliased_classes
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TClassConstant.php
Expand Up @@ -22,7 +22,7 @@ public function __construct(string $fq_classlike_name, string $const_name, bool
{
$this->fq_classlike_name = $fq_classlike_name;
$this->const_name = $const_name;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TClassString.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(
$this->is_loaded = $is_loaded;
$this->is_interface = $is_interface;
$this->is_enum = $is_enum;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}
/**
* @return static
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TClassStringMap.php
Expand Up @@ -46,7 +46,7 @@ public function __construct(
$this->param_name = $param_name;
$this->as_type = $as_type;
$this->value_param = $value_param;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getId(bool $exact = true, bool $nested = false): string
Expand Down
10 changes: 7 additions & 3 deletions src/Psalm/Type/Atomic/TClosure.php
Expand Up @@ -37,13 +37,17 @@ public function __construct(
array $extra_types = [],
bool $from_docblock = false
) {
$this->value = $value;
$this->params = $params;
$this->return_type = $return_type;
$this->is_pure = $is_pure;
$this->byref_uses = $byref_uses;
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;
parent::__construct(
$value,
false,
false,
$extra_types,
$from_docblock,
);
}

public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TConditional.php
Expand Up @@ -60,7 +60,7 @@ public function __construct(
$this->conditional_type = $conditional_type;
$this->if_type = $if_type;
$this->else_type = $else_type;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function setTypes(
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/TDependentGetClass.php
Expand Up @@ -30,6 +30,7 @@ public function __construct(string $typeof, Union $as_type)
{
$this->typeof = $typeof;
$this->as_type = $as_type;
parent::__construct(false);
}

public function getId(bool $exact = true, bool $nested = false): string
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/TDependentGetDebugType.php
Expand Up @@ -22,6 +22,7 @@ final class TDependentGetDebugType extends TString implements DependentType
public function __construct(string $typeof)
{
$this->typeof = $typeof;
parent::__construct(false);
}

public function getKey(bool $include_extra = true): string
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/TDependentGetType.php
Expand Up @@ -22,6 +22,7 @@ final class TDependentGetType extends TString
public function __construct(string $typeof)
{
$this->typeof = $typeof;
parent::__construct(false);
}

public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/TDependentListKey.php
Expand Up @@ -23,6 +23,7 @@ final class TDependentListKey extends TInt implements DependentType
public function __construct(string $var_id)
{
$this->var_id = $var_id;
parent::__construct(false);
}

public function getId(bool $exact = true, bool $nested = false): string
Expand Down
11 changes: 7 additions & 4 deletions src/Psalm/Type/Atomic/TGenericObject.php
Expand Up @@ -51,12 +51,15 @@ public function __construct(
$value = substr($value, 1);
}

$this->value = $value;
$this->type_params = $type_params;
$this->remapped_params = $remapped_params;
$this->is_static = $is_static;
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;
parent::__construct(
$value,
$is_static,
false,
$extra_types,
$from_docblock,
);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TIntMask.php
Expand Up @@ -19,7 +19,7 @@ final class TIntMask extends TInt
public function __construct(array $values, bool $from_docblock = false)
{
$this->values = $values;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TIntMaskOf.php
Expand Up @@ -22,7 +22,7 @@ final class TIntMaskOf extends TInt
public function __construct(Atomic $value, bool $from_docblock = false)
{
$this->value = $value;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TIntRange.php
Expand Up @@ -35,8 +35,8 @@ public function __construct(
) {
$this->min_bound = $min_bound;
$this->max_bound = $max_bound;
$this->from_docblock = $from_docblock;
$this->dependent_list_key = $dependent_list_key;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TIterable.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(array $type_params = [], array $extra_types = [], bo
$this->type_params = [Type::getMixed(), Type::getMixed()];
}
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TKeyOf.php
Expand Up @@ -21,7 +21,7 @@ final class TKeyOf extends TArrayKey
public function __construct(Union $type, bool $from_docblock = false)
{
$this->type = $type;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TKeyedArray.php
Expand Up @@ -84,7 +84,6 @@ public function __construct(
$this->class_strings = $class_strings;
$this->fallback_params = $fallback_params;
$this->is_list = $is_list;
$this->from_docblock = $from_docblock;
if ($this->is_list) {
$last_k = -1;
$had_possibly_undefined = false;
Expand All @@ -100,6 +99,7 @@ public function __construct(
$last_k = $k;
}
}
parent::__construct($from_docblock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TList.php
Expand Up @@ -42,7 +42,7 @@ class TList extends Atomic
public function __construct(Union $type_param, bool $from_docblock = false)
{
$this->type_param = $type_param;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TLiteralFloat.php
Expand Up @@ -15,7 +15,7 @@ final class TLiteralFloat extends TFloat
public function __construct(float $value, bool $from_docblock = false)
{
$this->value = $value;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TLiteralInt.php
Expand Up @@ -15,7 +15,7 @@ final class TLiteralInt extends TInt
public function __construct(int $value, bool $from_docblock = false)
{
$this->value = $value;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TLiteralString.php
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $value, bool $from_docblock = false)
);
}
$this->value = $value;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TMixed.php
Expand Up @@ -17,7 +17,7 @@ class TMixed extends Atomic
public function __construct(bool $from_loop_isset = false, bool $from_docblock = false)
{
$this->from_loop_isset = $from_loop_isset;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TNamedObject.php
Expand Up @@ -63,7 +63,7 @@ public function __construct(
$this->is_static = $is_static;
$this->definite_class = $definite_class;
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Psalm/Type/Atomic/TNonEmptyArray.php
Expand Up @@ -39,11 +39,10 @@ public function __construct(
string $value = 'non-empty-array',
bool $from_docblock = false
) {
$this->type_params = $type_params;
$this->count = $count;
$this->min_count = $min_count;
$this->value = $value;
$this->from_docblock = $from_docblock;
parent::__construct($type_params, $from_docblock);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type/Atomic/TNonEmptyList.php
Expand Up @@ -44,10 +44,10 @@ public function __construct(
?int $min_count = null,
bool $from_docblock = false
) {
$this->type_param = $type_param;
$this->count = $count;
$this->min_count = $min_count;
$this->from_docblock = $from_docblock;
/** @psalm-suppress DeprecatedClass */
parent::__construct($type_param, $from_docblock);
}

public function getKeyedArray(): TKeyedArray
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/Type/Atomic/TObjectWithProperties.php
Expand Up @@ -53,10 +53,11 @@ public function __construct(
$this->properties = $properties;
$this->methods = $methods;
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;

$this->is_stringable_object_only =
$this->properties === [] && $this->methods === ['__tostring' => 'string'];

parent::__construct($from_docblock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TPropertiesOf.php
Expand Up @@ -49,7 +49,7 @@ public function __construct(
) {
$this->classlike_type = $classlike_type;
$this->visibility_filter = $visibility_filter;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateIndexedAccess.php
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->array_param_name = $array_param_name;
$this->offset_param_name = $offset_param_name;
$this->defining_class = $defining_class;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateKeyOf.php
Expand Up @@ -39,7 +39,7 @@ public function __construct(
$this->param_name = $param_name;
$this->defining_class = $defining_class;
$this->as = $as;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateParam.php
Expand Up @@ -48,7 +48,7 @@ public function __construct(
$this->as = $extends;
$this->defining_class = $defining_class;
$this->extra_types = $extra_types;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Psalm/Type/Atomic/TTemplateParamClass.php
Expand Up @@ -27,10 +27,15 @@ public function __construct(
bool $from_docblock = false
) {
$this->param_name = $param_name;
$this->as = $as;
$this->as_type = $as_type;
$this->defining_class = $defining_class;
$this->from_docblock = $from_docblock;
parent::__construct(
$as,
$as_type,
false,
false,
false,
$from_docblock,
);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplatePropertiesOf.php
Expand Up @@ -46,7 +46,7 @@ public function __construct(
$this->defining_class = $defining_class;
$this->as = $as;
$this->visibility_filter = $visibility_filter;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateValueOf.php
Expand Up @@ -39,7 +39,7 @@ public function __construct(
$this->param_name = $param_name;
$this->defining_class = $defining_class;
$this->as = $as;
$this->from_docblock = $from_docblock;
parent::__construct($from_docblock);
}

public function getKey(bool $include_extra = true): string
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/Atomic/TTypeAlias.php
Expand Up @@ -31,6 +31,7 @@ public function __construct(string $declaring_fq_classlike_name, string $alias_n
$this->declaring_fq_classlike_name = $declaring_fq_classlike_name;
$this->alias_name = $alias_name;
$this->extra_types = $extra_types;
parent::__construct(true);
}
/**
* @param array<string, TTypeAlias>|null $extra_types
Expand Down

0 comments on commit 902a019

Please sign in to comment.