Skip to content

Commit

Permalink
Revert "Merge branch 'pr/79'"
Browse files Browse the repository at this point in the history
This reverts commit 11bb8ec, reversing
changes made to bb0e85f.
  • Loading branch information
rubenvanassche committed Jan 26, 2022
1 parent 11bb8ec commit 1d99c8e
Show file tree
Hide file tree
Showing 17 changed files with 2 additions and 248 deletions.
14 changes: 0 additions & 14 deletions src/Attributes/Validation/Sometimes.php

This file was deleted.

7 changes: 1 addition & 6 deletions src/Resolvers/DataFromArrayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spatie\LaravelData\Lazy;
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Undefined;

class DataFromArrayResolver
{
Expand Down Expand Up @@ -42,16 +41,12 @@ private function shouldIgnoreProperty(DataProperty $property, array $values): bo

private function resolveValue(DataProperty $property, array $values): mixed
{
$value = array_key_exists($property->name(), $values) ? $values[$property->name()] ?? null : Undefined::make();
$value = $values[$property->name()] ?? null;

if ($value === null) {
return $value;
}

if ($value instanceof Undefined) {
return $value;
}

if ($value instanceof Lazy) {
return $value;
}
Expand Down
17 changes: 0 additions & 17 deletions src/RuleInferrers/SometimesRuleInferrer.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Support/DataProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Spatie\LaravelData\Exceptions\CannotFindDataTypeForProperty;
use Spatie\LaravelData\Exceptions\InvalidDataPropertyType;
use Spatie\LaravelData\Lazy;
use Spatie\LaravelData\Undefined;
use TypeError;

class DataProperty
Expand All @@ -25,8 +24,6 @@ class DataProperty

protected bool $isNullable;

protected bool $isUndefinable;

protected bool $isData;

protected bool $isDataCollection;
Expand Down Expand Up @@ -81,11 +78,6 @@ public function isNullable(): bool
return $this->isNullable;
}

public function isUndefinable(): bool
{
return $this->isUndefinable;
}

public function isPromoted(): bool
{
return $this->property->isPromoted();
Expand Down Expand Up @@ -198,7 +190,6 @@ private function processNoType(): void
{
$this->isLazy = false;
$this->isNullable = true;
$this->isUndefinable = false;
$this->isData = false;
$this->isDataCollection = false;
$this->types = new DataPropertyTypes();
Expand All @@ -216,15 +207,13 @@ private function processNamedType(ReflectionNamedType $type)
$this->isData = is_a($name, Data::class, true);
$this->isDataCollection = is_a($name, DataCollection::class, true);
$this->isNullable = $type->allowsNull();
$this->isUndefinable = is_a($name, Undefined::class, true);
$this->types = new DataPropertyTypes([$name]);
}

private function processListType(ReflectionUnionType|ReflectionIntersectionType $type)
{
$this->isLazy = false;
$this->isNullable = false;
$this->isUndefinable = false;
$this->isData = false;
$this->isDataCollection = false;
$this->types = new DataPropertyTypes();
Expand All @@ -238,12 +227,6 @@ private function processListType(ReflectionUnionType|ReflectionIntersectionType
continue;
}

if ($name === Undefined::class) {
$this->isUndefinable = true;

continue;
}

if ($name === Lazy::class) {
$this->isLazy = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ protected function typeProcessors(): array
$this->config->getDefaultTypeReplacements()
),
new RemoveLazyTypeProcessor(),
new RemoveUndefinedTypeProcessor(),
new DtoCollectionTypeProcessor(),
];
}
Expand Down
48 changes: 0 additions & 48 deletions src/Support/TypeScriptTransformer/RemoveUndefinedTypeProcessor.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Transformers/DataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\TransformationType;
use Spatie\LaravelData\Undefined;

class DataTransformer
{
Expand Down Expand Up @@ -72,10 +71,6 @@ protected function shouldIncludeProperty(
?array $allowedIncludes,
?array $allowedExcludes,
): bool {
if ($value instanceof Undefined) {
return false;
}

if (! $value instanceof Lazy) {
return true;
}
Expand Down
12 changes: 0 additions & 12 deletions src/Undefined.php

This file was deleted.

6 changes: 0 additions & 6 deletions tests/Attributes/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
use Spatie\LaravelData\Attributes\Validation\Rule;
use Spatie\LaravelData\Attributes\Validation\Same;
use Spatie\LaravelData\Attributes\Validation\Size;
use Spatie\LaravelData\Attributes\Validation\Sometimes;
use Spatie\LaravelData\Attributes\Validation\StartsWith;
use Spatie\LaravelData\Attributes\Validation\StringType;
use Spatie\LaravelData\Attributes\Validation\Timezone;
Expand Down Expand Up @@ -374,11 +373,6 @@ public function attributesDataProvider(): Generator
'attribute' => new Uuid(),
'expected' => ['uuid'],
];

yield [
'attribute' => new Sometimes(),
'expected' => ['sometimes'],
];
}

public function acceptedIfAttributesDataProvider(): Generator
Expand Down
21 changes: 0 additions & 21 deletions tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Spatie\LaravelData\Tests\Fakes\Casts\ConfidentialDataCollectionCast;
use Spatie\LaravelData\Tests\Fakes\Casts\StringToUpperCast;
use Spatie\LaravelData\Tests\Fakes\DefaultLazyData;
use Spatie\LaravelData\Tests\Fakes\DefaultUndefinedData;
use Spatie\LaravelData\Tests\Fakes\DummyDto;
use Spatie\LaravelData\Tests\Fakes\DummyModel;
use Spatie\LaravelData\Tests\Fakes\DummyModelWithCasts;
Expand Down Expand Up @@ -937,24 +936,4 @@ public function it_continues_value_assignment_after_a_false_boolean()
$this->assertEquals('string', $data->string);
$this->assertTrue(Carbon::create(2020, 05, 16, 12, 00, 00)->equalTo($data->date));
}

