Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel authored and github-actions[bot] committed Jan 25, 2025
1 parent 65d6d9a commit 58ffe37
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Normalizers/Normalized/NormalizedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ protected function fetchNewProperty(string $name, DataProperty $dataProperty): m
return $this->properties[$name] = $this->model->getRelation($name);
}

if (!$this->model->isRelation($name)) {
if (! $this->model->isRelation($name)) {
try {
$propertyName = $this->model::$snakeAttributes ? Str::snake($name) : $name;

return $this->properties[$name] = $this->model->getAttribute($propertyName);
} catch (MissingAttributeException) {
// Fallback if missing Attribute
Expand Down
1 change: 0 additions & 1 deletion src/Resolvers/NameMappersResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spatie\LaravelData\Resolvers;

use Illuminate\Support\Collection;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Attributes\MapOutputName;
Expand Down
8 changes: 6 additions & 2 deletions src/Support/AttributeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static function makeFromReflectionAttributes(array $attributes): static
public function add($item): static
{
unset($this->groups);

return parent::add($item);
}

Expand All @@ -33,7 +34,7 @@ public function offsetSet($key, $value): void

private function maybeProcessItemsIntoGroups(): void
{
if (!isset($this->groups)) {
if (! isset($this->groups)) {
foreach ($this->items as $item) {
$implements = class_implements($item);
$parents = class_parents($item);
Expand All @@ -50,7 +51,8 @@ private function maybeProcessItemsIntoGroups(): void
public function hasAttribute(string $attributeClass): bool
{
$this->maybeProcessItemsIntoGroups();
return !empty($this->groups[$attributeClass]);

return ! empty($this->groups[$attributeClass]);
}

/**
Expand All @@ -62,6 +64,7 @@ public function hasAttribute(string $attributeClass): bool
public function getAttributes(string $attributeClass): Collection
{
$this->maybeProcessItemsIntoGroups();

return collect($this->groups[$attributeClass] ?? []);
}

Expand All @@ -74,6 +77,7 @@ public function getAttributes(string $attributeClass): Collection
public function getAttribute(string $attributeClass): ?object
{
$this->maybeProcessItemsIntoGroups();

return current($this->groups[$attributeClass] ?? []) ?: null;
}
}
1 change: 0 additions & 1 deletion src/Support/Factories/DataClassFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\LaravelData\Support\Factories;

use Illuminate\Support\Collection;
use ReflectionAttribute;
use ReflectionClass;
use ReflectionMethod;
use ReflectionParameter;
Expand Down
1 change: 0 additions & 1 deletion src/Support/Factories/DataPropertyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spatie\LaravelData\Support\Factories;

use ReflectionAttribute;
use ReflectionClass;
use ReflectionProperty;
use Spatie\LaravelData\Attributes\Computed;
Expand Down
1 change: 0 additions & 1 deletion tests/Resolvers/NameMappersResolverTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Illuminate\Support\Collection;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Attributes\MapOutputName;
Expand Down

0 comments on commit 58ffe37

Please sign in to comment.