Skip to content

Commit

Permalink
Reformat closures
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed May 1, 2023
1 parent d83210d commit 496fd44
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 86 deletions.
7 changes: 4 additions & 3 deletions src/Models/Attributes/DistinguishedName.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ public function assoc(): array
*/
public function multi(): array
{
return array_map(fn ($rdn) =>
static::explodeRdn($rdn)
, $this->rdns());
return array_map(
fn ($rdn) => static::explodeRdn($rdn),
$this->rdns()
);
}

/**
Expand Down
28 changes: 16 additions & 12 deletions src/Models/Attributes/DistinguishedNameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class DistinguishedNameBuilder
*/
public function __construct($dn = null)
{
$this->components = array_map(fn ($rdn) =>
DistinguishedName::explodeRdn($rdn)
, DistinguishedName::make($dn)->components());
$this->components = array_map(
fn ($rdn) => DistinguishedName::explodeRdn($rdn),
DistinguishedName::make($dn)->components()
);
}

/**
Expand Down Expand Up @@ -115,9 +116,10 @@ protected function makeAppendableComponent(string|array $attribute, string $valu
*/
public function pop(int $amount = 1, array &$removed = null): static
{
$removed = array_map(fn ($component) =>
DistinguishedName::makeRdn($component)
, array_splice($this->components, -$amount, $amount));
$removed = array_map(
fn ($component) => DistinguishedName::makeRdn($component),
array_splice($this->components, -$amount, $amount)
);

return $this;
}
Expand All @@ -127,9 +129,10 @@ public function pop(int $amount = 1, array &$removed = null): static
*/
public function shift(int $amount = 1, array &$removed = null): static
{
$removed = array_map(fn ($component) =>
DistinguishedName::makeRdn($component)
, array_splice($this->components, 0, $amount));
$removed = array_map(
fn ($component) => DistinguishedName::makeRdn($component),
array_splice($this->components, 0, $amount)
);

return $this;
}
Expand Down Expand Up @@ -183,8 +186,9 @@ protected function build(): string
? array_reverse($this->components)
: $this->components;

return implode(',', array_map(fn ($component) =>
DistinguishedName::makeRdn($component)
, $components));
return implode(',', array_map(
fn ($component) => DistinguishedName::makeRdn($component),
$components
));
}
}
8 changes: 5 additions & 3 deletions src/Models/Attributes/EscapedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public function __construct(mixed $value, string $ignore = '', int $flags = 0)
*/
public static function unescape(string $value): string
{
return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', fn ($matches) =>
chr(hexdec($matches[1]))
, $value);
return preg_replace_callback(
'/\\\([0-9A-Fa-f]{2})/',
fn ($matches) => chr(hexdec($matches[1])),
$value
);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Models/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,7 @@ public function setRawAttributes(array $attributes = []): static
// out the attributes that contain an integer key. LDAP
// search results will contain integer keys that have
// attribute names as values. We don't need these.
$this->attributes = array_filter($raw, fn ($key) =>
! is_int($key)
, ARRAY_FILTER_USE_KEY);
$this->attributes = array_filter($raw, fn ($key) => ! is_int($key), ARRAY_FILTER_USE_KEY);

// LDAP search results will contain the distinguished
// name inside of the `dn` key. We will retrieve this,
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Concerns/SerializesProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function __sleep(): array
));
}

