Skip to content

Commit

Permalink
Merge pull request #79 from KnpLabs/refactoring/cs-fixing
Browse files Browse the repository at this point in the history
Apply new cs fixing rule
  • Loading branch information
Antoine Lelaisant authored Oct 2, 2018
2 parents 9526149 + 5419379 commit 2b81721
Show file tree
Hide file tree
Showing 55 changed files with 153 additions and 133 deletions.
43 changes: 26 additions & 17 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<?php

function recur_ksort(&$array) {
foreach ($array as &$value) {
if (is_array($value)) recur_ksort($value);
}
return ksort($array);
}
declare(strict_types=1);

$rules = json_decode(file_get_contents('.php_cs.rules.json'), true);
use PedroTroller\CS\Fixer\Fixers;
use PedroTroller\CS\Fixer\RuleSetFactory;

recur_ksort($rules);

file_put_contents('.php_cs.rules.json', json_encode($rules, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

$config = PhpCsFixer\Config::create()
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules($rules)
->setRules(RuleSetFactory::create()
->symfony(true)
->php(7.0, true)
->pedrotroller(true)
->enable('ordered_imports')
->enable('align_multiline_comment')
->enable('array_indentation')
->enable('no_superfluous_phpdoc_tags')
->enable('binary_operator_spaces', [
'operators' => [
'=' => 'align_single_space_minimal',
'=>' => 'align_single_space_minimal',
],
])
->getRules()
)
->setUsingCache(false)
->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers())
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))
->registerCustomFixers(new Fixers())
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->append([__FILE__])
)
;

return $config;
50 changes: 0 additions & 50 deletions .php_cs.rules.json

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require-dev": {
"fzaninotto/faker": "~1.3",
"leanphp/phpspec-code-coverage": "^4.0",
"pedrotroller/php-cs-custom-fixer": "^2.6",
"pedrotroller/php-cs-custom-fixer": "^2.15",
"pedrotroller/symfony-integration-checker": "~2.0.0",
"phpspec/phpspec": "~4.0",
"phpspec/prophecy": ">=1.7.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DataCollector;

use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler;

use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler;

use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryFactoryBuildingPass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler;

use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryRegistrationPass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DependencyInjection;

use Knp\DictionaryBundle\DependencyInjection\Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\DependencyInjection;

use Knp\DictionaryBundle\DependencyInjection\KnpDictionaryExtension;
Expand Down
15 changes: 8 additions & 7 deletions spec/Knp/DictionaryBundle/Dictionary/CallableDictionarySpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary;

use Exception;
Expand Down Expand Up @@ -40,7 +42,7 @@ function it_is_a_dictionary()
function it_supports_callable_arguments()
{
$this->beConstructedWith('baz', function () {
return call_user_func_array([$this, 'execution'], func_get_args());
return \call_user_func_array([$this, 'execution'], \func_get_args());
}, [['foo' => 2, 'bar' => 1, 'baz' => 0]]);

$this->getValues()->shouldReturn(['foo' => 2, 'bar' => 1, 'baz' => 0]);
Expand Down Expand Up @@ -100,14 +102,13 @@ function it_access_to_value_like_an_array()
Assert::eq($this['baz']->getWrappedObject(), 2);
}

function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access(
$nothing
) {
function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access($nothing)
{
$this->beConstructedWith('foo', function () {
});

$this
->shouldThrow(new InvalidArgumentException('Dictionary callable must return an array or an instance of ArrayAccess'))
->shouldThrow(new InvalidArgumentException('Dictionary callable must return an array or an instance of ArrayAccess.'))
->duringGetValues();
}

Expand All @@ -132,7 +133,7 @@ public function execution()
{
if (false === $this->executed) {
$this->executed = true;
$args = func_get_args();
$args = \func_get_args();

return !empty($args) ? current($args) : [
'foo' => 0,
Expand All @@ -141,6 +142,6 @@ public function execution()
];
}

throw new Exception('Executed twice');
throw new Exception('Executed twice.');
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary;

use ArrayAccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\Factory;

use Knp\DictionaryBundle\Dictionary\Factory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\Factory;

use InvalidArgumentException;
Expand All @@ -19,11 +21,8 @@ function it_is_a_factory()
$this->shouldHaveType(Factory::class);
}

function it_supports_if_one_factory_supports(
Factory $factory1,
Factory $factory2,
Factory $factory3
) {
function it_supports_if_one_factory_supports(Factory $factory1, Factory $factory2, Factory $factory3)
{
$this->addFactory($factory1);
$this->addFactory($factory2);

Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Dictionary/Factory/KeyValueSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\Factory;

use InvalidArgumentException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\Factory;

use InvalidArgumentException;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Dictionary/Factory/ValueSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\Factory;

use InvalidArgumentException;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Dictionary/SimpleDictionarySpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary;

use Knp\DictionaryBundle\Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary;

use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\ValueTransformer;

use Knp\DictionaryBundle\Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Dictionary\ValueTransformer;

use Knp\DictionaryBundle\Dictionary\ValueTransformer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Exception;

use Knp\DictionaryBundle\Exception\DictionaryNotFoundException;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Faker/Provider/DictionarySpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Faker\Provider;

use Knp\DictionaryBundle\Dictionary\DictionaryRegistry;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Form/Type/DictionaryTypeSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Form\Type;

use Knp\DictionaryBundle\Dictionary;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/KnpDictionaryBundleSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle;

use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass;
Expand Down
2 changes: 2 additions & 0 deletions spec/Knp/DictionaryBundle/Twig/DictionaryExtensionSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Twig;

use Knp\DictionaryBundle\Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Validator\Constraints;

use Knp\DictionaryBundle\Validator\Constraints\Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Knp\DictionaryBundle\Validator\Constraints;

use Knp\DictionaryBundle\Dictionary;
Expand All @@ -14,11 +16,8 @@

class DictionaryValidatorSpec extends ObjectBehavior
{
function let(
DictionaryRegistry $dictionaries,
ExecutionContextInterface $context,
Dictionary $dictionary
) {
function let(DictionaryRegistry $dictionaries, ExecutionContextInterface $context, Dictionary $dictionary)
{
$this->beConstructedWith($dictionaries);
$this->initialize($context);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DictionaryBundle\DataCollector;

use Exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DictionaryBundle\DependencyInjection\Compiler;

use Knp\DictionaryBundle\Dictionary;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DictionaryBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
Loading

0 comments on commit 2b81721

Please sign in to comment.