Skip to content

Commit

Permalink
properly name mappers generators #678
Browse files Browse the repository at this point in the history
  • Loading branch information
majkel89 committed Apr 15, 2019
1 parent f79f39a commit c8ade97
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
46 changes: 23 additions & 23 deletions src/Mutator/Extensions/BCMath.php
Expand Up @@ -78,32 +78,32 @@ protected function mutatesNode(Node $node): bool
private function setupConverters(array $functionsMap): void
{
$converters = [
'bcadd' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Plus::class)
'bcadd' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Plus::class)
)),
'bcdiv' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Div::class)
'bcdiv' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Div::class)
)),
'bcmod' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Mod::class)
'bcmod' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Mod::class)
)),
'bcmul' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Mul::class)
'bcmul' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Mul::class)
)),
'bcpow' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Pow::class)
'bcpow' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Pow::class)
)),
'bcsub' => $this->mapCheckingMinArgs(2, $this->mapCastToString(
$this->mapBinaryOperator(Node\Expr\BinaryOp\Minus::class)
'bcsub' => $this->makeCheckingMinArgsMapper(2, $this->makeCastToStringMapper(
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Minus::class)
)),
'bcsqrt' => $this->mapCheckingMinArgs(1, $this->mapCastToString(
$this->mapSquareRoots()
'bcsqrt' => $this->makeCheckingMinArgsMapper(1, $this->makeCastToStringMapper(
$this->makeSquareRootsMapper()
)),
'bcpowmod' => $this->mapCheckingMinArgs(3, $this->mapCastToString(
$this->mapPowerModulo()
'bcpowmod' => $this->makeCheckingMinArgsMapper(3, $this->makeCastToStringMapper(
$this->makePowerModuloMapper()
)),
'bccomp' => $this->mapCheckingMinArgs(2,
$this->mapBinaryOperator(Node\Expr\BinaryOp\Spaceship::class)
'bccomp' => $this->makeCheckingMinArgsMapper(2,
$this->makeBinaryOperatorMapper(Node\Expr\BinaryOp\Spaceship::class)
),
];

Expand All @@ -114,7 +114,7 @@ private function setupConverters(array $functionsMap): void
$this->converters = \array_diff_key($converters, $functionsToRemove);
}

private function mapCheckingMinArgs(int $minimumArgsCount, callable $converter)
private function makeCheckingMinArgsMapper(int $minimumArgsCount, callable $converter)
{
return static function (Node\Expr\FuncCall $node) use ($minimumArgsCount, $converter): Generator {
if (\count($node->args) >= $minimumArgsCount) {
Expand All @@ -123,7 +123,7 @@ private function mapCheckingMinArgs(int $minimumArgsCount, callable $converter)
};
}

private function mapCastToString(callable $converter): callable
private function makeCastToStringMapper(callable $converter): callable
{
return static function (Node\Expr\FuncCall $node) use ($converter): Generator {
foreach ($converter($node) as $newNode) {
Expand All @@ -132,21 +132,21 @@ private function mapCastToString(callable $converter): callable
};
}

private function mapBinaryOperator(string $operator): callable
private function makeBinaryOperatorMapper(string $operator): callable
{
return static function (Node\Expr\FuncCall $node) use ($operator): Generator {
yield new $operator($node->args[0]->value, $node->args[1]->value);
};
}

private function mapSquareRoots(): callable
private function makeSquareRootsMapper(): callable
{
return static function (Node\Expr\FuncCall $node): Generator {
yield new Node\Expr\FuncCall(new Node\Name('\sqrt'), [$node->args[0]]);
};
}

private function mapPowerModulo(): callable
private function makePowerModuloMapper(): callable
{
return static function (Node\Expr\FuncCall $node): Generator {
yield new Node\Expr\BinaryOp\Mod(
Expand Down
42 changes: 21 additions & 21 deletions src/Mutator/Extensions/MBString.php
Expand Up @@ -78,24 +78,24 @@ protected function mutatesNode(Node $node): bool
private function setupConverters(array $functionsMap): void
{
$converters = [
'mb_chr' => $this->mapFunctionAndRemoveExtraArgs('chr', 1),
'mb_ord' => $this->mapFunctionAndRemoveExtraArgs('ord', 1),
'mb_parse_str' => $this->mapFunction('parse_str'),
'mb_send_mail' => $this->mapFunction('mail'),
'mb_strcut' => $this->mapFunctionAndRemoveExtraArgs('substr', 3),
'mb_stripos' => $this->mapFunctionAndRemoveExtraArgs('stripos', 3),
'mb_stristr' => $this->mapFunctionAndRemoveExtraArgs('stristr', 3),
'mb_strlen' => $this->mapFunctionAndRemoveExtraArgs('strlen', 1),
'mb_strpos' => $this->mapFunctionAndRemoveExtraArgs('strpos', 3),
'mb_strrchr' => $this->mapFunctionAndRemoveExtraArgs('strrchr', 2),
'mb_strripos' => $this->mapFunctionAndRemoveExtraArgs('strripos', 3),
'mb_strrpos' => $this->mapFunctionAndRemoveExtraArgs('strrpos', 3),
'mb_strstr' => $this->mapFunctionAndRemoveExtraArgs('strstr', 3),
'mb_strtolower' => $this->mapFunctionAndRemoveExtraArgs('strtolower', 1),
'mb_strtoupper' => $this->mapFunctionAndRemoveExtraArgs('strtoupper', 1),
'mb_substr_count' => $this->mapFunctionAndRemoveExtraArgs('substr_count', 2),
'mb_substr' => $this->mapFunctionAndRemoveExtraArgs('substr', 3),
'mb_convert_case' => $this->mapConvertCase(),
'mb_chr' => $this->makeFunctionAndRemoveExtraArgsMapper('chr', 1),
'mb_ord' => $this->makeFunctionAndRemoveExtraArgsMapper('ord', 1),
'mb_parse_str' => $this->makeFunctionMapper('parse_str'),
'mb_send_mail' => $this->makeFunctionMapper('mail'),
'mb_strcut' => $this->makeFunctionAndRemoveExtraArgsMapper('substr', 3),
'mb_stripos' => $this->makeFunctionAndRemoveExtraArgsMapper('stripos', 3),
'mb_stristr' => $this->makeFunctionAndRemoveExtraArgsMapper('stristr', 3),
'mb_strlen' => $this->makeFunctionAndRemoveExtraArgsMapper('strlen', 1),
'mb_strpos' => $this->makeFunctionAndRemoveExtraArgsMapper('strpos', 3),
'mb_strrchr' => $this->makeFunctionAndRemoveExtraArgsMapper('strrchr', 2),
'mb_strripos' => $this->makeFunctionAndRemoveExtraArgsMapper('strripos', 3),
'mb_strrpos' => $this->makeFunctionAndRemoveExtraArgsMapper('strrpos', 3),
'mb_strstr' => $this->makeFunctionAndRemoveExtraArgsMapper('strstr', 3),
'mb_strtolower' => $this->makeFunctionAndRemoveExtraArgsMapper('strtolower', 1),
'mb_strtoupper' => $this->makeFunctionAndRemoveExtraArgsMapper('strtoupper', 1),
'mb_substr_count' => $this->makeFunctionAndRemoveExtraArgsMapper('substr_count', 2),
'mb_substr' => $this->makeFunctionAndRemoveExtraArgsMapper('substr', 3),
'mb_convert_case' => $this->makeConvertCaseMapper(),
];

$functionsToRemove = \array_filter($functionsMap, static function (bool $isOn): bool {
Expand All @@ -105,21 +105,21 @@ private function setupConverters(array $functionsMap): void
$this->converters = \array_diff_key($converters, $functionsToRemove);
}

private function mapFunction(string $newFunctionName): callable
private function makeFunctionMapper(string $newFunctionName): callable
{
return function (Node\Expr\FuncCall $node) use ($newFunctionName): Generator {
yield $this->mapFunctionCall($node, $newFunctionName, $node->args);
};
}

private function mapFunctionAndRemoveExtraArgs(string $newFunctionName, int $argsAtMost): callable
private function makeFunctionAndRemoveExtraArgsMapper(string $newFunctionName, int $argsAtMost): callable
{
return function (Node\Expr\FuncCall $node) use ($newFunctionName, $argsAtMost): Generator {
yield $this->mapFunctionCall($node, $newFunctionName, \array_slice($node->args, 0, $argsAtMost));
};
}

private function mapConvertCase(): callable
private function makeConvertCaseMapper(): callable
{
return function (Node\Expr\FuncCall $node): Generator {
$modeValue = $this->getConvertCaseModeValue($node);
Expand Down

0 comments on commit c8ade97

Please sign in to comment.