Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename was_static property to is_static to be more accurate #7358

Merged
merged 1 commit into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -298,7 +298,7 @@ public function analyze(
$union = new Union($mixins);

$static_self = new TNamedObject($storage->name);
$static_self->was_static = true;
$static_self->is_static = true;

$union = TypeExpander::expandUnion(
$codebase,
Expand Down Expand Up @@ -1227,7 +1227,7 @@ function (FunctionLikeParameter $param): PhpParser\Node\Arg {
$method_context->self = $fq_class_name;

$this_atomic_object_type = new TNamedObject($fq_class_name);
$this_atomic_object_type->was_static = !$storage->final;
$this_atomic_object_type->is_static = !$storage->final;

$method_context->vars_in_scope['$this'] = new Union([$this_atomic_object_type]);
$method_context->vars_possibly_in_scope['$this'] = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClosureAnalyzer.php
Expand Up @@ -95,7 +95,7 @@ public static function analyzeExpression(
$use_context->vars_in_scope['$this'] = clone $context->vars_in_scope['$this'];
} elseif ($context->self) {
$this_atomic = new TNamedObject($context->self);
$this_atomic->was_static = true;
$this_atomic->is_static = true;

$use_context->vars_in_scope['$this'] = new Union([$this_atomic]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Expand Up @@ -1811,7 +1811,7 @@ private function getFunctionInformation(
$this_object_type = new TNamedObject($context->self);
}

$this_object_type->was_static = !$storage->final;
$this_object_type->is_static = !$storage->final;

if ($this->storage instanceof MethodStorage && $this->storage->if_this_is_type) {
$template_result = new TemplateResult($this->getTemplateTypeMap() ?? [], []);
Expand Down
Expand Up @@ -526,7 +526,7 @@ private static function analyzeNamedConstructor(
$generic_param_types
);

$result_atomic_type->was_static = $from_static;
$result_atomic_type->is_static = $from_static;

$statements_analyzer->node_data->setType(
$stmt,
Expand All @@ -553,7 +553,7 @@ private static function analyzeNamedConstructor(
)
);

$result_atomic_type->was_static = $from_static;
$result_atomic_type->is_static = $from_static;

$statements_analyzer->node_data->setType(
$stmt,
Expand Down
Expand Up @@ -158,7 +158,7 @@ public static function analyze(

if ($first_part_lc === 'static') {
$static_named_object = new TNamedObject($fq_class_name);
$static_named_object->was_static = true;
$static_named_object->is_static = true;

$statements_analyzer->node_data->setType(
$stmt,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/AssertionReconciler.php
Expand Up @@ -628,7 +628,7 @@ private static function filterAtomicWithAnother(
}

if ($type_1_atomic instanceof TNamedObject) {
$type_1_atomic->was_static = false;
$type_1_atomic->is_static = false;
}

$atomic_comparison_results = new TypeComparisonResult();
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php
Expand Up @@ -301,8 +301,8 @@ public static function isContainedBy(

if ($container_type_part instanceof TNamedObject
&& $input_type_part instanceof TNamedObject
&& $container_type_part->was_static
&& !$input_type_part->was_static
&& $container_type_part->is_static
&& !$input_type_part->is_static
) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
Expand Down Expand Up @@ -596,8 +596,8 @@ public static function isContainedBy(

if ($container_type_part instanceof TNamedObject
&& $input_type_part instanceof TNamedObject
&& $container_type_part->was_static
&& !$input_type_part->was_static
&& $container_type_part->is_static
&& !$input_type_part->is_static
) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Type/Comparator/GenericTypeComparator.php
Expand Up @@ -192,8 +192,8 @@ public static function isContainedBy(
$allow_interface_equality
) || $param_comparison_result->type_coerced
) {
if ($container_param->hasFormerStaticObject()
&& $input_param->isFormerStaticObject()
if ($container_param->hasStaticObject()
&& $input_param->isStaticObject()
&& UnionTypeComparator::isContainedBy(
$codebase,
$input_param,
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Type/Comparator/ObjectComparator.php
Expand Up @@ -45,7 +45,7 @@ public static function isShallowlyContainedBy(
} elseif ($intersection_container_type instanceof TTemplateParam) {
$intersection_container_type_lower = null;
} else {
$container_was_static = $intersection_container_type->was_static;
$container_was_static = $intersection_container_type->is_static;

$intersection_container_type_lower = strtolower(
$codebase->classlikes->getUnAliasedName(
Expand Down Expand Up @@ -203,7 +203,7 @@ private static function isIntersectionShallowlyContainedBy(

if ($intersection_container_type instanceof TNamedObject) {
// this is extra check is redundant since we're comparing to a template as type
$intersection_container_type->was_static = false;
$intersection_container_type->is_static = false;
}

return UnionTypeComparator::isContainedBy(
Expand All @@ -224,7 +224,7 @@ private static function isIntersectionShallowlyContainedBy(
} elseif ($intersection_input_type instanceof TObjectWithProperties) {
$intersection_input_type_lower = 'object';
} else {
$input_was_static = $intersection_input_type->was_static;
$input_was_static = $intersection_input_type->is_static;

$intersection_input_type_lower = strtolower(
$codebase->classlikes->getUnAliasedName(
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -270,7 +270,7 @@ public static function combine(
$generic_object = new TGenericObject($generic_type, $generic_type_params);

if ($combination->object_static[$generic_type] ?? false) {
$generic_object->was_static = true;
$generic_object->is_static = true;
}

/** @psalm-suppress PropertyTypeCoercion */
Expand Down Expand Up @@ -513,11 +513,11 @@ private static function scrapeTypeProperties(

if ($type instanceof TNamedObject) {
if (array_key_exists($type->value, $combination->object_static)) {
if ($combination->object_static[$type->value] && !$type->was_static) {
if ($combination->object_static[$type->value] && !$type->is_static) {
$combination->object_static[$type->value] = false;
}
} else {
$combination->object_static[$type->value] = $type->was_static;
$combination->object_static[$type->value] = $type->is_static;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Type/TypeExpander.php
Expand Up @@ -641,9 +641,9 @@ private static function expandNamedObject(
}

if (!$final && $return_type instanceof TNamedObject) {
$return_type->was_static = true;
$return_type->is_static = true;
}
} elseif ($return_type->was_static
} elseif ($return_type->is_static
&& ($static_class_type instanceof TNamedObject
|| $static_class_type instanceof TTemplateParam)
) {
Expand All @@ -661,9 +661,9 @@ private static function expandNamedObject(
$return_type->extra_types[$extra_static_type->getKey()] = clone $extra_static_type;
}
}
} elseif ($return_type->was_static && is_string($static_class_type) && $final) {
} elseif ($return_type->is_static && is_string($static_class_type) && $final) {
$return_type->value = $static_class_type;
$return_type->was_static = false;
$return_type->is_static = false;
} elseif ($self_class && $return_type_lc === 'self') {
$return_type->value = $self_class;
} elseif ($parent_class && $return_type_lc === 'parent') {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/TypeParser.php
Expand Up @@ -1084,7 +1084,7 @@ function (ParseTree $child_tree) use ($codebase, $template_type_map, $type_alias
if ($intersect_static
&& $first_type instanceof TNamedObject
) {
$first_type->was_static = true;
$first_type->is_static = true;
}

if ($keyed_intersection_types) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type.php
Expand Up @@ -127,10 +127,10 @@ public static function getStringFromFQCLN(
array $aliased_classes,
?string $this_class,
bool $allow_self = false,
bool $was_static = false
bool $is_static = false
): string {
if ($allow_self && $value === $this_class) {
if ($was_static) {
if ($is_static) {
return 'static';
}
return 'self';
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/GenericTrait.php
Expand Up @@ -64,7 +64,7 @@ public function getId(bool $nested = false): string
);
}

if ($this->was_static) {
if ($this->is_static) {
$extra_types .= '&static';
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type/Atomic/TAnonymousClassInstance.php
Expand Up @@ -15,9 +15,9 @@ class TAnonymousClassInstance extends TNamedObject
/**
* @param string $value the name of the object
*/
public function __construct(string $value, bool $was_static = false, ?string $extends = null)
public function __construct(string $value, bool $is_static = false, ?string $extends = null)
{
parent::__construct($value, $was_static);
parent::__construct($value, $is_static);

$this->extends = $extends;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Psalm/Type/Atomic/TNamedObject.php
Expand Up @@ -27,7 +27,7 @@ class TNamedObject extends Atomic
/**
* @var bool
*/
public $was_static = false;
public $is_static = false;

/**
* Whether or not this type can represent a child of the class named in $value
Expand All @@ -38,14 +38,14 @@ class TNamedObject extends Atomic
/**
* @param string $value the name of the object
*/
public function __construct(string $value, bool $was_static = false, bool $definite_class = false)
public function __construct(string $value, bool $is_static = false, bool $definite_class = false)
{
if ($value[0] === '\\') {
$value = substr($value, 1);
}

$this->value = $value;
$this->was_static = $was_static;
$this->is_static = $is_static;
$this->definite_class = $definite_class;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ public function getId(bool $nested = false): string
);
}

return $this->was_static ? $this->value . '&static' : $this->value;
return $this->is_static ? $this->value . '&static' : $this->value;
}

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ public function toNamespacedString(
$aliased_classes,
$this_class,
true,
$this->was_static
$this->is_static
) . $intersection_types;
}

Expand All @@ -122,7 +122,7 @@ public function toPhpString(
return $analysis_php_version_id >= 8_00_00 ? 'static' : null;
}

if ($this->was_static && $this->value === $this_class) {
if ($this->is_static && $this->value === $this_class) {
return $analysis_php_version_id >= 8_00_00 ? 'static' : 'self';
}

Expand All @@ -136,7 +136,7 @@ public function toPhpString(

public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
{
return ($this->value !== 'static' && $this->was_static === false) || $analysis_php_version_id >= 8_00_00;
return ($this->value !== 'static' && $this->is_static === false) || $analysis_php_version_id >= 8_00_00;
}

public function replaceTemplateTypesWithArgTypes(
Expand Down
10 changes: 5 additions & 5 deletions src/Psalm/Type/Union.php
Expand Up @@ -763,11 +763,11 @@ public function hasNamedObjectType(): bool
return false;
}

public function isFormerStaticObject(): bool
public function isStaticObject(): bool
{
foreach ($this->types as $type) {
if (!$type instanceof TNamedObject
|| !$type->was_static
|| !$type->is_static
) {
return false;
}
Expand All @@ -776,11 +776,11 @@ public function isFormerStaticObject(): bool
return true;
}

public function hasFormerStaticObject(): bool
public function hasStaticObject(): bool
{
foreach ($this->types as $type) {
if ($type instanceof TNamedObject
&& $type->was_static
&& $type->is_static
) {
return true;
}
Expand Down Expand Up @@ -926,7 +926,7 @@ public function hasTemplateOrStatic(): bool
$this->types,
fn(Atomic $type): bool => $type instanceof TTemplateParam
|| ($type instanceof TNamedObject
&& ($type->was_static
&& ($type->is_static
|| ($type->extra_types
&& array_filter(
$type->extra_types,
Expand Down