Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PHP-CS-Fixer #613

Merged
merged 14 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ jobs:
php-version: "${{ matrix.php }}"
coverage: none

- name: Remove PHP-CS-Fixer from dependencies
run: COMPOSER_ROOT_VERSION=dev-master composer remove --dev friendsofphp/php-cs-fixer --no-update

- name: Install dependencies
run: COMPOSER_ROOT_VERSION=dev-master composer update ${{ matrix.composer-flags }}
run: COMPOSER_ROOT_VERSION=dev-master composer update ${{ matrix.composer-flags }} --no-scripts
id: end-of-setup

- name: Run tests (phpspec)
Expand All @@ -59,5 +62,19 @@ jobs:
php-version: "8.2"
coverage: none
- name: Install dependencies
run: COMPOSER_ROOT_VERSION=dev-master composer update
run: COMPOSER_ROOT_VERSION=dev-master composer update --no-scripts
- run: ./vendor/bin/phpstan

coding-standards:
runs-on: ubuntu-latest
name: Coding standards
steps:
- uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
coverage: none
- name: Install dependencies
run: COMPOSER_ROOT_VERSION=dev-master composer update --no-scripts
- run: composer cs:check -- --ansi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.tgz
*.phar
/.php-cs-fixer.cache
/composer.lock
/dev-tools/vendor/
/vendor
/phpstan.neon
/phpunit.xml
Expand Down
26 changes: 26 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRules([
'@PER-CS' => true,
'braces_position' => [
'control_structures_opening_brace' => 'same_line',
],
'concat_space' => ['spacing' => 'none'],
'method_argument_space' => ['on_multiline' => 'ignore'],
// Since PHP 7.2 is supported we can't add trailing commas in arguments, parameters and match
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'visibility_required' => false,
])
->setFinder(
(new PhpCsFixer\Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->exclude(['fixtures'])
->notPath(['phpstan-baseline.php'])
->in(__DIR__)
)
;
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},

"require-dev": {
"friendsofphp/php-cs-fixer": "^3.40",
"phpspec/phpspec": "^6.0 || ^7.0",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^8.0 || ^9.0 || ^10.0"
Expand All @@ -45,11 +46,15 @@
},

"scripts": {
"cs:check": "@php php-cs-fixer check --verbose --diff",
"cs:fix": "@php php-cs-fixer fix",
"phpstan": "phpstan analyse",
"phpstan:baseline": "phpstan analyse --generate-baseline"
},

"scripts-descriptions": {
"cs:check": "Check coding standards",
"cs:fix": "Fix coding standards",
"phpstan": "Run PHPStan analysis",
"phpstan:baseline": "Dump PHPStan baseline file - use only for updating, do not add new errors when possible"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/Prophecy/Argument/Token/ArrayCountTokenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function it_does_not_score_if_argument_is_neither_array_nor_countable_object()
{
$this->scoreArgument('string')->shouldBe(false);
$this->scoreArgument(5)->shouldBe(false);
$this->scoreArgument(new \stdClass)->shouldBe(false);
$this->scoreArgument(new \stdClass())->shouldBe(false);
}

function it_does_not_score_if_argument_array_has_wrong_count()
Expand Down
10 changes: 5 additions & 5 deletions spec/Prophecy/Argument/Token/ArrayEntryTokenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function it_scores_array_half_of_combined_scores_from_key_and_value_tokens($key,
{
$key->scoreArgument('key')->willReturn(4);
$value->scoreArgument('value')->willReturn(6);
$this->scoreArgument(array('key'=>'value'))->shouldBe(5);
$this->scoreArgument(array('key' => 'value'))->shouldBe(5);
}

function it_scores_traversable_object_half_of_combined_scores_from_key_and_value_tokens(
Expand Down Expand Up @@ -82,7 +82,7 @@ function it_throws_exception_during_scoring_of_array_accessible_object_if_key_is
\ArrayAccess $object
) {
$key->__toString()->willReturn('any_token');
$this->beConstructedWith($key,$value);
$this->beConstructedWith($key, $value);
$errorMessage = 'You can only use exact value tokens to match key of ArrayAccess object'.PHP_EOL.
'But you used `any_token`.';
$this->shouldThrow(new InvalidArgumentException($errorMessage))->duringScoreArgument($object);
Expand Down Expand Up @@ -116,13 +116,13 @@ function it_accepts_any_key_token_type_to_score_object_that_is_both_traversable_
(\PHP_VERSION_ID < 80100) ? $object->rewind()->willReturn(null) : $object->rewind()->shouldBeCalled();
(\PHP_VERSION_ID < 80100) ? $object->next()->willReturn(null) : $object->next()->shouldBeCalled();
$object->valid()->willReturn(true);
$this->shouldNotThrow(new InvalidArgumentException)->duringScoreArgument($object);
$this->shouldNotThrow(new InvalidArgumentException())->duringScoreArgument($object);
}

function it_does_not_score_if_argument_is_neither_array_nor_traversable_nor_array_accessible()
{
$this->scoreArgument('string')->shouldBe(false);
$this->scoreArgument(new \stdClass)->shouldBe(false);
$this->scoreArgument(new \stdClass())->shouldBe(false);
}

function it_does_not_score_empty_array()
Expand Down Expand Up @@ -197,6 +197,6 @@ function its_score_is_capped_at_8($key, $value)
{
$key->scoreArgument('key')->willReturn(10);
$value->scoreArgument('value')->willReturn(10);
$this->scoreArgument(array('key'=>'value'))->shouldBe(8);
$this->scoreArgument(array('key' => 'value'))->shouldBe(8);
}
}
2 changes: 1 addition & 1 deletion spec/Prophecy/Argument/Token/ArrayEveryEntryTokenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function it_wraps_non_token_value_into_ExactValueToken(\stdClass $stdClass)
function it_does_not_score_if_argument_is_neither_array_nor_traversable()
{
$this->scoreArgument('string')->shouldBe(false);
$this->scoreArgument(new \stdClass)->shouldBe(false);
$this->scoreArgument(new \stdClass())->shouldBe(false);
}

function it_does_not_score_empty_array()
Expand Down
4 changes: 2 additions & 2 deletions spec/Prophecy/Argument/Token/ExactValueTokenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function it_generates_proper_string_representation_for_object(\stdClass $object)
$objHash = sprintf('exact(%s#%s',
get_class($object->getWrappedObject()),
spl_object_id($object->getWrappedObject())
) . " Object (\n 'objectProphecyClosure' => Closure#%s Object (\n 0 => Closure#%s Object\n )\n))";
)." Object (\n 'objectProphecyClosure' => Closure#%s Object (\n 0 => Closure#%s Object\n )\n))";

