Skip to content

Commit

Permalink
Upgrade PHPStan (#1033)
Browse files Browse the repository at this point in the history
- Upgrade to PHPStan 0.12
- Fix a few errors reported
  • Loading branch information
theofidry authored May 15, 2020
2 parents 8e83109 + cda58df commit fd8f9a4
Show file tree
Hide file tree
Showing 35 changed files with 41 additions and 370 deletions.
5 changes: 2 additions & 3 deletions fixtures/Definition/Object/ImmutableByCloneObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class ImmutableByCloneObject implements ObjectInterface

/**
* @param string $id
* @param object $instance
*/
public function __construct(string $id, $instance)
public function __construct(string $id, object $instance)
{
$this->id = $id;
$this->instance = $instance;
Expand All @@ -56,7 +55,7 @@ public function getInstance()
/**
* @inheritdoc
*/
public function withInstance($newInstance)
public function withInstance(object $newInstance)
{
return new self($this->id, $newInstance);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Object/CompleteObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getInstance()
/**
* @inheritdoc
*/
public function withInstance($newInstance)
public function withInstance(object $newInstance)
{
throw new LogicException('Cannot create a new object from a complete object.');
}
Expand Down
10 changes: 1 addition & 9 deletions src/Definition/Object/SimpleObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Nelmio\Alice\Definition\Object;

use Nelmio\Alice\ObjectInterface;
use Nelmio\Alice\Throwable\Error\TypeErrorFactory;

/**
* Minimalist implementation of ObjectInterface.
Expand All @@ -31,15 +30,8 @@ final class SimpleObject implements ObjectInterface
*/
private $instance;

/**
* @param object $instance
*/
public function __construct(string $id, $instance)
public function __construct(string $id, object $instance)
{
if (false === is_object($instance)) {
throw TypeErrorFactory::createForObjectArgument($instance);
}

$this->reference = $id;
$this->instance = $instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ private function resolveReferredFixture(
$fixtureSet
);
} catch (CircularReferenceException $exception) {
if (false === $needsCompleteGeneration && null !== $passIncompleteObject) {
if (!isset($needsCompleteGeneration)
|| (false === $needsCompleteGeneration && null !== $passIncompleteObject)
) {
throw $exception;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Loader/NativeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
* @method GeneratorInterface getGenerator()
* @method ParserInterface getParser()
* @method DenormalizerInterface getDenormalizer()
* @method FixtureBagDenormalizerInterface getFixtureBagDenormalizer
* @method FixtureBagDenormalizerInterface getFixtureBagDenormalizer()
* @method FixtureDenormalizerInterface getFixtureDenormalizer()
* @method FlagParserInterface getFlagParser()
* @method ConstructorDenormalizerInterface getConstructorDenormalizer()
Expand Down
3 changes: 1 addition & 2 deletions src/Loader/SimpleFilesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Nelmio\Alice\IsAServiceTrait;
use Nelmio\Alice\ObjectSet;
use Nelmio\Alice\Parser\IncludeProcessor\IncludeDataMerger;
use Nelmio\Alice\Parser\IncludeProcessorInterface;
use Nelmio\Alice\ParserInterface;

final class SimpleFilesLoader implements FilesLoaderInterface
Expand All @@ -31,7 +30,7 @@ final class SimpleFilesLoader implements FilesLoaderInterface
private $dataLoader;

/**
* @var IncludeProcessorInterface
* @var IncludeDataMerger
*/
private $dataMerger;

Expand Down
4 changes: 1 addition & 3 deletions src/ObjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public function getId(): string;
public function getInstance();

/**
* @param object $newInstance
*
* @return static
*/
public function withInstance($newInstance);
public function withInstance(object $newInstance);
}
3 changes: 0 additions & 3 deletions src/Parser/IncludeProcessor/DefaultIncludeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public function process(ParserInterface $parser, string $file, array $data): arr
return $this->dataMerger->mergeInclude($data, $includeData);
}

/**
* @param string[] $include
*/
private function retrieveIncludeData(ParserInterface $parser, string $file, array $include): array
{
$data = [];
Expand Down
10 changes: 0 additions & 10 deletions src/Throwable/Error/TypeErrorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
*/
final class TypeErrorFactory
{
public static function createForObjectArgument($instance): TypeError
{
return new TypeError(
sprintf(
'Expected instance argument to be an object. Got "%s" instead.',
gettype($instance)
)
);
}

public static function createForDynamicArrayQuantifier($quantifier): TypeError
{
return new TypeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public static function createForCouldNotGetConstructorData(
);
}

/**
* @param object $instance
*/
public static function createForInvalidInstanceType(FixtureInterface $fixture, $instance): InstantiationException
public static function createForInvalidInstanceType(FixtureInterface $fixture, ?object $instance): InstantiationException
{
return new InstantiationException(
sprintf(
Expand Down
4 changes: 3 additions & 1 deletion src/Throwable/LoadingThrowable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Nelmio\Alice\Throwable;

interface LoadingThrowable
use Throwable;

interface LoadingThrowable extends Throwable
{
}
2 changes: 1 addition & 1 deletion tests/Definition/Fixture/TemplatingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class TemplatingTest extends TestCase
{
/**
* @depends Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable
* @depends \Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable
*/
public function testIsImmutable()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Definition/Object/CompleteObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Nelmio\Alice\ObjectInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use stdClass;

/**
* @covers \Nelmio\Alice\Definition\Object\CompleteObject
Expand Down Expand Up @@ -129,6 +130,6 @@ public function testCannotCreateANewInstance()
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot create a new object from a complete object.');

$object->withInstance(null);
$object->withInstance(new stdClass());
}
}
21 changes: 0 additions & 21 deletions tests/Definition/Object/SimpleObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,4 @@ public function testNamedConstructor()
$this->assertEquals(new SimpleObject($reference, $originalInstance), $object);
$this->assertEquals(new SimpleObject($reference, $originalNewInstance), $newObject);
}

/**
* @dataProvider provideInvalidInstances
*/
public function testThrowsAnErrorIfInstanceIsNotAnObject($instance)
{
$this->expectException(\TypeError::class);
$this->expectExceptionMessageMatches('/^Expected instance argument to be an object. Got ".+?" instead\.$/');

new SimpleObject('user0', $instance);
}

public function provideInvalidInstances()
{
return [
'null' => [null],
'string' => ['string value'],
'int' => [10],
'float' => [1.01],
];
}
}
4 changes: 2 additions & 2 deletions tests/Definition/Value/FixtureMethodCallValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function testReadAccessorsReturnPropertiesValues()
}

/**
* @depends Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable
* @depends Nelmio\Alice\Definition\Value\FunctionCallValueTest::testIsImmutable
* @depends \Nelmio\Alice\Definition\ServiceReference\FixtureReferenceTest::testIsImmutable
* @depends \Nelmio\Alice\Definition\Value\FunctionCallValueTest::testIsImmutable
*/
public function testIsImmutable()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Definition/Value/FixturePropertyValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testReadAccessorsReturnPropertiesValues()
}

/**
* @depends Nelmio\Alice\Definition\Value\FixtureReferenceValueTest::testIsImmutable
* @depends \Nelmio\Alice\Definition\Value\FixtureReferenceValueTest::testIsImmutable
*/
public function testIsImmutable()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FixtureBuilder/BareFixtureSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testReadAccessorsReturnPropertiesValues()
}

/**
* @depends Nelmio\Alice\ParameterBagTest::testIsImmutable
* @depends Nelmio\Alice\FixtureBagTest::testIsImmutable
* @depends \Nelmio\Alice\ParameterBagTest::testIsImmutable
* @depends \Nelmio\Alice\FixtureBagTest::testIsImmutable
*/
public function testIsImmutable()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/FixtureBuilder/ExpressionLanguage/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testReadAccessorsReturnPropertiesValues()
}

/**
* @depends Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenTypeTest::testIsImmutable
* @depends \Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenTypeTest::testIsImmutable
*/
public function testIsImmutable()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Generator/Instantiator/InstantiatorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public function testPassValueResolverAwarenessPropertyToItsInstantiator()
$newRegistry = $registry->withValueResolver($resolver);

$this->assertEquals(new InstantiatorRegistry([]), $registry);
$this->assertEquals(new InstantiatorRegistry([], $resolver), $newRegistry);
$this->assertEquals(new InstantiatorRegistry([]), $newRegistry);


$registry = new InstantiatorRegistry([new FakeChainableInstantiator()]);
$newRegistry = $registry->withValueResolver($resolver);

$this->assertEquals(new InstantiatorRegistry([new FakeChainableInstantiator()]), $registry);
$this->assertEquals(
new InstantiatorRegistry([new FakeChainableInstantiator()], $resolver),
new InstantiatorRegistry([new FakeChainableInstantiator()]),
$newRegistry
);

Expand All @@ -94,7 +94,7 @@ public function testPassValueResolverAwarenessPropertyToItsInstantiator()

$this->assertEquals(new InstantiatorRegistry([$nonAwareInstantiator, $instantiator]), $registry);
$this->assertEquals(
new InstantiatorRegistry([$nonAwareInstantiator, new FakeChainableInstantiator()], $resolver),
new InstantiatorRegistry([$nonAwareInstantiator, new FakeChainableInstantiator()]),
$newRegistry
);

Expand Down
Loading

0 comments on commit fd8f9a4

Please sign in to comment.