Skip to content

Commit

Permalink
[Fix] Remaining undefined property fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 23, 2024
1 parent 4ec48d0 commit 65026a8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
8 changes: 5 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ parameters:
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

services:
-
class: Vormkracht10\TwoFactorAuth\Tests\PHPStan\UserPropertiesClassReflectionExtension
tags:
- phpstan.broker.propertiesClassReflectionExtension
69 changes: 69 additions & 0 deletions tests/PHPStan/CustomPropertyReflection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Vormkracht10\TwoFactorAuth\Tests\PHPStan;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\Type;

class CustomPropertyReflection implements PropertyReflection
{
private $declaringClass;
private $type;

public function __construct(ClassReflection $declaringClass, Type $type)
{
$this->declaringClass = $declaringClass;
$this->type = $type;
}

public function getDeclaringClass(): ClassReflection
{
return $this->declaringClass;
}

public function getType(): Type
{
return $this->type;
}

public function isStatic(): bool
{
return false;
}

public function isPrivate(): bool
{
return false;
}

public function isPublic(): bool
{
return true;
}

public function isDeprecated(): bool
{
return false;
}

public function getDeprecatedDescription(): ?string
{
return null;
}

public function isInternal(): bool
{
return false;
}

public function getDocComment(): ?string
{
return null;
}

public function isReadOnly(): bool
{
return false;
}
}
22 changes: 22 additions & 0 deletions tests/PHPStan/UserPropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Vormkracht10\TwoFactorAuth\Tests\PHPStan;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\ObjectType;

class UserPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
return $classReflection->getName() === 'Illuminate\Foundation\Auth\User' && $propertyName === 'two_factor_confirmed_at';
}

public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
$type = new ObjectType('Carbon\Carbon');
return new CustomPropertyReflection($classReflection, $type);
}
}

0 comments on commit 65026a8

Please sign in to comment.