Skip to content

Commit

Permalink
Psalm v5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 12, 2022
1 parent 63df87c commit 7a1c3fd
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,29 @@ private static function analyseArgument(array $args, StatementsSource $statement
$mode = InputArgument::OPTIONAL;
}

$add_null = false;
if ($mode & InputArgument::IS_ARRAY) {
$returnTypes = new MutableUnion([new TArray([new Union([new TInt()]), new Union([new TString()])])]);
$returnTypes = [new TArray([new Union([new TInt()]), new Union([new TString()])])];
} elseif ($mode & InputArgument::REQUIRED) {
$returnTypes = new MutableUnion([new TString()]);
$returnTypes = [new TString()];
} else {
$returnTypes = new MutableUnion([new TString(), new TNull()]);
$add_null = true;
$returnTypes = [new TString()];
}

$defaultParam = $normalizedParams['default'];
if ($defaultParam) {
$returnTypes->removeType('null');
$add_null = false;
if ($defaultParam->value instanceof Expr\ConstFetch && 'null' === $defaultParam->value->name->parts[0]) {
$returnTypes->addType(new TNull());
$add_null = true;
}
}

self::$arguments[$identifier] = $returnTypes->freeze();
if ($add_null) {
$returnTypes[] = new TNull();
}

self::$arguments[$identifier] = new Union($returnTypes);
}

/**
Expand Down Expand Up @@ -200,40 +206,45 @@ private static function analyseOption(array $args, StatementsSource $statements_
$mode = InputOption::VALUE_OPTIONAL;
}

$returnTypes = new MutableUnion([new TString(), new TNull()]);
$add_null = true;
$returnTypes = [new TString()];

$defaultParam = $normalizedParams['default'];
if ($defaultParam) {
if (0 === ($mode & InputOption::VALUE_OPTIONAL)) {
$returnTypes->removeType('null');
$add_null = false;
}

if ($defaultParam->value instanceof Expr\ConstFetch) {
switch ($defaultParam->value->name->parts[0]) {
case 'null':
$returnTypes->addType(new TNull());
$add_null = true;
break;
case 'false':
case 'true':
$returnTypes->addType(new TBool());
$returnTypes[] = new TBool();
break;
}
}
}

if ($mode & InputOption::VALUE_NONE) {
$returnTypes = new MutableUnion([new TBool()]);
if ($mode & InputOption::VALUE_REQUIRED && $mode & InputOption::VALUE_IS_ARRAY) {
$add_null = false;
}

if ($mode & InputOption::VALUE_REQUIRED && $mode & InputOption::VALUE_IS_ARRAY) {
$returnTypes->removeType('null');
if ($add_null) {
$returnTypes[] = new TNull();
}

if ($mode & InputOption::VALUE_NONE) {
$returnTypes = [new TBool()];
}

if ($mode & InputOption::VALUE_IS_ARRAY) {
$returnTypes = new MutableUnion([new TArray([new Union([new TInt()]), $returnTypes->freeze()])]);
$returnTypes = [new TArray([new Union([new TInt()]), new Union($returnTypes)])];
}

self::$options[$identifier] = $returnTypes->freeze();
self::$options[$identifier] = new Union($returnTypes);
}

/**
Expand Down

0 comments on commit 7a1c3fd

Please sign in to comment.