Skip to content

Commit 7a6dc26

Browse files
alexeyshockovlstrojny
authored andcommitted
PSR-2 code style (#184)
* PSR-2 code style for code and tests * PHP_CodeSniffer config and related code changes, Travis integration * Additiomal fixes after merging
1 parent b3e71a4 commit 7a6dc26

77 files changed

Lines changed: 253 additions & 262 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build/
2-
/phpunit.xml
3-
/vendor
4-
composer.lock
5-
/.idea/
2+
vendor/
63
.php_cs.cache
4+
composer.lock
5+
phpcs.xml
6+
phpunit.xml

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
language: php
22
sudo: false
3+
34
php:
45
- 7.0
56
- 7.1
67
- 7.2
78
- 7.3
89
- nightly
9-
1010
matrix:
1111
allow_failures:
1212
- php: nightly
1313

14-
before_script: composer install
15-
14+
before_script:
15+
- composer install
1616
script:
17-
- vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist
18-
- vendor/bin/phpunit --debug
17+
- composer tests
18+
- composer coding-style

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "~6",
22-
"friendsofphp/php-cs-fixer": "^2.13"
22+
"squizlabs/php_codesniffer": "~3.0",
23+
"friendsofphp/php-cs-fixer": "^2.14"
2324
},
2425
"autoload": {
2526
"psr-4": {"Functional\\": "src/Functional"},
@@ -114,11 +115,9 @@
114115
"autoload-dev": {
115116
"psr-4": {"Functional\\Tests\\": "tests/Functional"}
116117
},
117-
"extra": {
118-
"branch-alias": { "dev-master": "1.2-dev" }
119-
},
120118
"scripts": {
121-
"tests": "phpunit",
119+
"tests": "vendor/bin/phpunit",
120+
"coding-style": "vendor/bin/phpcs && vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist",
122121
"clear": "rm -rf vendor/"
123122
}
124123
}

phpcs.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
name="PHP_CodeSniffer"
4+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
5+
<description>Functional PHP coding style configuration</description>
6+
7+
<file>src</file>
8+
<file>tests</file>
9+
10+
<arg name="colors"/>
11+
<arg value="n"/>
12+
13+
<rule ref="PSR2" />
14+
15+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
16+
<exclude-pattern>tests/*</exclude-pattern>
17+
</rule>
18+
19+
<rule ref="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase">
20+
<exclude-pattern>src/Functional/Functional.php</exclude-pattern>
21+
</rule>
22+
</ruleset>

src/Functional/Average.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ function average($collection)
3939
$divisor = 0;
4040

4141
foreach ($collection as $element) {
42-
4342
if (\is_numeric($element)) {
4443
$sum += $element;
4544
++$divisor;
4645
}
47-
4846
}
4947

5048
if ($sum === null) {

src/Functional/ButLast.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* THE SOFTWARE.
2222
*/
2323
namespace Functional;
24+
2425
use Functional\Exceptions\InvalidArgumentException;
2526
use Traversable;
2627

src/Functional/CompareObjectHashOn.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ function compare_object_hash_on(callable $comparison, callable $keyFunction = nu
3535

3636
return compare_on($comparison, $keyFunction);
3737
}
38-

src/Functional/CompareOn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* THE SOFTWARE.
2222
*/
2323
namespace Functional;
24+
2425
/**
2526
* Returns a comparison function that can be used with e.g. `usort()`
2627
*
@@ -40,4 +41,3 @@ function compare_on(callable $comparison, callable $reducer = null)
4041
return $comparison($reducer($left), $reducer($right));
4142
};
4243
}
43-

src/Functional/Contains.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ function contains($collection, $value, $strict = true)
3939
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
4040

4141
foreach ($collection as $element) {
42-
4342
if ($value === $element || (!$strict && $value == $element)) {
4443
return true;
4544
}
46-
4745
}
4846

4947
return false;

src/Functional/Curry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
function curry(callable $function, $required = true)
3838
{
39-
if (\method_exists('Closure','fromCallable')) {
39+
if (\method_exists('Closure', 'fromCallable')) {
4040
$reflection = new ReflectionFunction(Closure::fromCallable($function));
4141
} else {
4242
if (\is_string($function) && \strpos($function, '::', 1) !== false) {

0 commit comments

Comments
 (0)