Skip to content

Commit b3e71a4

Browse files
damianopetrungarolstrojny
authored andcommitted
refactor: Add leading \ before function invocation to speed up resolving (#176)
* refactor: Add leading \ before function invocation to speed up resolving * ci(travis): Add cs-fixer to travis tests
1 parent 253f018 commit b3e71a4

51 files changed

Lines changed: 133 additions & 125 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build/
33
/vendor
44
composer.lock
55
/.idea/
6+
.php_cs.cache

.php_cs.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setRiskyAllowed(true)
5+
->setRules([
6+
'native_function_invocation' => true,
7+
])
8+
->setFinder(PhpCsFixer\Finder::create()->exclude('tests')->in(__DIR__));

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ matrix:
1212
- php: nightly
1313

1414
before_script: composer install
15-
script: vendor/bin/phpunit --debug
15+
16+
script:
17+
- vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist
18+
- vendor/bin/phpunit --debug

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"php": "~7"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "~6"
21+
"phpunit/phpunit": "~6",
22+
"friendsofphp/php-cs-fixer": "^2.13"
2223
},
2324
"autoload": {
2425
"psr-4": {"Functional\\": "src/Functional"},

src/Functional/Average.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function average($collection)
4040

4141
foreach ($collection as $element) {
4242

43-
if (is_numeric($element)) {
43+
if (\is_numeric($element)) {
4444
$sum += $element;
4545
++$divisor;
4646
}

src/Functional/ButLast.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ function but_last($collection)
3434
{
3535
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
3636

37-
$butLast = is_array($collection) ? $collection : iterator_to_array($collection);
38-
array_pop($butLast);
37+
$butLast = \is_array($collection) ? $collection : \iterator_to_array($collection);
38+
\array_pop($butLast);
3939

4040
return $butLast;
4141
}

src/Functional/CompareObjectHashOn.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
namespace Functional;
2424

25-
use function Functional\compose;
26-
2725
/**
2826
* Returns a comparison function that can be used with e.g. `usort()`
2927
*

src/Functional/Compose.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
namespace Functional;
2424

25-
use function Functional\id;
26-
2725
/**
2826
* Return a new function that composes all functions in $functions into a single callable
2927
*
@@ -34,7 +32,7 @@
3432
*/
3533
function compose(...$functions)
3634
{
37-
return array_reduce(
35+
return \array_reduce(
3836
$functions,
3937
function ($carry, $item) {
4038
return function ($x) use ($carry, $item) {

src/Functional/Concat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
/**
2626
* Concatenates zero or more strings
2727
*
28-
* @param string[] $functions
28+
* @param string[] $strings
2929
* @return string
3030
*/
3131
function concat(string ...$strings)
3232
{
33-
return implode('', $strings);
33+
return \implode('', $strings);
3434
}

src/Functional/Curry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
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 {
42-
if (is_string($function) && strpos($function, '::', 1) !== false) {
42+
if (\is_string($function) && \strpos($function, '::', 1) !== false) {
4343
$reflection = new ReflectionMethod($function);
44-
} elseif (is_array($function) && count($function) === 2) {
44+
} elseif (\is_array($function) && \count($function) === 2) {
4545
$reflection = new ReflectionMethod($function[0], $function[1]);
46-
} elseif (is_object($function) && method_exists($function, '__invoke')) {
46+
} elseif (\is_object($function) && \method_exists($function, '__invoke')) {
4747
$reflection = new ReflectionMethod($function, '__invoke');
4848
} else {
4949
$reflection = new ReflectionFunction($function);

0 commit comments

Comments
 (0)