Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Oct 2, 2024
1 parent 7a16d59 commit d25ea76
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 1 deletion.
8 changes: 7 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
>
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
<ini name="error_reporting" value="22527"/>
</php>

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>

<testsuite name="php84">
<directory>tests</directory>
<exclude>tests/Internal/NativeAdapter/AdapterCompatibilityTest.php</exclude>
<exclude>tests/TyphoonReflectorMemoryTest.php</exclude>
</testsuite>

<testsuite name="infection">
<file>tests/Internal/Inheritance/TypeResolversTest.php</file>
<file>tests/Internal/PhpDoc/PhpDocTypeReflectorTest.php</file>
Expand Down
1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@
<file name="tests/Internal/NativeAdapter/Fixtures/classes.php" preloadClasses="true"/>
<file name="tests/Internal/NativeAdapter/Fixtures/classes_php82.php" preloadClasses="true"/>
<file name="tests/Internal/NativeAdapter/Fixtures/classes_php83.php" preloadClasses="true"/>
<file name="src/Internal/NativeAdapter/PropertyHookType.php" preloadClasses="true"/>
</stubs>
</psalm>
80 changes: 80 additions & 0 deletions src/Internal/NativeAdapter/ClassAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,86 @@ public function setStaticPropertyValue(string $name, mixed $value): void
parent::setStaticPropertyValue($name, $value);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function newLazyGhost(callable $initializer, int $options = 0): object
{
$this->loadNative();

return parent::newLazyGhost($initializer, $options);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function newLazyProxy(callable $factory, int $options = 0): object
{
$this->loadNative();

return parent::newLazyProxy($factory, $options);
}

/**
* @psalm-suppress UndefinedMethod
*/
public function resetAsLazyGhost(object $object, callable $initializer, int $options = 0): void
{
$this->loadNative();

parent::resetAsLazyGhost($object, $initializer, $options);
}

/**
* @psalm-suppress UndefinedMethod
*/
public function resetAsLazyProxy(object $object, callable $factory, int $options = 0): void
{
$this->loadNative();

parent::resetAsLazyProxy($object, $factory, $options);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function initializeLazyObject(object $object): object
{
$this->loadNative();

return parent::initializeLazyObject($object);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function markLazyObjectAsInitialized(object $object): object
{
$this->loadNative();

return parent::markLazyObjectAsInitialized($object);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function getLazyInitializer(object $object): ?callable
{
$this->loadNative();

return parent::getLazyInitializer($object);
}

/**
* @psalm-suppress MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isUninitializedLazyObject(object $object): bool
{
$this->loadNative();

return parent::isUninitializedLazyObject($object);
}

/**
* @return Properties
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Internal/NativeAdapter/ClassConstantAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public function hasType(): bool
return $this->reflection->type(TypeKind::Native) !== null;
}

/**
* @psalm-suppress PossiblyUnusedMethod, UnusedPsalmSuppress
* @TODO
*/
public function isDeprecated(): bool
{
return false;
}

public function isEnumCase(): bool
{
return $this->reflection->isEnumCase();
Expand Down
64 changes: 64 additions & 0 deletions src/Internal/NativeAdapter/EnumAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,68 @@ public function setStaticPropertyValue(string $name, mixed $value): void
{
$this->_class->setStaticPropertyValue($name, $value);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function newLazyGhost(callable $initializer, int $options = 0): object
{
return $this->_class->newLazyGhost($initializer, $options);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function newLazyProxy(callable $factory, int $options = 0): object
{
return $this->_class->newLazyProxy($factory, $options);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function resetAsLazyGhost(object $object, callable $initializer, int $options = 0): void
{
$this->_class->resetAsLazyGhost($object, $initializer, $options);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function resetAsLazyProxy(object $object, callable $factory, int $options = 0): void
{
$this->_class->resetAsLazyProxy($object, $factory, $options);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function initializeLazyObject(object $object): object
{
return $this->_class->initializeLazyObject($object);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function markLazyObjectAsInitialized(object $object): object
{
return $this->_class->markLazyObjectAsInitialized($object);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function getLazyInitializer(object $object): ?callable
{
return $this->_class->getLazyInitializer($object);
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function isUninitializedLazyObject(object $object): bool
{
return $this->_class->isUninitializedLazyObject($object);
}
}
8 changes: 8 additions & 0 deletions src/Internal/NativeAdapter/EnumBackedCaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public function hasType(): bool
return $this->constant->hasType();
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function isDeprecated(): bool
{
return $this->constant->isDeprecated();
}

public function isEnumCase(): bool
{
return $this->constant->isEnumCase();
Expand Down
148 changes: 148 additions & 0 deletions src/Internal/NativeAdapter/PropertyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,154 @@ public function setValue(mixed $objectOrValue, mixed $value = null): void
parent::setValue($objectOrValue, $value);
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function getHooks(): array
{
$this->loadNative();

return parent::getHooks();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function getHook(\PropertyHookType $hook): ?\ReflectionMethod
{
$this->loadNative();

return parent::getHook($hook);
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isVirtual(): bool
{
$this->loadNative();

return parent::isVirtual();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function getSettableType(): ?\ReflectionType
{
$this->loadNative();

return parent::getSettableType();
}

/**
* @psalm-suppress PossiblyUnusedMethod, UndefinedMethod
*/
public function getRawValue(object $object): mixed
{
$this->loadNative();

return parent::getRawValue($object);
}

/**
* @psalm-suppress PossiblyUnusedMethod, UndefinedMethod
*/
public function setRawValue(object $object, mixed $value): void
{
$this->loadNative();

parent::setRawValue($object, $value);
}

/**
* @psalm-suppress PossiblyUnusedMethod, UndefinedMethod
*/
public function setRawValueWithoutLazyInitialization(object $object, mixed $value): void
{
$this->loadNative();

parent::setRawValueWithoutLazyInitialization($object, $value);
}

/**
* @psalm-suppress PossiblyUnusedMethod, UndefinedMethod
*/
public function skipLazyInitialization(object $object): void
{
$this->loadNative();

parent::skipLazyInitialization($object);
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isPrivateSet(): bool
{
$this->loadNative();

return parent::isPrivateSet();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isProtectedSet(): bool
{
$this->loadNative();

return parent::isProtectedSet();
}

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function isDynamic(): bool
{
return false;
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isAbstract(): bool
{
$this->loadNative();

return parent::isAbstract();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function isFinal(): bool
{
$this->loadNative();

return parent::isFinal();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function hasHooks(): bool
{
$this->loadNative();

return parent::hasHooks();
}

/**
* @psalm-suppress PossiblyUnusedMethod, MixedInferredReturnType, MixedReturnStatement, UndefinedMethod
*/
public function hasHook(\PropertyHookType $hook): bool
{
$this->loadNative();

return parent::hasHook($hook);
}

private bool $nativeLoaded = false;

private function loadNative(): void
Expand Down
13 changes: 13 additions & 0 deletions src/Internal/NativeAdapter/PropertyHookType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

if (enum_exists(PropertyHookType::class)) {
return;
}

enum PropertyHookType: string
{
case Get = 'get';
case Set = 'set';
}
Loading

0 comments on commit d25ea76

Please sign in to comment.