Navigation Menu

Skip to content

Commit

Permalink
Merge 21d2cfc into cadf18f
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Oct 20, 2018
2 parents cadf18f + 21d2cfc commit c236a94
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 65 deletions.
29 changes: 28 additions & 1 deletion .php_cs.dist
@@ -1,4 +1,21 @@
<?php
/*
* Copyright 2017, 2018 Alexey Kopytko <alexey@kopytko.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

$header = <<<'EOF'
Copyright 2017, 2018 Alexey Kopytko <alexey@kopytko.com>
Expand All @@ -20,6 +37,8 @@ return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'explicit_indirect_variable' => true,
Expand All @@ -31,13 +50,21 @@ return PhpCsFixer\Config::create()
'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' => null,
'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,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -40,7 +40,7 @@ COMPOSER=$(PHP) $(shell which composer)

# Infection
INFECTION=vendor/bin/infection
MIN_MSI=90
MIN_MSI=100
MIN_COVERED_MSI=100
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=$(JOBS) --coverage=build/logs --log-verbosity=default --show-mutations

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
"require-dev": {
"codacy/coverage": "^1.4",
"friendsofphp/php-cs-fixer": "^2.11",
"infection/infection": "~0.8",
"infection/infection": ">=0.10.5",
"league/pipeline": "^1.0|^0.3",
"mockery/mockery": "^1.0",
"phan/phan": "^0.12",
Expand Down
4 changes: 2 additions & 2 deletions example.php
Expand Up @@ -30,8 +30,8 @@

// next processing step
$pipeline->map(function ($value) {
yield pow($value, 2);
yield pow($value, 3);
yield $value ** 2;
yield $value ** 3;
});

// simple one-to-one mapper
Expand Down
5 changes: 5 additions & 0 deletions infection.json.dist
Expand Up @@ -5,6 +5,11 @@
"src"
]
},
"mutators": {
"@default": true,
"IdenticalEqual": false,
"NotIdenticalNotEqual": false
},
"logs": {
"text": "infection-log.txt",
"badge": {"branch": "master"}
Expand Down
6 changes: 3 additions & 3 deletions src/Principal.php
Expand Up @@ -115,7 +115,7 @@ public function filter(callable $func)
}

// We got an array, that's what we need. Moving along.
if (is_array($this->pipeline)) {
if (\is_array($this->pipeline)) {
$this->pipeline = array_filter($this->pipeline, $func);

return $this;
Expand Down Expand Up @@ -160,7 +160,7 @@ public function toArray(): array
}

// We got what we need, moving along
if (is_array($this->pipeline)) {
if (\is_array($this->pipeline)) {
return array_values($this->pipeline);
}

Expand All @@ -180,7 +180,7 @@ public function toArray(): array
*/
public function reduce(callable $func, $initial)
{
if (is_array($this->pipeline)) {
if (\is_array($this->pipeline)) {
return array_reduce($this->pipeline, $func, $initial);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Standard.php
Expand Up @@ -54,7 +54,7 @@ public function unpack(callable $func = null): self
*/
public function map(callable $func = null): self
{
if (is_null($func)) {
if (null === $func) {
return $this;
}

Expand All @@ -76,7 +76,7 @@ public function filter(callable $func = null): self
};

// Strings usually are internal functions, which require exact number of parameters.
if (is_string($func)) {
if (\is_string($func)) {
$func = static function ($value) use ($func) {
return $func($value);
};
Expand All @@ -95,7 +95,7 @@ public function filter(callable $func = null): self
*/
public function reduce(callable $func = null, $initial = null)
{
if (is_null($func)) {
if (null === $func) {
return parent::reduce(static function ($carry, $item) {
/** @psalm-suppress MixedOperand */
$carry += $item;
Expand Down
6 changes: 3 additions & 3 deletions tests/ArraysTest.php
Expand Up @@ -35,7 +35,7 @@ public function testInitialCallbackNotGenerator()
return PHP_INT_MAX;
});

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

public function testArrayToArray()
Expand All @@ -45,7 +45,7 @@ public function testArrayToArray()
return 42;
});

$this->assertEquals([42], $pipeline->toArray());
$this->assertSame([42], $pipeline->toArray());
}

public function testArrayFilter()
Expand All @@ -55,7 +55,7 @@ public function testArrayFilter()
return false;
})->filter()->filter();

$this->assertEquals([], $pipeline->toArray());
$this->assertSame([], $pipeline->toArray());
}

public function testArrayReduce()
Expand Down
20 changes: 10 additions & 10 deletions tests/EdgeCasesTest.php
Expand Up @@ -33,7 +33,7 @@ public function testStandardStringFunctions()
$pipeline = new Standard(new \ArrayIterator([1, 2, 'foo', 'bar']));
$pipeline->filter('is_int');

$this->assertEquals([1, 2], iterator_to_array($pipeline));
$this->assertSame([1, 2], iterator_to_array($pipeline));
}

public function testFilterAnyFalseValue()
Expand Down Expand Up @@ -61,15 +61,15 @@ public function testMapUnprimed()
return 1;
});

$this->assertEquals([1], $pipeline->toArray());
$this->assertSame([1], $pipeline->toArray());
}

public function testFilterUnprimed()
{
$pipeline = new Standard();
$pipeline->filter()->unpack();

$this->assertEquals([], $pipeline->toArray());
$this->assertSame([], $pipeline->toArray());
}

public function testUnpackUnprimed()
Expand All @@ -79,15 +79,15 @@ public function testUnpackUnprimed()
return 1;
});

