Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private function addHasManyRelationCallback(string $relationName, array $relatio
? $this->removeTablePrefix($hasMany->ownerJoin)
: $this->getDefaultForeignKeyName();

$insert = Arr\map_iterable(
$insert = Arr\map(
array: $relations,
map: fn ($item) => $this->prepareRelationItem($item, $foreignKey, $parentId),
);
Expand Down Expand Up @@ -306,7 +306,7 @@ private function handleStandardHasOneRelation(HasOne $hasOne, object|array $rela

private function resolveData(): array
{
return Arr\map_iterable(
return Arr\map(
array: $this->rows,
map: fn (object|iterable $model) => $this->resolveModelData($model),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function serializeWithType(mixed $input): mixed
}

if (is_array($input)) {
return Arr\map_iterable($input, $this->serializeWithType(...));
return Arr\map($input, $this->serializeWithType(...));
}

return $input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function map(mixed $from, mixed $to): GenericRequest
'path' => $from->getUri()->getPath(),
'query' => $query,
'files' => $uploads,
'cookies' => Arr\filter(Arr\map_iterable(
'cookies' => Arr\filter(Arr\map(
array: $_COOKIE,
map: function (string $value, string $key) {
try {
Expand Down
8 changes: 4 additions & 4 deletions packages/mail/src/Testing/MailTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ public function assertNotSent(string $email): self
}

public array $from {
get => Arr\map_iterable(
get => Arr\map(
array: $this->sentSymfonyEmail->getFrom(),
map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()),
);
}

public array $to {
get => Arr\map_iterable(
get => Arr\map(
array: $this->sentSymfonyEmail->getTo(),
map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()),
);
}

public array $attachments {
get => Arr\map_iterable(
get => Arr\map(
array: $this->sentSymfonyEmail->getAttachments(),
map: fn (DataPart $attachment) => new Attachment(
resolve: fn () => $attachment->getBody(),
Expand Down Expand Up @@ -383,7 +383,7 @@ public function assertAttached(string $filename, ?Closure $callback = null): sel
Assert::fail(sprintf(
'Failed asserting that the email has an attachment named `%s`. Existing attachments: %s.',
$filename,
Arr\join(Arr\map_iterable($attachments, fn (DataPart $attachment) => $attachment->getName())),
Arr\join(Arr\map($attachments, fn (DataPart $attachment) => $attachment->getName())),
));

return $this;
Expand Down
2 changes: 1 addition & 1 deletion packages/mail/src/Transports/RoundRobinMailerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function createTransport(): TransportInterface
/** @return TransportInterface[] */
private function buildTransports(): array
{
return Arr\map_iterable($this->transports, fn (MailerConfig $config) => $config->createTransport());
return Arr\map($this->transports, fn (MailerConfig $config) => $config->createTransport());
}
}
2 changes: 1 addition & 1 deletion packages/router/src/Exceptions/HtmlExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function renderValidationFailedResponse(ValidationFailed $exception): Re
$this->container->get(FormSession::class)->setOriginalValues($this->filterSensitiveFields($this->request, $exception->targetClass));
}

$errors = Arr\map_iterable($exception->failingRules, fn (array $failingRulesForField, string $field) => Arr\map_iterable(
$errors = Arr\map($exception->failingRules, fn (array $failingRulesForField, string $field) => Arr\map(
array: $failingRulesForField,
map: fn (FailingRule $rule) => $this->validator->getErrorMessage($rule, $field),
));
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/Exceptions/JsonExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function renderHttpRequestFailed(HttpRequestFailed $exception): Response

private function renderValidationFailedResponse(ValidationFailed $exception): Response
{
$errors = Arr\map_iterable($exception->failingRules, fn (array $failingRulesForField, string $field) => Arr\map_iterable(
$errors = Arr\map($exception->failingRules, fn (array $failingRulesForField, string $field) => Arr\map(
array: $failingRulesForField,
map: fn (FailingRule $rule) => $this->validator->getErrorMessage($rule, $field),
));
Expand Down Expand Up @@ -94,7 +94,7 @@ private function renderErrorResponse(Status $status, ?string $message = null, ?T
'exception' => get_class($throwable),
'file' => $throwable->getFile(),
'line' => $throwable->getLine(),
'trace' => Arr\map_iterable(
'trace' => Arr\map(
array: $throwable->getTrace(),
map: fn (array $trace) => Arr\remove_keys($trace, 'args'),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/support/src/Arr/ManipulatesArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function each(Closure $each): self
*/
public function map(Closure $map): self
{
return $this->createOrModify(namespace\map_iterable($this->value, $map));
return $this->createOrModify(map($this->value, $map));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/support/src/Arr/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ function each(iterable $array, Closure $each): array
*
* @return array<TKey, TMapValue>
*/
function map_iterable(iterable $array, Closure $map): array
function map(iterable $array, Closure $map): array
{
$result = [];

Expand Down Expand Up @@ -1086,7 +1086,7 @@ function group_by(iterable $array, Closure $keyExtracor): array
*/
function flat_map(iterable $array, Closure $map, int|float $depth = 1): array
{
return namespace\flatten(namespace\map_iterable(to_array($array), $map), $depth);
return namespace\flatten(map(to_array($array), $map), $depth);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/upgrade/config/sets/tempest30.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Rector\Config\RectorConfig;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Tempest\Upgrade\Tempest3\UpdateArrMapFunctionRector;
use Tempest\Upgrade\Tempest3\UpdateCommandFunctionImportsRector;
use Tempest\Upgrade\Tempest3\UpdateContainerFunctionImportsRector;
use Tempest\Upgrade\Tempest3\UpdateEventFunctionImportsRector;
Expand All @@ -16,6 +17,7 @@
SimpleParameterProvider::setParameter(Option::AUTO_IMPORT_NAMES, value: true);
SimpleParameterProvider::setParameter(Option::IMPORT_SHORT_CLASSES, value: true);

$config->rule(UpdateArrMapFunctionRector::class);
$config->rule(UpdateCommandFunctionImportsRector::class);
$config->rule(UpdateContainerFunctionImportsRector::class);
$config->rule(UpdateEventFunctionImportsRector::class);
Expand Down
40 changes: 40 additions & 0 deletions packages/upgrade/src/Tempest3/UpdateArrMapFunctionRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tempest\Upgrade\Tempest3;

use PhpParser\Node;
use Rector\Rector\AbstractRector;

final class UpdateArrMapFunctionRector extends AbstractRector
{
public function getNodeTypes(): array
{
return [
Node\UseItem::class,
Node\Expr\FuncCall::class,
];
}

public function refactor(Node $node): ?int
{
if ($node instanceof Node\UseItem) {
if ($node->name->toString() === 'Tempest\Support\Arr\map_iterable') {
$node->name = new Node\Name('Tempest\Support\Arr\map');
}

return null;
}

if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
$functionName = $node->name->toString();

if ($functionName === 'Tempest\Support\Arr\map_iterable') {
$node->name = new Node\Name\FullyQualified('Tempest\Support\Arr\map');

return null;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Tempest\Support\Arr;

final class FullyQualifiedMapIterableCall
{
public function __invoke(array $data)
{
return Arr\map_iterable($data, fn ($item) => $item * 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use function Tempest\Support\Arr\map_iterable;

final class MapIterableNamespaceChange
{
public function __invoke(array $data)
{
return map_iterable($data, fn ($item) => $item * 2);
}
}
16 changes: 16 additions & 0 deletions packages/upgrade/tests/Tempest3/Tempest3RectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ public function test_fully_qualified_view_call(): void
->assertContains('use Tempest\View\view;')
->assertContains('return view($template);');
}

public function test_map_iterable_namespace_change(): void
{
$this->rector
->runFixture(__DIR__ . '/Fixtures/MapIterableNamespaceChange.input.php')
->assertContains('use function Tempest\Support\Arr\map;')
->assertNotContains('use function Tempest\Support\Arr\map_iterable;');
}

public function test_fully_qualified_map_iterable_call(): void
{
$this->rector
->runFixture(__DIR__ . '/Fixtures/FullyQualifiedMapIterableCall.input.php')
->assertContains('use Tempest\Support\Arr\map;')
->assertContains('return map($data, fn ($item) => $item * 2);');
}
}
6 changes: 3 additions & 3 deletions packages/validation/src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function createValidationFailureException(array $failingRules, null|objec
return new ValidationFailed(
failingRules: $failingRules,
subject: $subject,
errorMessages: Arr\map_iterable($failingRules, function (array $rules, string $field) {
return Arr\map_iterable($rules, fn (FailingRule $rule) => $this->getErrorMessage($rule, $field));
errorMessages: Arr\map($failingRules, function (array $rules, string $field) {
return Arr\map($rules, fn (FailingRule $rule) => $this->getErrorMessage($rule, $field));
}),
targetClass: $targetClass,
);
Expand Down Expand Up @@ -151,7 +151,7 @@ public function validateValueForProperty(PropertyReflector $property, mixed $val

$key = $property->getAttribute(TranslationKey::class)?->key;

return Arr\map_iterable(
return Arr\map(
array: $this->validateValue($value, $rules),
map: fn (FailingRule $rule) => $rule->withKey($key),
);
Expand Down