-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from TebexOllie/phpstan
Add PHPStan compatibility
- Loading branch information
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
- | ||
class: LiamWiltshire\LaravelModelMeta\PHPStan\ModelAttributeExtension | ||
tags: | ||
- phpstan.broker.propertiesClassReflectionExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace LiamWiltshire\LaravelModelMeta\PHPStan; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\PropertiesClassReflectionExtension; | ||
use PHPStan\Reflection\PropertyReflection; | ||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\MixedType; | ||
use PHPStan\Type\StringType; | ||
use PHPStan\Type\Type; | ||
|
||
class MetaProperty implements PropertyReflection | ||
{ | ||
|
||
private $classReflection; | ||
private $propertyName; | ||
|
||
public function __construct(ClassReflection $classReflection, string $propertyName) | ||
{ | ||
$this->classReflection = $classReflection; | ||
$this->propertyName = $propertyName; | ||
} | ||
|
||
public function isStatic(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPrivate(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isPublic(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function isReadable(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function isWritable(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function isDeprecated(): TrinaryLogic | ||
{ | ||
return false; | ||
} | ||
|
||
public function isInternal(): TrinaryLogic | ||
{ | ||
return false; | ||
} | ||
|
||
public function canChangeTypeAfterAssignment(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getReadableType(): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function getWritableType(): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function getDeclaringClass(): \PHPStan\Reflection\ClassReflection | ||
{ | ||
return $this->classReflection; | ||
} | ||
|
||
public function getPropertyName(): string | ||
{ | ||
return $this->propertyName; | ||
} | ||
|
||
public function getDocComment(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getDeprecatedDescription(): ?string | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace LiamWiltshire\LaravelModelMeta\PHPStan; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use LiamWiltshire\LaravelModelMeta\Concerns\HasMeta; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\PropertiesClassReflectionExtension; | ||
use PHPStan\Reflection\PropertyReflection; | ||
use Tebex\Checkout\Models\RecurringPayment; | ||
|
||
class ModelAttributeExtension implements PropertiesClassReflectionExtension | ||
{ | ||
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool | ||
{ | ||
foreach ($classReflection->getTraits() as $trait) { | ||
if ($trait->getName() === (string)HasMeta::class) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection | ||
{ | ||
return new MetaProperty($classReflection, $propertyName); | ||
} | ||
} |