Skip to content

Commit d686e25

Browse files
committed
code style fixes
1 parent ee69d95 commit d686e25

File tree

15 files changed

+166
-170
lines changed

15 files changed

+166
-170
lines changed

src/Attributes/ResolveModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getMorphModel(string $fromPropertyKey, array $properties, array
8080
}
8181

8282
$morphMap = Relation::morphMap();
83-
83+
8484
$modelModelClass = array_filter(
8585
array_map(
8686
fn (string $morphType) => $morphMap[$morphType] ?? null,

src/Mapper.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Pipeline\Pipeline;
99
use Illuminate\Support\Collection;
10-
use OpenSoutheners\LaravelDataMapper\MappingValue;
11-
use OpenSoutheners\LaravelDataMapper\Enums\BuiltInType;
1210
use ReflectionClass;
1311
use ReflectionProperty;
1412

@@ -19,21 +17,21 @@ final class Mapper
1917
protected ?string $dataClass = null;
2018

2119
protected ?string $throughClass = null;
22-
20+
2321
protected ?MappingValue $fromMappingValue = null;
24-
22+
2523
protected ?string $property = null;
2624

2725
protected array $propertyTypes = [];
28-
26+
2927
protected bool $runningFromMapper = false;
3028

3129
public function __construct(mixed $input)
3230
{
3331
if (is_array($input) && count($input) === 1) {
3432
$input = reset($input);
3533
}
36-
34+
3735
if (is_object($input)) {
3836
$this->dataClass = get_class($input);
3937
}
@@ -74,7 +72,7 @@ protected function takeDataFrom(mixed $input): mixed
7472
public function through(string $class): static
7573
{
7674
$this->throughClass = $class;
77-
75+
7876
return $this;
7977
}
8078

@@ -96,7 +94,7 @@ public function to(?string $output = null)
9694

9795
$mappingDataValue = new MappingValue(
9896
data: $this->data,
99-
allMappingData: (!$this->runningFromMapper ? $this->fromMappingValue?->allMappingData : $this->data) ?? [],
97+
allMappingData: (! $this->runningFromMapper ? $this->fromMappingValue?->allMappingData : $this->data) ?? [],
10098
types: $this->propertyTypes,
10199
objectClass: $output,
102100
collectClass: $this->throughClass,

src/Mappers/CollectionDataMapper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace OpenSoutheners\LaravelDataMapper\Mappers;
44

55
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
6-
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Support\Collection;
87
use OpenSoutheners\LaravelDataMapper\MappingValue;
98
use Symfony\Component\TypeInfo\Type;
@@ -32,7 +31,7 @@ public function resolve(MappingValue $mappingValue): void
3231
{
3332
if ($mappingValue->objectClass === EloquentCollection::class) {
3433
$mappingValue->data = $mappingValue->data->toBase();
35-
34+
3635
return;
3736
}
3837

@@ -41,15 +40,15 @@ public function resolve(MappingValue $mappingValue): void
4140
is_string($mappingValue->data) => Collection::make(explode(',', $mappingValue->data)),
4241
default => Collection::make($mappingValue->data),
4342
};
44-
43+
4544
if ($mappingValue->preferredTypeClass) {
4645
$collection = $collection->map(fn ($value) => map($value)->to($mappingValue->preferredTypeClass));
4746
}
4847

4948
// if ($mappingValue->preferredType->getBuiltinType() === Type::BUILTIN_TYPE_ARRAY) {
5049
// $collection = $collection->all();
5150
// }
52-
51+
5352
$mappingValue->data = $collection;
5453
}
5554
}

src/Mappers/DataMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ abstract public function assert(MappingValue $mappingValue): bool;
1616
* Resolve mapper that runs once assert returns true.
1717
*/
1818
abstract public function resolve(MappingValue $mappingValue): void;
19-
19+
2020
public function __invoke(MappingValue $mappingValue, Closure $next)
2121
{
22-
if (!$this->assert($mappingValue)) {
22+
if (! $this->assert($mappingValue)) {
2323
return $next($mappingValue);
2424
}
25-
25+
2626
$this->resolve($mappingValue);
27-
27+
2828
return $next($mappingValue);
2929
}
3030
}

src/Mappers/ModelDataMapper.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,42 @@ public function resolve(MappingValue $mappingValue): void
3333
if (is_array($mappingValue->data) && Arr::isAssoc($mappingValue->data)) {
3434
/** @var Model $modelInstance */
3535
$modelInstance = new $mappingValue->preferredTypeClass;
36-
36+
3737
foreach ($mappingValue->data as $key => $value) {
3838
if ($modelInstance->isRelation($key) && $modelInstance->$key() instanceof BelongsTo) {
3939
$modelInstance->$key()->associate($value);
40-
40+
4141
continue;
4242
}
43-
43+
4444
if ($modelInstance->isRelation($key) && $modelInstance->$key() instanceof HasMany) {
4545
$modelInstance->setRelation($key, map($value)->to(get_class($modelInstance->$key()->getModel())));
46-
46+
4747
continue;
4848
}
4949

5050
$modelInstance->fill([$key => $value]);
5151
}
52-
52+
5353
$mappingValue->data = $modelInstance;
54-
54+
5555
return;
5656
}
57-
57+
5858
if (is_string($mappingValue->data) && str_contains($mappingValue->data, ',')) {
5959
$mappingValue->data = array_filter(explode(',', $mappingValue->data));
6060
}
61-
61+
6262
if (count($mappingValue->types) <= 1) {
6363
$mappingValue->data = $this->resolveIntoModelInstance($mappingValue->data, $mappingValue->preferredTypeClass);
6464
}
65-
65+
6666
if ($mappingValue->collectClass === Collection::class) {
6767
$mappingValue->data = $mappingValue->data instanceof DatabaseCollection
6868
? $mappingValue->data->toBase()
6969
: Collection::make($mappingValue->data);
7070
}
71-
71+
7272
// $resolveModelAttributeReflector = $mappingValue->property->getAttributes(ResolveModel::class);
7373

7474
// /** @var \ReflectionAttribute<\OpenSoutheners\LaravelDataMapper\Attributes\ResolveModel>|null $resolveModelAttributeReflector */
@@ -128,7 +128,7 @@ public function resolve(MappingValue $mappingValue): void
128128
// if (! is_null($valueB)) {
129129
// $lastNonValue = $valueB;
130130
// }
131-
131+
132132
// return [$valueA, $valueB ?? $lastNonValue];
133133
// },
134134
// $data,

src/Mappers/ObjectDataMapper.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace OpenSoutheners\LaravelDataMapper\Mappers;
44

55
use Illuminate\Contracts\Container\ContextualAttribute;
6-
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Support\Collection;
87
use Illuminate\Support\Str;
98
use OpenSoutheners\LaravelDataMapper\Attributes\NormaliseProperties;
@@ -44,7 +43,7 @@ public function assert(MappingValue $mappingValue): bool
4443
public function resolve(MappingValue $mappingValue): void
4544
{
4645
$class = new ReflectionClass($mappingValue->preferredTypeClass);
47-
46+
4847
$data = [];
4948

5049
$mappingData = is_string($mappingValue->data) ? json_decode($mappingValue->data, true) : $mappingValue->data;
@@ -59,7 +58,7 @@ public function resolve(MappingValue $mappingValue): void
5958
$value = $propertiesData[$key] ?? null;
6059

6160
$type = app(PropertyInfoExtractor::class)->typeInfo($class->getName(), $key);
62-
61+
6362
/** @var \Illuminate\Support\Collection<\ReflectionAttribute> $propertyAttributes */
6463
$propertyAttributes = Collection::make($property->getAttributes());
6564

@@ -76,21 +75,21 @@ public function resolve(MappingValue $mappingValue): void
7675
if (is_null($value)) {
7776
continue;
7877
}
79-
78+
8079
$unwrappedType = app(PropertyInfoExtractor::class)->unwrapType($type);
81-
80+
8281
if ($type instanceof Type\NullableType) {
8382
$type = $type->getWrappedType();
8483
}
85-
84+
8685
if ($type instanceof Type\CollectionType) {
8786
$data[$key] = map($value)
8887
->through((string) $unwrappedType)
8988
->to($type->getCollectionValueType());
90-
89+
9190
continue;
9291
}
93-
92+
9493
$data[$key] = match (true) {
9594
$type instanceof Type\ObjectType => map($value)->to((string) $type),
9695
default => $value,
@@ -106,7 +105,7 @@ public function resolve(MappingValue $mappingValue): void
106105
protected function normalisePropertyKey(MappingValue $mappingValue, string $key): ?string
107106
{
108107
$class = new ReflectionClass($mappingValue->objectClass);
109-
108+
110109
$normaliseProperty = count($class->getAttributes(NormaliseProperties::class)) > 0
111110
?: (app('config')->get('data-mapper.normalise_properties') ?? true);
112111

src/MappingValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ final class MappingValue
2727
public function __construct(
2828
public mixed $data,
2929
public readonly array $allMappingData,
30-
30+
3131
public readonly ?string $objectClass = null,
3232
public readonly ?string $collectClass = null,
33-
33+
3434
public readonly ?array $types = null,
3535
) {
3636
$this->preferredType = $types ? (reset($types) ?? null) : null;

src/PropertyInfoExtractor.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ final class PropertyInfoExtractor
1515

1616
public function __construct()
1717
{
18-
$phpStanExtractor = new PhpStanExtractor();
19-
$reflectionExtractor = new ReflectionExtractor();
20-
18+
$phpStanExtractor = new PhpStanExtractor;
19+
$reflectionExtractor = new ReflectionExtractor;
20+
2121
$this->extractor = new Extractor(
2222
[$reflectionExtractor],
2323
[$phpStanExtractor, $reflectionExtractor],
2424
);
2525
}
26-
26+
2727
public function typeInfo(string $class, string $property, array $context = []): ?Type
2828
{
2929
return $this->extractor->getType($class, $property, $context);
@@ -35,26 +35,26 @@ public function typeInfo(string $class, string $property, array $context = []):
3535
public function typeInfoFromClass(string $class, array $context = []): array
3636
{
3737
$classReflection = new ReflectionClass($class);
38-
38+
3939
$classProperties = $classReflection->getProperties(ReflectionProperty::IS_PUBLIC);
40-
40+
4141
$propertiesTypes = [];
42-
42+
4343
foreach ($classProperties as $property) {
4444
$propertiesTypes[$property->getName()] = $this->extractor->getType($class, $property->getName(), $context);
4545
}
46-
46+
4747
return $propertiesTypes;
4848
}
49-
49+
5050
public function unwrapType(Type $type): Type
5151
{
5252
$builtinType = $type;
53-
53+
5454
while (method_exists($builtinType, 'getWrappedType')) {
5555
$builtinType = $builtinType->getWrappedType();
5656
}
57-
57+
5858
return $builtinType;
5959
}
6060
}

src/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function ($dataClass, $parameters, $app) {
5050
});
5151
}
5252
);
53-
54-
$this->app->instance(PropertyInfoExtractor::class, new PropertyInfoExtractor());
53+
54+
$this->app->instance(PropertyInfoExtractor::class, new PropertyInfoExtractor);
5555
$this->app->alias(PropertyInfoExtractor::class, 'propertyInfo');
5656
}
5757

0 commit comments

Comments
 (0)