[Web] Some minor fixes and improvements for PHP 8
This commit is contained in:
@@ -55,7 +55,7 @@ class ClassStub extends ConstStub
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== strpos($identifier, "@anonymous\0")) {
|
||||
if (str_contains($identifier, "@anonymous\0")) {
|
||||
$this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
|
||||
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
|
||||
}, $identifier);
|
||||
@@ -65,7 +65,7 @@ class ClassStub extends ConstStub
|
||||
$s = ReflectionCaster::castFunctionAbstract($r, [], new Stub(), true, Caster::EXCLUDE_VERBOSE);
|
||||
$s = ReflectionCaster::getSignature($s);
|
||||
|
||||
if ('()' === substr($identifier, -2)) {
|
||||
if (str_ends_with($identifier, '()')) {
|
||||
$this->value = substr_replace($identifier, $s, -2);
|
||||
} else {
|
||||
$this->value .= $s;
|
||||
|
@@ -82,7 +82,7 @@ class DOMCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castImplementation($dom, array $a, Stub $stub, bool $isNested)
|
||||
public static function castImplementation(\DOMImplementation $dom, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$a += [
|
||||
Caster::PREFIX_VIRTUAL.'Core' => '1.0',
|
||||
|
@@ -149,7 +149,7 @@ class ExceptionCaster
|
||||
$f = self::castFrameStub($frame, [], $frame, true);
|
||||
if (isset($f[$prefix.'src'])) {
|
||||
foreach ($f[$prefix.'src']->value as $label => $frame) {
|
||||
if (0 === strpos($label, "\0~collapse=0")) {
|
||||
if (str_starts_with($label, "\0~collapse=0")) {
|
||||
if ($collapse) {
|
||||
$label = substr_replace($label, '1', 11, 1);
|
||||
} else {
|
||||
@@ -281,7 +281,7 @@ class ExceptionCaster
|
||||
}
|
||||
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);
|
||||
|
||||
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && false !== strpos($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
|
||||
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && str_contains($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
|
||||
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
|
||||
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
|
||||
}, $a[Caster::PREFIX_PROTECTED.'message']);
|
||||
|
@@ -23,7 +23,7 @@ class LinkStub extends ConstStub
|
||||
private static $vendorRoots;
|
||||
private static $composerRoots;
|
||||
|
||||
public function __construct($label, int $line = 0, $href = null)
|
||||
public function __construct(string $label, int $line = 0, string $href = null)
|
||||
{
|
||||
$this->value = $label;
|
||||
|
||||
@@ -33,12 +33,12 @@ class LinkStub extends ConstStub
|
||||
if (!\is_string($href)) {
|
||||
return;
|
||||
}
|
||||
if (0 === strpos($href, 'file://')) {
|
||||
if (str_starts_with($href, 'file://')) {
|
||||
if ($href === $label) {
|
||||
$label = substr($label, 7);
|
||||
}
|
||||
$href = substr($href, 7);
|
||||
} elseif (false !== strpos($href, '://')) {
|
||||
} elseif (str_contains($href, '://')) {
|
||||
$this->attr['href'] = $href;
|
||||
|
||||
return;
|
||||
@@ -69,7 +69,7 @@ class LinkStub extends ConstStub
|
||||
self::$vendorRoots = [];
|
||||
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
|
||||
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
|
||||
$r = new \ReflectionClass($class);
|
||||
$v = \dirname($r->getFileName(), 2);
|
||||
if (is_file($v.'/composer/installed.json')) {
|
||||
@@ -85,7 +85,7 @@ class LinkStub extends ConstStub
|
||||
}
|
||||
|
||||
foreach (self::$vendorRoots as $root) {
|
||||
if ($inVendor = 0 === strpos($file, $root)) {
|
||||
if ($inVendor = str_starts_with($file, $root)) {
|
||||
return $root;
|
||||
}
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ class MemcachedCaster
|
||||
|
||||
$optionConstants = [];
|
||||
foreach ($reflectedMemcached->getConstants() as $constantKey => $value) {
|
||||
if (0 === strpos($constantKey, 'OPT_')) {
|
||||
if (str_starts_with($constantKey, 'OPT_')) {
|
||||
$optionConstants[$constantKey] = $value;
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
*/
|
||||
class RdKafkaCaster
|
||||
{
|
||||
public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, $isNested)
|
||||
public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -51,7 +51,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castTopic(Topic $c, array $a, Stub $stub, $isNested)
|
||||
public static function castTopic(Topic $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -75,7 +75,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castMessage(Message $c, array $a, Stub $stub, $isNested)
|
||||
public static function castMessage(Message $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -86,7 +86,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castConf(Conf $c, array $a, Stub $stub, $isNested)
|
||||
public static function castConf(Conf $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -97,7 +97,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castTopicConf(TopicConf $c, array $a, Stub $stub, $isNested)
|
||||
public static function castTopicConf(TopicConf $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -108,7 +108,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, $isNested)
|
||||
public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -121,14 +121,14 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, $isNested)
|
||||
public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$a += iterator_to_array($c);
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, $isNested)
|
||||
public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -140,7 +140,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, $isNested)
|
||||
public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
@@ -153,7 +153,7 @@ class RdKafkaCaster
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, $isNested)
|
||||
public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
|
@@ -42,7 +42,7 @@ class ReflectionCaster
|
||||
|
||||
$a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter);
|
||||
|
||||
if (false === strpos($c->name, '{closure}')) {
|
||||
if (!str_contains($c->name, '{closure}')) {
|
||||
$stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name;
|
||||
unset($a[$prefix.'class']);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class ReflectionCaster
|
||||
$prefix.'allowsNull' => $c->allowsNull(),
|
||||
$prefix.'isBuiltin' => $c->isBuiltin(),
|
||||
];
|
||||
} elseif ($c instanceof \ReflectionUnionType) {
|
||||
} elseif ($c instanceof \ReflectionUnionType || $c instanceof \ReflectionIntersectionType) {
|
||||
$a[$prefix.'allowsNull'] = $c->allowsNull();
|
||||
self::addMap($a, $c, [
|
||||
'types' => 'getTypes',
|
||||
@@ -381,7 +381,7 @@ class ReflectionCaster
|
||||
} elseif (\is_array($v)) {
|
||||
$signature .= $v ? '[…'.\count($v).']' : '[]';
|
||||
} elseif (\is_string($v)) {
|
||||
$signature .= 10 > \strlen($v) && false === strpos($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
|
||||
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
|
||||
} elseif (\is_bool($v)) {
|
||||
$signature .= $v ? 'true' : 'false';
|
||||
} else {
|
||||
|
@@ -48,7 +48,7 @@ class ResourceCaster
|
||||
public static function castStream($stream, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
|
||||
if (isset($a['uri'])) {
|
||||
if ($a['uri'] ?? false) {
|
||||
$a['uri'] = new LinkStub($a['uri']);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class ResourceCaster
|
||||
return @stream_context_get_params($stream) ?: $a;
|
||||
}
|
||||
|
||||
public static function castGd($gd, array $a, Stub $stub, $isNested)
|
||||
public static function castGd($gd, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$a['size'] = imagesx($gd).'x'.imagesy($gd);
|
||||
$a['trueColor'] = imageistruecolor($gd);
|
||||
|
@@ -39,7 +39,7 @@ class SplCaster
|
||||
return self::castSplArray($c, $a, $stub, $isNested);
|
||||
}
|
||||
|
||||
public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested)
|
||||
public static function castHeap(\Iterator $c, array $a, Stub $stub, bool $isNested)
|
||||
{
|
||||
$a += [
|
||||
Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c),
|
||||
@@ -129,7 +129,7 @@ class SplCaster
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($a[$prefix.'realPath'])) {
|
||||
if ($a[$prefix.'realPath'] ?? false) {
|
||||
$a[$prefix.'realPath'] = new LinkStub($a[$prefix.'realPath']);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user