Skip to content

Commit 46e2d19

Browse files
More test coverage
1 parent d70d4d5 commit 46e2d19

30 files changed

+422
-170
lines changed

src/Attributes/MapName.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Spatie\LaravelData\Attributes;
44

55
use Attribute;
6+
use Spatie\LaravelData\Mappers\NameMapper;
67

78
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)]
89
class MapName
910
{
10-
public function __construct(public string|int $input, public string|int|null $output = null)
11+
public function __construct(public string|int|NameMapper $input, public string|int|NameMapper|null $output = null)
1112
{
1213
$this->output ??= $this->input;
1314
}

src/Concerns/BaseData.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ public static function prepareForPipeline(array $properties): array
8585
return $properties;
8686
}
8787

88-
public function getMorphClass(): string
89-
{
90-
/** @var class-string<BaseDataContract> $class */
91-
$class = static::class;
92-
93-
return app(DataConfig::class)->morphMap->getDataClassAlias($class) ?? $class;
94-
}
95-
9688
public function __sleep(): array
9789
{
9890
$dataClass = app(DataConfig::class)->getDataClass(static::class);

src/Concerns/EnumerableMethods.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
trait EnumerableMethods
1414
{
1515
/**
16+
* @deprecated In v5, use a regular Laravel collection instead
17+
*
1618
* @param callable(TValue, TKey): TValue $through
1719
*
1820
* @return static
@@ -27,6 +29,8 @@ public function through(callable $through): static
2729
}
2830

2931
/**
32+
* @deprecated In v5, use a regular Laravel collection instead
33+
*
3034
* @param callable(TValue, TKey): TValue $map
3135
*
3236
* @return static
@@ -37,6 +41,8 @@ public function map(callable $map): static
3741
}
3842

3943
/**
44+
* @deprecated In v5, use a regular Laravel collection instead
45+
*
4046
* @param callable(TValue): bool $filter
4147
*
4248
* @return static
@@ -51,6 +57,8 @@ public function filter(callable $filter): static
5157
}
5258

5359
/**
60+
* @deprecated In v5, use a regular Laravel collection instead
61+
*
5462
* @param callable(TValue): bool $filter
5563
*
5664
* @return static
@@ -65,6 +73,8 @@ public function reject(callable $filter): static
6573
}
6674

6775
/**
76+
* @deprecated In v5, use a regular Laravel collection instead
77+
*
6878
* @template TFirstDefault
6979
*
7080
* @param null| (callable(TValue,TKey): bool) $callback
@@ -78,6 +88,8 @@ public function first(callable|null $callback = null, $default = null)
7888
}
7989

8090
/**
91+
* @deprecated In v5, use a regular Laravel collection instead
92+
*
8193
* @template TLastDefault
8294
*
8395
* @param null| (callable(TValue,TKey): bool) $callback
@@ -91,6 +103,8 @@ public function last(callable|null $callback = null, $default = null)
91103
}
92104

93105
/**
106+
* @deprecated In v5, use a regular Laravel collection instead
107+
*
94108
* @param callable(TValue, TKey): mixed $callback
95109
*
96110
* @return static
@@ -103,6 +117,8 @@ public function each(callable $callback): static
103117
}
104118

105119
/**
120+
* @deprecated In v5, use a regular Laravel collection instead
121+
*
106122
* @return static<int, TValue>
107123
*/
108124
public function values(): static
@@ -114,6 +130,9 @@ public function values(): static
114130
return $cloned;
115131
}
116132

133+
/**
134+
* @deprecated In v5, use a regular Laravel collection instead
135+
*/
117136
public function where(string $key, mixed $operator = null, mixed $value = null): static
118137
{
119138
$cloned = clone $this;
@@ -124,6 +143,8 @@ public function where(string $key, mixed $operator = null, mixed $value = null):
124143
}
125144

126145
/**
146+
* @deprecated In v5, use a regular Laravel collection instead
147+
*
127148
* @template TReduceInitial
128149
* @template TReduceReturnType
129150
*
@@ -138,6 +159,8 @@ public function reduce(callable $callback, mixed $initial = null)
138159
}
139160

140161
/**
162+
* @deprecated In v5, use a regular Laravel collection instead
163+
*
141164
* @param (callable(TValue, TKey): bool)|string|null $key
142165
* @param mixed $operator
143166
* @param mixed $value
@@ -153,6 +176,8 @@ public function sole(callable|string|null $key = null, mixed $operator = null, m
153176
}
154177

155178
/**
179+
*
180+
*
156181
* @param DataCollection $collection
157182
*
158183
* @return static

src/Contracts/BaseData.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@ public static function normalizers(): array;
5151
public static function prepareForPipeline(array $properties): array;
5252

5353
public static function pipeline(): DataPipeline;
54-
55-
public function getMorphClass(): string;
5654
}

src/Exceptions/DataMissingFeature.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Exceptions/InvalidDataClassMapper.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/LaravelDataServiceProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ public function packageRegistered(): void
3434
fn () => $this->app->make(DataStructureCache::class)->getConfig() ?? DataConfig::createFromConfig(config('data'))
3535
);
3636

37-
/** @psalm-suppress UndefinedInterfaceMethod */
3837
$this->app->beforeResolving(BaseData::class, function ($class, $parameters, $app) {
39-
if ($app->has($class)) {
40-
return;
41-
}
42-
4338
$app->bind(
4439
$class,
4540
fn ($container) => $class::from($container['request'])

src/Mappers/CamelCaseMapper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ class CamelCaseMapper implements NameMapper
88
{
99
public function map(int|string $name): string|int
1010
{
11-
if (! is_string($name)) {
12-
return $name;
13-
}
14-
1511
return Str::camel($name);
1612
}
1713
}

src/Mappers/ProvidedNameMapper.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,4 @@ public function map(int|string $name): string|int
1212
{
1313
return $this->name;
1414
}
15-
16-
public function inverse(): NameMapper
17-
{
18-
return $this;
19-
}
2015
}

src/Mappers/SnakeCaseMapper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ class SnakeCaseMapper implements NameMapper
88
{
99
public function map(int|string $name): string|int
1010
{
11-
if (! is_string($name)) {
12-
return $name;
13-
}
14-
1511
return Str::snake($name);
1612
}
1713
}

0 commit comments

Comments
 (0)