Skip to content

Commit

Permalink
Fix: Run 'composer cs'
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 27, 2019
1 parent 096b413 commit f617186
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ public function getClass(): string

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

/**
* @param MethodReflection $methodReflection
* @param MethodCall $methodCall
* @param Scope $scope
* @return Type
* @param MethodCall $methodCall
* @param Scope $scope
*
* @throws \PHPStan\ShouldNotHappenException
*
* @return Type
*/
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
Expand Down
21 changes: 12 additions & 9 deletions src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

class ProphetProphesizeDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{

/** @var string */
/**
* @var string
*/
private $className;

public function __construct(string $className)
Expand All @@ -31,22 +32,24 @@ public function getClass(): string

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

/**
* @param MethodReflection $methodReflection
* @param MethodCall $methodCall
* @param Scope $scope
* @return Type
* @param MethodCall $methodCall
* @param Scope $scope
*
* @throws \PHPStan\ShouldNotHappenException
*
* @return Type
*/
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
$prophecyType = $parametersAcceptor->getReturnType();

if (\count($methodCall->args) === 0) {
if (0 === \count($methodCall->args)) {
return $prophecyType;
}

Expand All @@ -62,11 +65,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
throw new ShouldNotHappenException();
}

if ($class === 'static') {
if ('static' === $class) {
return $prophecyType;
}

if ($class === 'self' && $scope->getClassReflection() !== null) {
if ('self' === $class && null !== $scope->getClassReflection()) {
$class = $scope->getClassReflection()->getName();
}

Expand Down
13 changes: 8 additions & 5 deletions src/PhpDoc/TypeNodeResolverExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

class TypeNodeResolverExtension implements \PHPStan\PhpDoc\TypeNodeResolverExtension, TypeNodeResolverAwareExtension
{

/** @var TypeNodeResolver */
/**
* @var TypeNodeResolver
*/
private $typeNodeResolver;

public function setTypeNodeResolver(TypeNodeResolver $typeNodeResolver): void
Expand All @@ -34,13 +35,15 @@ public function resolve(TypeNode $typeNode, NameScope $nameScope): ?Type
return null;
}

if (count($typeNode->types) === 2) {
if (2 === \count($typeNode->types)) {
$objectProphecyType = null;
$prophesizedType = null;

foreach ($typeNode->types as $innerType) {
$type = $this->typeNodeResolver->resolve($innerType, $nameScope);

if ($type instanceof TypeWithClassName) {
if ($type->getClassName() === ObjectProphecy::class) {
if (ObjectProphecy::class === $type->getClassName()) {
$objectProphecyType = $type;
} else {
$prophesizedType = $type;
Expand All @@ -50,7 +53,7 @@ public function resolve(TypeNode $typeNode, NameScope $nameScope): ?Type
}
}

if ($objectProphecyType !== null && $prophesizedType !== null) {
if (null !== $objectProphecyType && null !== $prophesizedType) {
return new ObjectProphecyType($prophesizedType->getClassName());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ProphecyMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
{
// don't know which class is prophesized here, so let's say yes to every method
// must match class in MockBuilderType parent::__construct() equivalent
return $classReflection->getName() === 'Prophecy\Prophecy\ObjectProphecy';
return 'Prophecy\Prophecy\ObjectProphecy' === $classReflection->getName();
}

public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
Expand Down
21 changes: 11 additions & 10 deletions src/Type/ObjectProphecyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ public function __construct(string $prophesizedClass)
parent::__construct('Prophecy\Prophecy\ObjectProphecy');
}

public function describe(VerbosityLevel $level): string
{
return sprintf('%s<%s>', parent::describe($level), $this->prophesizedClass);
}

public function getProphesizedClass(): string
{
return $this->prophesizedClass;
}

/**
* @param mixed[] $properties
*
* @return self
*/
public static function __set_state(array $properties): Type
{
return new self($properties['prophesizedClass']);
}

public function describe(VerbosityLevel $level): string
{
return \sprintf('%s<%s>', parent::describe($level), $this->prophesizedClass);
}

public function getProphesizedClass(): string
{
return $this->prophesizedClass;
}
}
18 changes: 11 additions & 7 deletions tests/Test/BaseModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
use Prophecy\Prophecy\ObjectProphecy;
use Tests\Model\BaseModel;

class BaseModelTest extends TestCase
/**
* @internal
* @coversNothing
*/
final class BaseModelTest extends TestCase
{
/**
* @var BaseModel|ObjectProphecy
Expand All @@ -21,8 +25,8 @@ public function testBasicProperty(): void
$subject = new BaseModel();
$subject->setFoo($word);

$this->assertEquals($word, $subject->getFoo());
$this->assertEquals(4, $subject->doubleTheNumber(2));
self::assertEquals($word, $subject->getFoo());
self::assertEquals(4, $subject->doubleTheNumber(2));
}

public function testWithProphecy(): void
Expand All @@ -32,8 +36,8 @@ public function testWithProphecy(): void

$subject->doubleTheNumber(Argument::is(2))->willReturn(5);

$this->assertEquals('bar', $subject->reveal()->getFoo());
$this->assertEquals(5, $subject->reveal()->doubleTheNumber(2));
self::assertEquals('bar', $subject->reveal()->getFoo());
self::assertEquals(5, $subject->reveal()->doubleTheNumber(2));
}

/**
Expand All @@ -51,7 +55,7 @@ public function testProphesizedAttributesShouldAlsoWork(): void

$subject = $this->subject->reveal();

$this->assertEquals('bar', $subject->getFoo());
$this->assertEquals(5, $subject->doubleTheNumber(2));
self::assertEquals('bar', $subject->getFoo());
self::assertEquals(5, $subject->doubleTheNumber(2));
}
}

0 comments on commit f617186

Please sign in to comment.