Skip to content

Commit

Permalink
CS improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Mar 14, 2020
1 parent 220c69e commit d743b82
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 188 deletions.
41 changes: 14 additions & 27 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -36,40 +36,27 @@ EOF;
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'header_comment' => ['commentType' => 'PHPDoc', 'header' => $header, 'separate' => 'bottom', 'location' => 'after_open'],

'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'explicit_indirect_variable' => true,
'no_superfluous_elseif' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,

'ordered_class_elements' => false,
'non_printable_character' => true,
'ordered_imports' => true,
'php_unit_test_class_requires_covers' => true,
'php_unit_strict' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'visibility_required' => true,
'header_comment' => ['header' => $header, 'separate' => 'bottom', 'location' => 'after_open'],
'ternary_to_null_coalescing' => true,
'yoda_style' => true,
'phpdoc_to_comment' => false,
'strict_comparison' => true,
'is_null' => true,
'function_to_constant' => true,
'void_return' => false,
'return_assignment' => true,
'array_syntax' => ['syntax' => 'short'],
'array_indentation' => true,
'native_function_invocation' => null,
'comment_to_phpdoc' => true,
'native_function_invocation' => true,
'php_unit_test_case_static_method_calls' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->in(__DIR__)
->append([__FILE__])
)
;
14 changes: 7 additions & 7 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,7 +24,7 @@

// wrap an initial generator with a pipeline
$pipeline = map(function () {
foreach (range(1, 3) as $value) {
foreach (\range(1, 3) as $value) {
yield $value;
}
});
Expand Down Expand Up @@ -69,11 +69,11 @@
return $carry + $valuetem;
}, 0);

var_dump($value);
\var_dump($value);
// int(104)

$sum = take([1, 2, 3])->reduce();
var_dump($sum);
\var_dump($sum);
// int(6)

// now with League\Pipeline
Expand All @@ -86,8 +86,8 @@
$pipeline = new \Pipeline\Standard(new \ArrayIterator([10, 20, 30]));
$pipeline->map($leaguePipeline);

$result = iterator_to_array($pipeline);
var_dump($result);
$result = \iterator_to_array($pipeline);
\var_dump($result);
// array(3) {
// [0] =>
// int(22)
Expand All @@ -111,7 +111,7 @@
});

$arrayResult = $pipeline->toArray();
var_dump($arrayResult);
\var_dump($arrayResult);
// Since keys are discarded we get:
// array(4) {
// [0] =>
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/PrincipalPipeline.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/StandardPipeline.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -63,7 +63,7 @@ public function filter(callable $func = null);
* @param ?callable $func {@inheritdoc}
* @param ?mixed $initial {@inheritdoc}
*
* @return mixed|null
* @return null|mixed
*/
public function reduce(callable $func = null, $initial = null);

Expand Down
5 changes: 3 additions & 2 deletions src/Principal.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -82,6 +82,7 @@ private static function apply(iterable $previous, callable $func): \Generator
$result = $func($value);
if ($result instanceof \Generator) {
yield from $result;

continue;
}

Expand Down Expand Up @@ -163,7 +164,7 @@ public function toArray(): array
* @param callable $func {@inheritdoc}
* @param mixed $initial {@inheritdoc}
*
* @return mixed|null
* @return null|mixed
*/
public function reduce(callable $func, $initial)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Standard.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
20 changes: 11 additions & 9 deletions tests/ArraysTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -23,22 +23,24 @@
use Pipeline\Standard;

/**
* @covers \Pipeline\Standard
* @covers \Pipeline\Principal
* @covers \Pipeline\Standard
*
* @internal
*/
class ArraysTest extends TestCase
final class ArraysTest extends TestCase
{
public function testInitialCallbackNotGenerator()
public function testInitialCallbackNotGenerator(): void
{
$pipeline = new Standard();
$pipeline->map(function () {
return PHP_INT_MAX;
});

$this->assertSame([PHP_INT_MAX], iterator_to_array($pipeline));
$this->assertSame([PHP_INT_MAX], \iterator_to_array($pipeline));
}

public function testArrayToArray()
public function testArrayToArray(): void
{
$pipeline = new Standard();
$pipeline->map(function () {
Expand All @@ -48,7 +50,7 @@ public function testArrayToArray()
$this->assertSame([42], $pipeline->toArray());
}

public function testArrayFilter()
public function testArrayFilter(): void
{
$pipeline = new Standard();
$pipeline->map(function () {
Expand All @@ -58,7 +60,7 @@ public function testArrayFilter()
$this->assertSame([], $pipeline->toArray());
}

public function testArrayReduce()
public function testArrayReduce(): void
{
$pipeline = new Standard();
$pipeline->map(function () {
Expand All @@ -68,7 +70,7 @@ public function testArrayReduce()
$this->assertSame(3, $pipeline->reduce());
}

public function testArrayValues()
public function testArrayValues(): void
{
$pipeline = new Standard();

Expand Down
14 changes: 8 additions & 6 deletions tests/EagerWithArraysTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
* Copyright 2017, 2018 Alexey Kopytko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,8 +27,10 @@

/**
* @covers \Pipeline\Principal
*
* @internal
*/
class EagerWithArraysTest extends TestCase
final class EagerWithArraysTest extends TestCase
{
public static function specimens(): \Generator
{
Expand All @@ -39,7 +41,7 @@ public static function specimens(): \Generator
/**
* @dataProvider specimens
*/
public function testEagerArrayFilter(Standard $pipeline)
public function testEagerArrayFilter(Standard $pipeline): void
{
$reflectionClass = new \ReflectionClass(Principal::class);
$reflectionProperty = $reflectionClass->getProperty('pipeline');
Expand All @@ -59,7 +61,7 @@ public function testEagerArrayFilter(Standard $pipeline)
/**
* @dataProvider specimens
*/
public function testEagerArrayReduce(Standard $pipeline)
public function testEagerArrayReduce(Standard $pipeline): void
{
$this->assertSame(6, $pipeline->reduce());

Expand All @@ -71,7 +73,7 @@ public function testEagerArrayReduce(Standard $pipeline)
/**
* @dataProvider specimens
*/
public function testEagerArrayFilterAndReduce(Standard $pipeline)
public function testEagerArrayFilterAndReduce(Standard $pipeline): void
{
$this->assertSame(6, $pipeline->filter()->reduce());
// This should be possible with an array
Expand All @@ -81,7 +83,7 @@ public function testEagerArrayFilterAndReduce(Standard $pipeline)
/**
* @dataProvider specimens
*/
public function testNonEagerArrayMap(Standard $pipeline)
public function testNonEagerArrayMap(Standard $pipeline): void
{
$this->assertSame([1, 1, 1, 1, 1], $pipeline->map(function ($value) {
return 1;
Expand Down
Loading

0 comments on commit d743b82

Please sign in to comment.