Skip to content

Commit

Permalink
Migrate to PHP-CS-Fixer 3.0 (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 12, 2021
1 parent 6c95897 commit 9d104bf
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.php_cs.cache
/.php-cs-fixer.cache
/bin/
/composer.lock
/dist/
Expand Down
23 changes: 11 additions & 12 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
__DIR__.'/tests',
])
->append([
__DIR__.'/.php_cs.dist',
__DIR__.'/.php-cs-fixer.dist.php',
])
->exclude([
'fixtures/Parser/files/php',
'Bridge/Symfony/Application/var',
])
;

return Config::create()
return (new Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'blank_line_before_statement' => true,
'cast_spaces' => true,
'combine_consecutive_unsets' => true,
'declare_equal_normalize' => true,
Expand All @@ -45,13 +45,13 @@
'header_comment' => [
'location' => 'after_open',
'header' => <<<'LICENSE'
This file is part of the Alice package.
(c) Nelmio <hello@nelm.io>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
LICENSE
This file is part of the Alice package.
(c) Nelmio <hello@nelm.io>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
LICENSE,
],
'lowercase_cast' => true,
'general_phpdoc_annotation_remove' => true,
Expand All @@ -60,7 +60,6 @@
'import_constants' => true,
'import_functions' => true,
],
'method_separation' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
Expand All @@ -81,6 +80,7 @@
'ordered_imports' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_order_by_value' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_trim' => true,
Expand All @@ -92,7 +92,6 @@
'php_unit_namespaced' => true,
'php_unit_test_case_static_method_calls' => true,
'php_unit_test_class_requires_covers' => true,
'php_unit_ordered_covers' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function denormalize(array $data): FixtureBag
)
);
}

