Skip to content

Commit

Permalink
chore: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Feb 12, 2020
1 parent 636254d commit 3fa7a87
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/PHPStan/Type/Helper.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\PHPStan\Type;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\MethodReflection;

final class Helper
{
public static function getTranslationClass(Broker $broker, MethodCall $methodCall, Scope $scope): string
{
$type = $scope->getType($methodCall->var);
$type = $scope->getType($methodCall->var);
$translatableClass = $type->getReferencedClasses()[0];

return $broker
Expand All @@ -23,7 +24,7 @@ public static function getTranslationClass(Broker $broker, MethodCall $methodCal

public static function getTranslatableClass(Broker $broker, MethodCall $methodCall, Scope $scope): string
{
$type = $scope->getType($methodCall->var);
$type = $scope->getType($methodCall->var);
$translatableClass = $type->getReferencedClasses()[0];

return $broker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Knp\DoctrineBehaviors\PHPStan\Type;

use Doctrine\Common\Collections\Collection;
use function in_array;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
Expand All @@ -15,11 +16,14 @@
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

final class TranslatableGetTranslationsDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension
{
/** @var Broker */
/**
* @var Broker
*/
private $broker;

public function setBroker(Broker $broker): void
Expand All @@ -34,11 +38,14 @@ public function getClass(): string

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return \in_array($methodReflection->getName(), ['getTranslations', 'getNewTranslations'], true);
return in_array($methodReflection->getName(), ['getTranslations', 'getNewTranslations'], true);
}

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type
{
public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): Type {
$translationClass = Helper::getTranslationClass($this->broker, $methodCall, $scope);

return TypeCombinator::intersect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;

final class TranslatableTranslateDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension
{
/** @var Broker */
/**
* @var Broker
*/
private $broker;

public function setBroker(Broker $broker): void
Expand All @@ -30,11 +33,14 @@ public function getClass(): string

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

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type
{
public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): Type {
$translationClass = Helper::getTranslationClass($this->broker, $methodCall, $scope);

return new ObjectType($translationClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;

final class TranslationGetTranslatableDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension
{
/** @var Broker */
/**
* @var Broker
*/
private $broker;

public function setBroker(Broker $broker): void
Expand All @@ -30,11 +33,14 @@ public function getClass(): string

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

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type
{
public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): Type {
$translatableClass = Helper::getTranslatableClass($this->broker, $methodCall, $scope);

return new ObjectType($translatableClass);
Expand Down
1 change: 0 additions & 1 deletion tests/ORM/TranslatableInheritanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Knp\DoctrineBehaviors\Tests\ORM;

use Doctrine\Persistence\ObjectRepository;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Tests\AbstractBehaviorTestCase;
use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\ExtendedTranslatableEntity;

Expand Down

0 comments on commit 3fa7a87

Please sign in to comment.