Skip to content
Permalink
Browse files

Allow use of namespaced Resource class

Ref #2052
  • Loading branch information...
muglug committed Aug 26, 2019
1 parent 03f59ae commit 781e7112437072ded641429c12ea563badb04c43
@@ -116,10 +116,12 @@ public function analyze(
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 @@ public static function checkFullyQualifiedClassLikeName(
}
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'

This comment has been minimized.

Copy link
@staabm

staabm Aug 26, 2019

Contributor

in case this fix sticks: do we need the same fix for some of the other types, e.g. this cases are valid classnames

This comment has been minimized.

Copy link
@muglug

muglug Aug 26, 2019

Author Member

Yeah, I think so - the thing with resource is that PHP is unlikely to ever make it a single type class (because there are different sorts of resources), whereas numeric and mixed could be

) {
$class_name_parts = explode('\\', $fq_class_name);
$class_name = array_pop($class_name_parts);
@@ -628,6 +628,39 @@ public function doFoo(): int {
}
}',
],
'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;
}
}',
],
];
}

0 comments on commit 781e711

Please sign in to comment.
You can’t perform that action at this time.