$this->beConstructedWith($object);

Expand Down Expand Up @@ -164,7 +164,7 @@ function it_does_not_scores_if_value_an_numeric_and_equal_to_argument_as_stringa

function it_does_not_scores_if_value_an_object_and_not_equal_to_argument_object()
{
$value = new ExactValueTokenFixtureA;
$value = new ExactValueTokenFixtureA();
$argument = new ExactValueTokenC("example");

$this->beConstructedWith($value);
Expand Down
2 changes: 1 addition & 1 deletion spec/Prophecy/Argument/Token/IdenticalValueTokenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function it_generates_proper_string_representation_for_object($object)
$objHash = sprintf('identical(%s#%s',
get_class($object->getWrappedObject()),
spl_object_id($object->getWrappedObject())
) . " Object (\n 'objectProphecyClosure' => Closure#%s Object (\n 0 => Closure#%s Object\n )\n))";
)." Object (\n 'objectProphecyClosure' => Closure#%s Object (\n 0 => Closure#%s Object\n )\n))";

$this->beConstructedWith($object);

Expand Down
13 changes: 5 additions & 8 deletions spec/Prophecy/Call/CallCenterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

class CallCenterSpec extends ObjectBehavior
{
function let(ObjectProphecy $objectProphecy)
{
}
function let(ObjectProphecy $objectProphecy) {}

function it_records_calls_made_through_makeCall_method(ObjectProphecy $objectProphecy, ArgumentsWildcard $wildcard)
{
Expand All @@ -33,8 +31,7 @@ function it_records_calls_made_through_makeCall_method(ObjectProphecy $objectPro

function it_returns_null_for_any_call_through_makeCall_if_no_method_prophecies_added(
$objectProphecy
)
{
) {
$objectProphecy->getMethodProphecies()->willReturn(array());

$this->makeCall($objectProphecy, 'setValues', array(5, 2, 3))->shouldReturn(null);
Expand Down Expand Up @@ -68,7 +65,7 @@ function it_executes_promise_of_method_prophecy_that_matches_signature_passed_to

$objectProphecy->getMethodProphecies()->willReturn(array(
'method1' => array($method1),
'method2' => array($method2, $method3)
'method2' => array($method2, $method3),
));
$objectProphecy->getMethodProphecies('getName')->willReturn(array($method1, $method3));
$objectProphecy->reveal()->willReturn(new \stdClass());
Expand Down Expand Up @@ -110,10 +107,10 @@ function it_executes_promise_of_method_prophecy_that_matches_with_highest_score_

$objectProphecy->getMethodProphecies()->willReturn(array(
'method1' => array($method1),
'method2' => array($method2, $method3)
'method2' => array($method2, $method3),
));
$objectProphecy->getMethodProphecies('getName')->willReturn(array(
$method1, $method2, $method3
$method1, $method2, $method3,
));
$objectProphecy->reveal()->willReturn(new \stdClass());

Expand Down
12 changes: 6 additions & 6 deletions spec/Prophecy/Comparator/ClosureComparatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ function it_accepts_only_closures()
$this->accepts('string', 'string')->shouldReturn(false);
$this->accepts(false, true)->shouldReturn(false);
$this->accepts(true, false)->shouldReturn(false);
$this->accepts((object)array(), (object)array())->shouldReturn(false);
$this->accepts(function(){}, (object)array())->shouldReturn(false);
$this->accepts(function(){}, (object)array())->shouldReturn(false);
$this->accepts((object) array(), (object) array())->shouldReturn(false);
$this->accepts(function () {}, (object) array())->shouldReturn(false);
$this->accepts(function () {}, (object) array())->shouldReturn(false);

$this->accepts(function(){}, function(){})->shouldReturn(true);
$this->accepts(function () {}, function () {})->shouldReturn(true);
}

function it_asserts_that_different_closures_are_different()
{
$this->shouldThrow()->duringAssertEquals(function(){}, function(){});
$this->shouldThrow()->duringAssertEquals(function () {}, function () {});
}

function it_asserts_that_closures_are_equal_if_its_the_same_closure()
{
$closure = function(){};
$closure = function () {};

$this->shouldNotThrow()->duringAssertEquals($closure, $closure);
}
Expand Down
2 changes: 1 addition & 1 deletion spec/Prophecy/Comparator/FactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function it_extends_Sebastian_Comparator_Factory()

function it_should_have_ClosureComparator_registered()
{
$comparator = $this->getInstance()->getComparatorFor(function(){}, function(){});
$comparator = $this->getInstance()->getComparatorFor(function () {}, function () {});
$comparator->shouldHaveType('Prophecy\Comparator\ClosureComparator');
}
}
6 changes: 3 additions & 3 deletions spec/Prophecy/Comparator/ProphecyComparatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function it_accepts_only_prophecy_objects()
$this->accepts('string', 'string')->shouldReturn(false);
$this->accepts(false, true)->shouldReturn(false);
$this->accepts(true, false)->shouldReturn(false);
$this->accepts((object)array(), (object)array())->shouldReturn(false);
$this->accepts(function(){}, (object)array())->shouldReturn(false);
$this->accepts(function(){}, function(){})->shouldReturn(false);
$this->accepts((object) array(), (object) array())->shouldReturn(false);
$this->accepts(function () {}, (object) array())->shouldReturn(false);
$this->accepts(function () {}, function () {})->shouldReturn(false);

$prophet = new Prophet();
$prophecy = $prophet->prophesize('Prophecy\Prophecy\ObjectProphecy');
Expand Down
4 changes: 1 addition & 3 deletions spec/Prophecy/Doubler/CachedDoublerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,4 @@ function it_creates_two_different_class_definitions_for_the_same_class_with_same
}
}