/** @test */
public function it_excludes_undefined_values_data()
{
$data = DefaultUndefinedData::from([]);

$this->assertEquals([], $data->toArray());
}

/** @test */
public function it_includes_value_if_not_undefined_data()
{
$data = DefaultUndefinedData::from([
'name' => 'Freek'
]);

$this->assertEquals([
'name' => 'Freek'
], $data->toArray());
}
}
2 changes: 0 additions & 2 deletions tests/Fakes/ComplicatedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\Undefined;

class ComplicatedData extends Data
{
Expand All @@ -20,7 +19,6 @@ public function __construct(
public string $string,
public array $array,
public ?int $nullable,
public int|Undefined $undefinable,
public mixed $mixed,
#[WithCast(DateTimeInterfaceCast::class, format: 'd-m-Y', type: CarbonImmutable::class)]
public $explicitCast,
Expand Down
14 changes: 0 additions & 14 deletions tests/Fakes/DefaultUndefinedData.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/Resolvers/DataFromArrayResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Spatie\LaravelData\Tests\Fakes\NestedModelData;
use Spatie\LaravelData\Tests\Fakes\SimpleData;
use Spatie\LaravelData\Tests\TestCase;
use Spatie\LaravelData\Undefined;

class DataFromArrayResolverTest extends TestCase
{
Expand Down Expand Up @@ -70,7 +69,6 @@ public function it_maps_default_types()
$this->assertEquals('Hello world', $data->string);
$this->assertEquals([1, 1, 2, 3, 5, 8], $data->array);
$this->assertNull($data->nullable);
$this->assertInstanceOf(Undefined::class, $data->undefinable);
$this->assertEquals(42, $data->mixed);
$this->assertEquals(DateTime::createFromFormat(DATE_ATOM, '1994-05-16T12:00:00+01:00'), $data->defaultCast);
$this->assertEquals(CarbonImmutable::createFromFormat('d-m-Y', '16-06-1994'), $data->explicitCast);
Expand Down
52 changes: 0 additions & 52 deletions tests/Resolvers/EmptyDataResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Spatie\LaravelData\Resolvers\EmptyDataResolver;
use Spatie\LaravelData\Tests\Fakes\SimpleData;
use Spatie\LaravelData\Tests\TestCase;
use Spatie\LaravelData\Undefined;

class EmptyDataResolverTest extends TestCase
{
Expand Down Expand Up @@ -106,37 +105,6 @@ public function it_will_return_the_base_type_for_lazy_types_that_can_be_null()
});
}

public function it_will_return_the_base_type_for_lazy_types_that_can_be_undefined()
{
$this->assertEmptyPropertyValue(null, new class () {
public Lazy | string | Undefined $property;
});

$this->assertEmptyPropertyValue([], new class () {
public Lazy | array | Undefined $property;
});

$this->assertEmptyPropertyValue(['string' => null], new class () {
public Lazy | SimpleData | Undefined $property;
});
}

/** @test */
public function it_will_return_the_base_type_for_undefinable_types()
{
$this->assertEmptyPropertyValue(null, new class() {
public Undefined | string $property;
});

$this->assertEmptyPropertyValue([], new class () {
public Undefined | array $property;
});

$this->assertEmptyPropertyValue(['string' => null], new class () {
public Undefined | SimpleData $property;
});
}

/** @test */
public function it_cannot_have_multiple_types()
{
Expand Down Expand Up @@ -167,26 +135,6 @@ public function it_cannot_have_multiple_types_with_a_nullable_lazy()
});
}

/** @test */
public function it_cannot_have_multiple_types_with_a_undefined()
{
$this->expectException(DataPropertyCanOnlyHaveOneType::class);

$this->assertEmptyPropertyValue(null, new class () {
public int | string | Undefined $property;
});
}

/** @test */
public function it_cannot_have_multiple_types_with_a_nullable_undefined()
{
$this->expectException(DataPropertyCanOnlyHaveOneType::class);

$this->assertEmptyPropertyValue(null, new class () {
public int | string | Undefined | null $property;
});
}

/** @test */
public function it_can_overwrite_empty_properties()
{
Expand Down
Loading

0 comments on commit 1d99c8e

Please sign in to comment.