framework/php-packages/phpstan/src/Properties/HigherOrderCollectionProxyPropertyExtension.php
dependabot[bot] 37a882118a
chore(deps): bump glob-parent from 3.1.0 to 5.1.2 in /extensions/emoji/js (#3345)
* chore(deps): bump glob-parent in /extensions/emoji/js

Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 3.1.0 to 5.1.2.
- [Release notes](https://github.com/gulpjs/glob-parent/releases)
- [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gulpjs/glob-parent/compare/v3.1.0...v5.1.2)

---
updated-dependencies:
- dependency-name: glob-parent
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Apply fixes from StyleCI

[ci skip] [skip ci]

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
2022-03-11 18:11:20 -05:00

125 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\PHPStan\Properties;
use Flarum\PHPStan\Support\HigherOrderCollectionProxyHelper;
use PHPStan\Analyser\OutOfClassScope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\TrinaryLogic;
use PHPStan\Type;
final class HigherOrderCollectionProxyPropertyExtension implements PropertiesClassReflectionExtension
{
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
return HigherOrderCollectionProxyHelper::hasPropertyOrMethod($classReflection, $propertyName, 'property');
}
public function getProperty(
ClassReflection $classReflection,
string $propertyName
): PropertyReflection {
$activeTemplateTypeMap = $classReflection->getActiveTemplateTypeMap();
/** @var Type\Constant\ConstantStringType $methodType */
$methodType = $activeTemplateTypeMap->getType('T');
/** @var Type\ObjectType $modelType */
$modelType = $activeTemplateTypeMap->getType('TValue');
$propertyType = $modelType->getProperty($propertyName, new OutOfClassScope())->getReadableType();
$returnType = HigherOrderCollectionProxyHelper::determineReturnType($methodType->getValue(), $modelType, $propertyType);
return new class($classReflection, $returnType) implements PropertyReflection {
/** @var ClassReflection */
private $classReflection;
/** @var Type\Type */
private $returnType;
public function __construct(ClassReflection $classReflection, Type\Type $returnType)
{
$this->classReflection = $classReflection;
$this->returnType = $returnType;
}
public function getDeclaringClass(): \PHPStan\Reflection\ClassReflection
{
return $this->classReflection;
}
public function isStatic(): bool
{
return false;
}
public function isPrivate(): bool
{
return false;
}
public function isPublic(): bool
{
return true;
}
public function getDocComment(): ?string
{
return null;
}
public function getReadableType(): Type\Type
{
return $this->returnType;
}
public function getWritableType(): Type\Type
{
return $this->returnType;
}
public function canChangeTypeAfterAssignment(): bool
{
return false;
}
public function isReadable(): bool
{
return true;
}
public function isWritable(): bool
{
return false;
}
public function isDeprecated(): \PHPStan\TrinaryLogic
{
return TrinaryLogic::createNo();
}
public function getDeprecatedDescription(): ?string
{
return null;
}
public function isInternal(): \PHPStan\TrinaryLogic
{
return TrinaryLogic::createNo();
}
};
}
}