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

Use objects, not strings, for assertions #7410

Merged
merged 5 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/Psalm/Storage/Assertion/IsIdentical.php
Expand Up @@ -22,7 +22,7 @@ public function getNegation(): Assertion

public function __toString(): string
{
return '=' . $this->type->getAssertionString(true);
return '=' . $this->type->getAssertionString();
}

/** @psalm-mutation-free */
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Storage/Assertion/IsLooselyEqual.php
Expand Up @@ -22,7 +22,7 @@ public function getNegation(): Assertion

public function __toString(): string
{
return '~' . $this->type->getAssertionString(true);
return '~' . $this->type->getAssertionString();
}

/** @psalm-mutation-free */
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Storage/Assertion/IsNotIdentical.php
Expand Up @@ -33,7 +33,7 @@ public function hasEquality(): bool

public function __toString(): string
{
return '!=' . $this->type->getAssertionString(true);
return '!=' . $this->type->getAssertionString();
}

/** @psalm-mutation-free */
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Storage/Assertion/IsNotLooselyEqual.php
Expand Up @@ -33,7 +33,7 @@ public function hasEquality(): bool

public function __toString(): string
{
return '!~' . $this->type->getAssertionString(true);
return '!~' . $this->type->getAssertionString();
}

/** @psalm-mutation-free */
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic.php
Expand Up @@ -568,7 +568,7 @@ public function getId(bool $nested = false): string
return $this->__toString();
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return $this->getId();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Type/Atomic/TArray.php
Expand Up @@ -83,13 +83,13 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool
return true;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
if (!$exact || $this->type_params[1]->isMixed()) {
if ($this->type_params[0]->isMixed() && $this->type_params[1]->isMixed()) {
return 'array';
}

return $this->toNamespacedString(null, [], null, false);
return $this->getId();
}

public function isEmptyArray(): bool
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TCallableObject.php
Expand Up @@ -34,7 +34,9 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
orklah marked this conversation as resolved.
Show resolved Hide resolved
{
return 'object';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TCallableString.php
Expand Up @@ -23,7 +23,9 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'string';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TClassConstant.php
Expand Up @@ -37,7 +37,9 @@ public function getId(bool $nested = false): string
return $this->fq_classlike_name . '::' . $this->const_name;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'class-constant(' . $this->fq_classlike_name . '::' . $this->const_name . ')';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TClassString.php
Expand Up @@ -63,7 +63,9 @@ public function getId(bool $nested = false): string
. '-string' . ($this->as === 'object' ? '' : '<' . $this->as_type . '>');
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'class-string';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TClassStringMap.php
Expand Up @@ -231,7 +231,9 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool
return true;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return $this->getKey();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TConditional.php
Expand Up @@ -82,7 +82,9 @@ public function getKey(bool $include_extra = true): string
return $this->__toString();
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return '';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TDependentListKey.php
Expand Up @@ -34,7 +34,9 @@ public function getVarId(): string
return $this->var_id;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'int';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TGenericObject.php
Expand Up @@ -98,7 +98,9 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool
return true;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return $this->value;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TIterable.php
Expand Up @@ -56,7 +56,9 @@ public function getKey(bool $include_extra = true): string
return 'iterable';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'iterable';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TKeyOfClassConstant.php
Expand Up @@ -97,7 +97,9 @@ public function toNamespacedString(
return 'key-of<\\' . $this->fq_classlike_name . '::' . $this->const_name . '>';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return 'mixed';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TKeyedArray.php
Expand Up @@ -409,7 +409,9 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool
return true;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return $this->getKey();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Type/Atomic/TList.php
Expand Up @@ -197,13 +197,13 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool
return true;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
if (!$exact || $this->type_param->isMixed()) {
if ($this->type_param->isMixed()) {
return 'list';
}

return $this->toNamespacedString(null, [], null, false);
return $this->getId();
}

public function getChildNodes(): array
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic/TLiteralClassString.php
Expand Up @@ -57,7 +57,9 @@ public function getId(bool $nested = false): string
return $this->value . '::class';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString()

/** @psalm-mutation-free */: string
{
return $this->getKey();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TLiteralInt.php
Expand Up @@ -25,7 +25,7 @@ public function getId(bool $nested = false): string
return (string) $this->value;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'int(' . $this->value . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TLiteralString.php
Expand Up @@ -35,7 +35,7 @@ public function getId(bool $nested = false): string
return '"' . $no_newline_value . '"';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'string(' . $this->value . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TMixed.php
Expand Up @@ -44,7 +44,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return $analysis_php_version_id >= 8_00_00;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'mixed';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TNonEmptyList.php
Expand Up @@ -19,7 +19,7 @@ class TNonEmptyList extends TList

public const KEY = 'non-empty-list';

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'non-empty-list';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TNonspecificLiteralInt.php
Expand Up @@ -18,7 +18,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'int';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TNonspecificLiteralString.php
Expand Up @@ -18,7 +18,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'string';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TNumericString.php
Expand Up @@ -27,7 +27,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'string';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TObjectWithProperties.php
Expand Up @@ -265,7 +265,7 @@ public function getChildNodes(): array
return array_merge($this->properties, $this->extra_types !== null ? array_values($this->extra_types) : []);
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return $this->getKey();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TScalar.php
Expand Up @@ -35,7 +35,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'scalar';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateParam.php
Expand Up @@ -53,7 +53,7 @@ public function getKey(bool $include_extra = true): string
return $this->param_name . ':' . $this->defining_class;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return $this->as->getId();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTemplateParamClass.php
Expand Up @@ -45,7 +45,7 @@ public function getId(bool $nested = false): string
. ' as ' . ($this->as_type ? $this->as_type->getId() : $this->as) . '>';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'class-string<' . $this->param_name . '>';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TTypeAlias.php
Expand Up @@ -78,7 +78,7 @@ public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
return false;
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'mixed';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TValueOfClassConstant.php
Expand Up @@ -72,7 +72,7 @@ public function toNamespacedString(
. '>::' . $this->const_name . '>';
}

public function getAssertionString(bool $exact = false): string
public function getAssertionString(): string
{
return 'mixed';
}
Expand Down