Skip to content

Remove usages of deprecated TList types #15

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

Merged
merged 1 commit into from
Nov 28, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/psl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
working-directory: psl
run: |
composer config repositories.psalm-plugin path ../
composer require --dev 'php-standard-library/psalm-plugin:*@dev'
composer require --dev 'php-standard-library/psalm-plugin:*@dev' 'vimeo/psalm:>=5.16'

- name: "installing dependencies"
working-directory: psl
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.1",
"vimeo/psalm": "^5.0"
"vimeo/psalm": ">=5.16"
},
"conflict": {
"azjezz/psl": "<2.0"
Expand Down
14 changes: 5 additions & 9 deletions src/EventHandler/Str/Chunk/FunctionReturnTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,26 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
$argument_type = Argument::getType($event->getCallArgs(), $event->getStatementsSource(), 0);
if (null === $argument_type) {
// [unknown] -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}

$string_argument_type = $argument_type->getAtomicTypes()['string'] ?? null;
if (null === $string_argument_type) {
// [unknown] -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}

if ($string_argument_type instanceof Type\Atomic\TNonEmptyString) {
// non-empty-lowercase-string => non-empty-list<non-empty-lowercase-string>
if ($string_argument_type instanceof Type\Atomic\TNonEmptyLowercaseString) {
return new Type\Union([
new Type\Atomic\TNonEmptyList(new Type\Union([
new Type\Atomic\TNonEmptyLowercaseString()
]))
]);
return Type::getNonEmptyList(Type::getNonEmptyLowercaseString());
}

// non-empty-string => non-empty-list<non-empty-string>
return new Type\Union([new Type\Atomic\TNonEmptyList(new Type\Union([new Type\Atomic\TNonEmptyString()]))]);
return Type::getNonEmptyList(Type::getNonEmptyString());
}

// string -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}
}
14 changes: 5 additions & 9 deletions src/EventHandler/Str/Split/FunctionReturnTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,26 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
$argument_type = Argument::getType($event->getCallArgs(), $event->getStatementsSource(), 0);
if (null === $argument_type) {
// [unknown] -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}

$string_argument_type = $argument_type->getAtomicTypes()['string'] ?? null;
if (null === $string_argument_type) {
// [unknown] -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}

if ($string_argument_type instanceof Type\Atomic\TNonEmptyString) {
// non-empty-lowercase-string => non-empty-list<non-empty-lowercase-string>
if ($string_argument_type instanceof Type\Atomic\TNonEmptyLowercaseString) {
return new Type\Union([
new Type\Atomic\TNonEmptyList(new Type\Union([
new Type\Atomic\TNonEmptyLowercaseString()
]))
]);
return Type::getNonEmptyList(Type::getNonEmptyLowercaseString());
}

// non-empty-string => non-empty-list<non-empty-string>
return new Type\Union([new Type\Atomic\TNonEmptyList(new Type\Union([new Type\Atomic\TNonEmptyString()]))]);
return Type::getNonEmptyList(Type::getNonEmptyString());
}

// string -> list<string>
return new Type\Union([new Type\Atomic\TList(new Type\Union([new Type\Atomic\TString()]))]);
return Type::getList(Type::getString());
}
}