<commit_before><?php declare(strict_types = 1);

namespace SaschaEgerer\PhpstanTypo3\Type;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\DateTimeAspect;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Context\TypoScriptAspect;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Context\VisibilityAspect;
use TYPO3\CMS\Core\Context\WorkspaceAspect;

class ContextDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{

	public function getClass(): string
	{
		return Context::class;
	}

	public function isMethodSupported(
		MethodReflection $methodReflection
	): bool
	{
		return $methodReflection->getName() === 'getAspect';
	}

	public function getTypeFromMethodCall(
		MethodReflection $methodReflection,
		MethodCall $methodCall,
		Scope $scope
	): Type
	{
		$arg = $methodCall->args[0]->value;
		if (!($arg instanceof \PhpParser\Node\Scalar\String_)) {
			return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
		}

		switch ($arg->value) {
			case 'date':
				return new ObjectType(DateTimeAspect::class);
			case 'visibility':
				return new ObjectType(VisibilityAspect::class);
			case 'backend.user':
			case 'frontend.user':
				return new ObjectType(UserAspect::class);
			case 'workspace':
				return new ObjectType(WorkspaceAspect::class);
			case 'language':
				return new ObjectType(LanguageAspect::class);
			case 'typoscript':
				return new ObjectType(TypoScriptAspect::class);
			default:
				return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
		}
	}

}<commit_msg>Use FQCN instead of use statements to allow compatibility with TYPO 8.7<commit_after><?php declare(strict_types = 1);

namespace SaschaEgerer\PhpstanTypo3\Type;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;

class ContextDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{

	public function getClass(): string
	{
		return \TYPO3\CMS\Core\Context\Context::class;
	}

	public function isMethodSupported(
		MethodReflection $methodReflection
	): bool
	{
		return $methodReflection->getName() === 'getAspect';
	}

	public function getTypeFromMethodCall(
		MethodReflection $methodReflection,
		MethodCall $methodCall,
		Scope $scope
	): Type
	{
		$arg = $methodCall->args[0]->value;
		if (!($arg instanceof \PhpParser\Node\Scalar\String_)) {
			return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
		}

		switch ($arg->value) {
			case 'date':
				return new ObjectType(\TYPO3\CMS\Core\Context\DateTimeAspect::class);
			case 'visibility':
				return new ObjectType(\TYPO3\CMS\Core\Context\VisibilityAspect::class);
			case 'backend.user':
			case 'frontend.user':
				return new ObjectType(\TYPO3\CMS\Core\Context\UserAspect::class);
			case 'workspace':
				return new ObjectType(\TYPO3\CMS\Core\Context\WorkspaceAspect::class);
			case 'language':
				return new ObjectType(\TYPO3\CMS\Core\Context\LanguageAspect::class);
			case 'typoscript':
				return new ObjectType(\TYPO3\CMS\Core\Context\TypoScriptAspect::class);
			default:
				return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
		}
	}

}
{'fraction_non_alphanumeric': 0.11690405804891159, 'fraction_numerical': 0.005912389142703574, 'mean_word_length': 5.622775800711744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6532419', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1143, 'n_words': 211}