try {
foreach ($rawFixtureSet as $reference => $specs) {
if (null === $specs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function canParse(Token $token): bool
public function parse(Token $token): ParameterValue
{
$value = $token->getValue();

try {
$paramKey = strlen($value) > 3 ? substr($value, 2, -2) : false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function parse(Token $token): ValueInterface
parent::parse($token);

$value = $token->getValue();

try {
$elements = substr($value, 1, -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor)
public function hydrate(ObjectInterface $object, Property $property, GenerationContext $context): ObjectInterface
{
$instance = $object->getInstance();

try {
$this->propertyAccessor->setValue($instance, $property->getName(), $property->getValue());
} catch (SymfonyNoSuchPropertyException $exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function canInstantiate(FixtureInterface $fixture): bool
protected function createInstance(FixtureInterface $fixture)
{
$class = $fixture->getClassName();

try {
$constructRefl = new ReflectionMethod($class, '__construct');

Expand Down
1 change: 1 addition & 0 deletions src/Generator/NamedArgumentsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function resolveArguments(array $arguments, string $className, string $me
if ($parameter->isVariadic()) {
continue;
}

throw new RuntimeException(sprintf(
'Argument $%s of %s::%s() is not passed a value and does not define a default one.',
$name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function resolve(
// We make use of the underscore prefix (`_`) here to limit the possible conflicts with the variables injected
// in the scope.
$_scope = $scope;

try {
$_scope['current'] = $fixture->getValueForCurrent();

Expand Down
1 change: 1 addition & 0 deletions tests/Definition/Fixture/SimpleFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function testReadAccessorsReturnPropertiesValues(): void
static::assertEquals($reference, $fixture->getId());
static::assertEquals($className, $fixture->getClassName());
static::assertEquals($specs, $fixture->getSpecs());

try {
$fixture->getValueForCurrent();
static::fail('Expected exception to be thrown.');
Expand Down
1 change: 1 addition & 0 deletions tests/Faker/GeneratorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GeneratorFactoryTest extends TestCase
public function testAssertGeneratorLocaleMethod(): void
{
$this->assertGeneratorLocaleIs('en_US', FakerFactory::create());

try {
$this->assertGeneratorLocaleIs('fr_FR', FakerFactory::create());
static::fail('Expected exception to be thrown.');
Expand Down
1 change: 1 addition & 0 deletions tests/Faker/Provider/AliceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testCurrentReturnsFixtureCurrentValue(): void
public function testCurrentThrowsAnExceptionIfFixtureHasNoCurrentValue(): void
{
$fixture = new SimpleFixture('dummy', 'Dummy', SpecificationBagFactory::create());

try {
AliceProvider::current($fixture);
static::fail('Expected exception to be thrown.');
Expand Down
1 change: 1 addition & 0 deletions tests/FixtureBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testReadAccessorsReturnPropertiesValues(): void
static::assertFalse($bag->has('bar'));

static::assertEquals($fixture, $bag->get('foo'));

try {
$bag->get('bar');
static::fail('Expected exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function testWhenParserThrowsExceptionDenormalizerAExceptionIsThrown(): v
$parser = $parserProphecy->reveal();

$denormalizer = new SimpleValueDenormalizer($parser);

try {
$denormalizer->denormalize(new FakeFixture(), null, 'foo');
static::fail('Expected throwable to be thrown.');
Expand Down
1 change: 1 addition & 0 deletions tests/Generator/Instantiator/InstantiatorResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function testThrowsAGenerationThrowableIfResolutionFails(): void
$resolver = $resolverProphecy->reveal();

$instantiator = new InstantiatorResolver(new FakeInstantiator(), $resolver);

try {
$instantiator->instantiate($fixture, $set, new GenerationContext());
static::fail('Expected exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function testReadAccessorsReturnPropertiesValues(): void
static::assertEquals($template, $bag->get($templateId));

static::assertFalse($bag->has('foo'));

try {
$bag->get('foo');
static::fail('Expected exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ function ($args) {
$decoratedResolver = $decoratedResolverProphecy->reveal();

$resolver = new RecursiveParameterResolver($decoratedResolver);

try {
$resolver->resolve($parameter, $unresolvedParameters, $resolvedParameters, $context);
static::fail('Expected exception to be thrown.');
Expand All @@ -320,6 +321,7 @@ function ($args) {
}

$resolver = new RecursiveParameterResolver($decoratedResolver, 10);

try {
$resolver->resolve($parameter, $unresolvedParameters, $resolvedParameters, $context);
static::fail('Expected exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function testChecksIfParameterIsReferencedBeforeTryingToResolveIt(): void
$resolvedParameters = new ParameterBag();

$resolver = new StringParameterResolver();

try {
$resolver->resolve($parameter, $unresolvedParameters, $resolvedParameters);
static::fail('Expected exception to be thrown');
Expand All @@ -169,6 +170,7 @@ public function testChecksIfParameterIsReferencedBeforeTryingToResolveIt(): void
$injectedResolver = $injectedResolverProphecy->reveal();

$resolver = (new StringParameterResolver())->withResolver($injectedResolver);

try {
$resolver->resolve($parameter, $unresolvedParameters, $resolvedParameters);
static::fail('Expected exception to be thrown');
Expand Down
3 changes: 3 additions & 0 deletions tests/Generator/Resolver/ResolvingContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testFactoryMethodCannotTriggerACircularReference(): void
$context->checkForCircularReference('foo');

$context->add('foo');

try {
$context->checkForCircularReference('foo');
static::fail('Expected exception to be thrown.');
Expand All @@ -79,6 +80,7 @@ public function testThrowsAnExceptionWhenACircularReferenceIsDetected(): void
$context->checkForCircularReference('foo');

$context->add('foo');

try {
$context->checkForCircularReference('foo');
static::fail('Expected exception to be thrown.');
Expand All @@ -93,6 +95,7 @@ public function testThrowsAnExceptionWhenACircularReferenceIsDetected(): void
$context->checkForCircularReference('foo');

$context->add('foo');

try {
$context->checkForCircularReference('foo');
static::fail('Expected exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function testVariablesInference(): void
static::assertSame(['foo' => 'bar'], $scope);

$value = new EvaluatedValue('$scope');

try {
$resolver->resolve($value, $fixture, $set, $scope, new GenerationContext());
static::fail('Expected an exception to be thrown.');
Expand Down Expand Up @@ -203,6 +204,7 @@ public function testVariablesInferenceWithCurrent(): void
static::assertEquals($expected, $actual);

$value = new EvaluatedValue('$scope');

try {
$resolver->resolve($value, $fixture, $set, $scope, new GenerationContext());
static::fail('Expected an exception to be thrown.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public function testThrowsIfLimitForGenerationOfUniqueValuesIsReached(): void


$resolver = new UniqueValueResolver($pool, $decoratedResolver);

try {
$resolver->resolve($value, $fixture, $set, $scope, $context);
static::fail('Expected exception to be thrown.');
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/RuntimeCacheParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function testThrowsAnExceptionIfFileCouldNotBeFound(): void
$fileLocator = $fileLocatorProphecy->reveal();

$parser = new RuntimeCacheParser(new FakeParser(), $fileLocator, new FakeIncludeProcessor());

try {
$parser->parse('/nowhere');

Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.3"
"friendsofphp/php-cs-fixer": "^3.0"
},
"config": {
"bin-dir": "bin",
Expand Down

0 comments on commit 9d104bf

Please sign in to comment.