$this->assertEquals([1], $pipeline->toArray());
$this->assertSame([1], $pipeline->toArray());
}

public function testInitialInvokeReturnsScalar()
{
$pipeline = new Standard();
$pipeline->map($this);

$this->assertEquals([null], iterator_to_array($pipeline));
$this->assertSame([null], iterator_to_array($pipeline));
}

private function firstValueFromIterator(\Iterator $iterator)
Expand All @@ -106,11 +106,11 @@ public function testIteratorIterator()

$iterator = new \IteratorIterator($pipeline);
/* @var $iterator \Iterator */
$this->assertEquals(42, $this->firstValueFromIterator($iterator));
$this->assertSame(42, $this->firstValueFromIterator($iterator));

$pipeline = new Standard(new \ArrayIterator([42]));
$iterator = new \IteratorIterator($pipeline);
$this->assertEquals(42, $this->firstValueFromIterator($iterator));
$this->assertSame(42, $this->firstValueFromIterator($iterator));
}

private function pipelineWithNonUniqueKeys(): Standard
Expand All @@ -131,12 +131,12 @@ private function pipelineWithNonUniqueKeys(): Standard

public function testIteratorToArrayWithSameKeys()
{
$this->assertEquals([3, 4], iterator_to_array($this->pipelineWithNonUniqueKeys()));
$this->assertSame([3, 4], iterator_to_array($this->pipelineWithNonUniqueKeys()));
}

public function testIteratorToArrayWithAllValues()
{
$this->assertEquals([2, 3, 3, 4], $this->pipelineWithNonUniqueKeys()->toArray());
$this->assertSame([2, 3, 3, 4], $this->pipelineWithNonUniqueKeys()->toArray());
}

public function testPipelineInvokeReturnsGenerator()
Expand All @@ -150,7 +150,7 @@ public function testInvokeMaps()
$pipeline = new Standard(new \ArrayIterator(range(1, 5)));
$pipeline->map($this);

$this->assertEquals(range(1, 5), iterator_to_array($pipeline));
$this->assertSame(range(1, 5), iterator_to_array($pipeline));
}

public function __invoke($default = null)
Expand Down
2 changes: 1 addition & 1 deletion tests/ErrorsTest.php
Expand Up @@ -63,7 +63,7 @@ public function testPipelineInPipelineUsesSelf()
});

$pipeline->map($pipeline)->filter(function ($i) {
return $i % 2 != 0;
return 0 !== $i % 2;
});

$this->expectExceptionMessage('Cannot rewind a generator that was already run');
Expand Down
16 changes: 8 additions & 8 deletions tests/IterableTest.php
Expand Up @@ -32,7 +32,7 @@ class IterableTest extends TestCase

public static function setUpBeforeClass()
{
if (PHP_VERSION_ID < 70100) {
if (\PHP_VERSION_ID < 70100) {
self::$usesIterable = false;

return;
Expand All @@ -46,20 +46,20 @@ public static function setUpBeforeClass()
protected function setUp()
{
if (!self::$usesIterable) {
$this->markTestSkipped();
$this->markTestSkipped('Not testing iterables: not yet supported by the interface');
}
}

public function testArrayToArray()
{
$pipeline = new Standard([1, 2, 3]);
$this->assertEquals([1, 2, 3], $pipeline->toArray());
$this->assertSame([1, 2, 3], $pipeline->toArray());
}

public function testArrayToIterator()
{
$pipeline = new Standard([1, 2, 3]);
$this->assertEquals([1, 2, 3], iterator_to_array($pipeline));
$this->assertSame([1, 2, 3], iterator_to_array($pipeline));
}

public function testEmptyArrayStaysEmpty()
Expand All @@ -71,27 +71,27 @@ public function testEmptyArrayStaysEmpty()
yield $value;
})->filter()->unpack();

$this->assertEquals([], $pipeline->toArray());
$this->assertSame([], $pipeline->toArray());
}

public function testArrayFilter()
{
$pipeline = new Standard([0, 1, 2, 3, 0]);
$this->assertEquals([1, 2, 3], $pipeline->filter()->toArray());
$this->assertSame([1, 2, 3], $pipeline->filter()->toArray());
}

public function testArrayMap()
{
$pipeline = new Standard([1 => 0, 1, 2, 3]);
$this->assertEquals([0 => 0, 1, 2, 3], $pipeline->map(function ($value) {
$this->assertSame([0 => 0, 1, 2, 3], $pipeline->map(function ($value) {
return $value;
})->toArray());
}

public function testArrayMapFilter()
{
$pipeline = new Standard([1 => 0, 1, 2, 3]);
$this->assertEquals([0 => 1, 2, 3], $pipeline->map(function ($value) {
$this->assertSame([0 => 1, 2, 3], $pipeline->map(function ($value) {
return $value;
})->filter()->toArray());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/LeaguePipelineTest.php
Expand Up @@ -34,11 +34,11 @@ public function testWithLeaguePipeline()
return $payload * 2;
});

$this->assertEquals(22, $leaguePipeline(10));
$this->assertSame(22, $leaguePipeline(10));

$pipeline = new \Pipeline\Standard(new \ArrayIterator([10, 20, 30]));
$pipeline->map($leaguePipeline);

$this->assertEquals([22, 42, 62], iterator_to_array($pipeline));
$this->assertSame([22, 42, 62], iterator_to_array($pipeline));
}
}

0 comments on commit c236a94

Please sign in to comment.