mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
parent
03f59ae05e
commit
781e711243
@ -116,10 +116,12 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
||||
return;
|
||||
}
|
||||
|
||||
if ($class->name && preg_match(
|
||||
'/(^|\\\)(int|float|bool|string|void|null|false|true|resource|object|numeric|mixed)$/i',
|
||||
$fq_class_name
|
||||
)) {
|
||||
if ($class->name
|
||||
&& (preg_match(
|
||||
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|numeric|mixed)$/i',
|
||||
$fq_class_name
|
||||
) || strtolower($fq_class_name) === 'resource')
|
||||
) {
|
||||
$class_name_parts = explode('\\', $fq_class_name);
|
||||
$class_name = array_pop($class_name_parts);
|
||||
|
||||
|
@ -235,9 +235,9 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
|
||||
}
|
||||
|
||||
if (preg_match(
|
||||
'/(^|\\\)(int|float|bool|string|void|null|false|true|resource|object|numeric|mixed)$/i',
|
||||
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|numeric|mixed)$/i',
|
||||
$fq_class_name
|
||||
)
|
||||
) || strtolower($fq_class_name) === 'resource'
|
||||
) {
|
||||
$class_name_parts = explode('\\', $fq_class_name);
|
||||
$class_name = array_pop($class_name_parts);
|
||||
|
@ -628,6 +628,39 @@ class ReturnTypeTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'allowResourceInNamespace' => [
|
||||
'<?php
|
||||
|
||||
namespace Bar;
|
||||
|
||||
class Resource {
|
||||
function get(string $key): ?string {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
/** @var string[] */
|
||||
private $references = [];
|
||||
|
||||
/** @var Resource */
|
||||
private $resource;
|
||||
|
||||
public function __construct() {
|
||||
$this->resource = new Resource();
|
||||
}
|
||||
|
||||
public function foo(): array {
|
||||
$types = [];
|
||||
|
||||
foreach ($this->references as $ref => $data) {
|
||||
$types[$ref] = $this->resource->get($data);
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user