Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
majkel89 committed Mar 3, 2019
1 parent fe53b75 commit aa6ef2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
18 changes: 11 additions & 7 deletions src/Mutator/Removal/ArrayItemRemoval.php
Expand Up @@ -35,11 +35,11 @@

namespace Infection\Mutator\Removal;

use Generator;
use Infection\Config\Exception\InvalidConfigException;
use Infection\Mutator\Util\Mutator;
use Infection\Mutator\Util\MutatorConfig;
use PhpParser\Node;
use Generator;

/**
* @internal
Expand All @@ -66,12 +66,13 @@ public function __construct(MutatorConfig $config)

public function mutate(Node $arrayNode): Generator
{
/** @var Node\Expr\Array_ $arrayNode */
foreach ($this->getItemsIndexes($arrayNode->items) as $indexToRemove) {
/** @var Node\Expr\Array_ $newArrayNode */
$newArrayNode = clone $arrayNode;
unset($newArrayNode->items[$indexToRemove]);
yield $newArrayNode;
if ($arrayNode instanceof Node\Expr\Array_) {
foreach ($this->getItemsIndexes($arrayNode->items) as $indexToRemove) {
$newArrayNode = clone $arrayNode;
unset($newArrayNode->items[$indexToRemove]);

yield $newArrayNode;
}
}
}

Expand All @@ -80,7 +81,9 @@ protected function mutatesNode(Node $node): bool
if (!$node instanceof Node\Expr\Array_) {
return false;
}

$itemsCount = \count($node->items);

return $itemsCount && ($this->remove !== 'all' || $itemsCount <= $this->limit);
}

Expand Down Expand Up @@ -120,6 +123,7 @@ private function getResultSettings(): array
private function throwConfigException(string $property): void
{
$value = $this->getSettings()[$property];

throw new InvalidConfigException(sprintf(
'Invalid configuration of ArrayItemRemoval mutator. Setting `%s` is invalid (%s)',
$property,
Expand Down
10 changes: 1 addition & 9 deletions tests/Mutator/Removal/ArrayItemRemovalTest.php
Expand Up @@ -33,9 +33,9 @@

namespace Infection\Tests\Mutator\Removal;

use Generator;
use Infection\Config\Exception\InvalidConfigException;
use Infection\Tests\Mutator\AbstractMutatorTestCase;
use Generator;

/**
* @internal
Expand All @@ -44,10 +44,6 @@ final class ArrayItemRemovalTest extends AbstractMutatorTestCase
{
/**
* @dataProvider provideMutationCases
* @param string $input
* @param string[]|string $expected
* @param array $settings
* @throws \Exception
*/
public function test_mutator(string $input, $expected = null, array $settings = []): void
{
Expand Down Expand Up @@ -98,10 +94,6 @@ public function provideMutationCases(): Generator
}

/**
* @param string $setting
* @param mixed $value
* @param string $valueInError
* @throws \Exception
* @dataProvider provideInvalidConfigurationCases
*/
public function test_settings_validation(string $setting, $value, string $valueInError): void
Expand Down

0 comments on commit aa6ef2a

Please sign in to comment.