Skip to content

Commit

Permalink
Try another strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jan 13, 2022
1 parent cbfa6a1 commit 2fa0a3a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 38 deletions.
Expand Up @@ -2,6 +2,8 @@

namespace Psalm\Internal\Analyzer\Statements\Expression\Call\Method;

use Exception;
use PDOException;
use PhpParser;
use Psalm\CodeLocation;
use Psalm\Codebase;
Expand All @@ -27,6 +29,7 @@
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;
use Throwable;
use UnexpectedValueException;

use function array_filter;
Expand Down Expand Up @@ -92,6 +95,16 @@ public static function fetch(
}
}

if ($premixin_method_id->method_name === 'getcode'
&& $premixin_method_id->fq_class_name !== Exception::class
&& in_array(Throwable::class, $class_storage->class_implements)) {
if ($premixin_method_id->fq_class_name === PDOException::class) {
return Type::parseString('string');
} else {
return Type::parseString('int');
}
}

if ($declaring_method_id && $declaring_method_id !== $method_id) {
$declaring_fq_class_name = $declaring_method_id->fq_class_name;
$declaring_method_name = $declaring_method_id->method_name;
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Provider/FunctionReturnTypeProvider.php
Expand Up @@ -23,7 +23,6 @@
use Psalm\Internal\Provider\ReturnTypeProvider\ArraySpliceReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\ArrayUniqueReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\ArrayValuesReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\ExceptionCodeReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\ExplodeReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\FilterVarReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\FirstArgStringReturnTypeProvider;
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Provider/MethodReturnTypeProvider.php
Expand Up @@ -8,7 +8,6 @@
use Psalm\Context;
use Psalm\Internal\Provider\ReturnTypeProvider\ClosureFromCallableReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\DomNodeAppendChild;
use Psalm\Internal\Provider\ReturnTypeProvider\ExceptionCodeReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\ImagickPixelColorReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\PdoStatementReturnTypeProvider;
use Psalm\Internal\Provider\ReturnTypeProvider\SimpleXmlElementAsXml;
Expand Down Expand Up @@ -59,7 +58,6 @@ public function __construct()
$this->registerClass(SimpleXmlElementAsXml::class);
$this->registerClass(PdoStatementReturnTypeProvider::class);
$this->registerClass(ClosureFromCallableReturnTypeProvider::class);
$this->registerClass(ExceptionCodeReturnTypeProvider::class);
}

/**
Expand Down

This file was deleted.

0 comments on commit 2fa0a3a

Please sign in to comment.