return array_values(array_filter(array_map(fn ($p) =>
$p->isStatic() ? null : $p->getName()
, $properties)));
return array_values(array_filter(
array_map(fn ($p) => $p->isStatic() ? null : $p->getName(), $properties)
));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Relations/OneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ protected function attemptFailableOperation(Closure $operation, string|array $by
*/
public function detachAll(): Collection
{
return $this->onceWithoutMerging(fn () =>
$this->get()->each(function (Model $model) {
return $this->onceWithoutMerging(
fn () => $this->get()->each(function (Model $model) {
$this->detach($model);
})
);
Expand All @@ -363,8 +363,8 @@ public function detachAll(): Collection
*/
public function detachAllOrDelete(): Collection
{
return $this->onceWithoutMerging(fn () =>
$this->get()->each(function (Model $model) {
return $this->onceWithoutMerging(
fn () => $this->get()->each(function (Model $model) {
$relation = $model->getRelation($this->relationName);

if ($relation && $relation->count() >= 1) {
Expand Down
46 changes: 22 additions & 24 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ public function newNestedInstance(Closure $closure = null): static
*/
public function get(array|string $columns = ['*']): Collection|array
{
return $this->onceWithColumns(Arr::wrap($columns), fn () =>
$this->query($this->getQuery())
return $this->onceWithColumns(Arr::wrap($columns), fn () => $this->query($this->getQuery())
);
}

Expand Down Expand Up @@ -366,8 +365,7 @@ public function paginate(int $pageSize = 1000, bool $isCritical = false): Collec
// Here we will create the pagination callback. This allows us
// to only execute an LDAP request if caching is disabled
// or if no cache of the given query exists yet.
$callback = fn () =>
$this->runPaginate($query, $pageSize, $isCritical);
$callback = fn () => $this->runPaginate($query, $pageSize, $isCritical);

$pages = $this->getCachedResponse($query, $callback);

Expand All @@ -381,8 +379,8 @@ public function paginate(int $pageSize = 1000, bool $isCritical = false): Collec
*/
protected function runPaginate(string $filter, int $perPage, bool $isCritical): array
{
return $this->connection->run(fn (LdapInterface $ldap) =>
(new Paginator($this, $filter, $perPage, $isCritical))->execute($ldap)
return $this->connection->run(
fn (LdapInterface $ldap) => (new Paginator($this, $filter, $perPage, $isCritical))->execute($ldap)
);
}

Expand Down Expand Up @@ -419,8 +417,8 @@ public function chunk(int $pageSize, Closure $callback, bool $isCritical = false
}
};

$isolate ? $this->connection->isolate(fn (Connection $replicate) =>
$chunk($this->clone()->setConnection($replicate))
$isolate ? $this->connection->isolate(
fn (Connection $replicate) => $chunk($this->clone()->setConnection($replicate))
) : $chunk($this);

$this->logQuery($this, 'chunk', $this->getElapsedTime($start));
Expand All @@ -433,8 +431,8 @@ public function chunk(int $pageSize, Closure $callback, bool $isCritical = false
*/
protected function runChunk(string $filter, int $perPage, bool $isCritical): Generator
{
return $this->connection->run(fn (LdapInterface $ldap) =>
(new LazyPaginator($this, $filter, $perPage, $isCritical))->execute($ldap)
return $this->connection->run(
fn (LdapInterface $ldap) => (new LazyPaginator($this, $filter, $perPage, $isCritical))->execute($ldap)
);
}

Expand Down Expand Up @@ -1370,8 +1368,8 @@ public function insert(string $dn, array $attributes): bool
);
}

return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->add($dn, $attributes)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->add($dn, $attributes)
);
}

Expand All @@ -1380,8 +1378,8 @@ public function insert(string $dn, array $attributes): bool
*/
public function add(string $dn, array $attributes): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->modAdd($dn, $attributes)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->modAdd($dn, $attributes)
);
}

Expand All @@ -1390,8 +1388,8 @@ public function add(string $dn, array $attributes): bool
*/
public function update(string $dn, array $modifications): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->modifyBatch($dn, $modifications)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->modifyBatch($dn, $modifications)
);
}

Expand All @@ -1400,8 +1398,8 @@ public function update(string $dn, array $modifications): bool
*/
public function replace(string $dn, array $attributes): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->modReplace($dn, $attributes)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->modReplace($dn, $attributes)
);
}

Expand All @@ -1410,8 +1408,8 @@ public function replace(string $dn, array $attributes): bool
*/
public function delete(string $dn): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->delete($dn)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->delete($dn)
);
}

Expand All @@ -1420,8 +1418,8 @@ public function delete(string $dn): bool
*/
public function remove(string $dn, array $attributes): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->modDelete($dn, $attributes)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->modDelete($dn, $attributes)
);
}

Expand All @@ -1430,8 +1428,8 @@ public function remove(string $dn, array $attributes): bool
*/
public function rename(string $dn, string $rdn, string $newParentDn, bool $deleteOldRdn = true): bool
{
return $this->connection->run(fn (LdapInterface $ldap) =>
$ldap->rename($dn, $rdn, $newParentDn, $deleteOldRdn)
return $this->connection->run(
fn (LdapInterface $ldap) => $ldap->rename($dn, $rdn, $newParentDn, $deleteOldRdn)
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Query/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ protected function valueRetriever(mixed $value): callable
return $value;
}

return fn ($item) =>
$item instanceof Model
return fn ($item) => $item instanceof Model
? $item->getFirstAttribute($value)
: data_get($item, $value);
}
Expand Down
Loading

0 comments on commit 496fd44

Please sign in to comment.