class aClass
{
}
class aClass {}
28 changes: 6 additions & 22 deletions spec/Prophecy/Doubler/ClassPatch/MagicCallPatchSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,28 @@ class MagicalApi
/**
* @return void
*/
public function definedMethod()
{

}
public function definedMethod() {}
}

/**
* @method
*/
class MagicalApiInvalidMethodDefinition
{
}
class MagicalApiInvalidMethodDefinition {}

/**
* @method void definedMethod()
*/
class MagicalApiExtended extends MagicalApi
{

}
class MagicalApiExtended extends MagicalApi {}

/**
*/
class MagicalApiImplemented implements MagicalApiInterface
{

}
class MagicalApiImplemented implements MagicalApiInterface {}

/**
*/
class MagicalApiImplementedExtended extends MagicalApiImplemented
{
}
class MagicalApiImplementedExtended extends MagicalApiImplemented {}

/**
* @method void implementedMethod()
*/
interface MagicalApiInterface
{

}
interface MagicalApiInterface {}
6 changes: 3 additions & 3 deletions spec/Prophecy/Doubler/ClassPatch/SplFileInfoPatchSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function it_should_not_supply_a_file_for_a_directory_iterator(ClassNode $node, M
$node->getMethod('__construct')->willReturn($method);
$node->getParentClass()->willReturn('DirectoryIterator');

$method->setCode(Argument::that(function($value) {
$method->setCode(Argument::that(function ($value) {
return strpos($value, '.php') === false;
}))->shouldBeCalled();

Expand All @@ -76,7 +76,7 @@ function it_should_supply_a_file_for_a_spl_file_object(ClassNode $node, MethodNo
$node->getMethod('__construct')->willReturn($method);
$node->getParentClass()->willReturn('SplFileObject');

$method->setCode(Argument::that(function($value) {
$method->setCode(Argument::that(function ($value) {
return strpos($value, '.php') !== false;
}))->shouldBeCalled();

Expand All @@ -89,7 +89,7 @@ function it_should_supply_a_file_for_a_symfony_spl_file_info(ClassNode $node, Me
$node->getMethod('__construct')->willReturn($method);
$node->getParentClass()->willReturn('Symfony\\Component\\Finder\\SplFileInfo');

$method->setCode(Argument::that(function($value) {
$method->setCode(Argument::that(function ($value) {
return strpos($value, '.php') !== false;
}))->shouldBeCalled();

Expand Down
Loading