Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Apr 6, 2022
1 parent eb509c8 commit 51d3705
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/Concerns/IncludeableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public function getPartialTrees(): PartialTrees
}

return new PartialTrees(
!empty($this->includes) ? (new PartialsParser())->execute($this->includes) : null,
!empty($this->excludes) ? (new PartialsParser())->execute($this->excludes) : null,
!empty($this->only) ? (new PartialsParser())->execute($this->only) : null,
!empty($this->except) ? (new PartialsParser())->execute($this->except) : null,
! empty($this->includes) ? (new PartialsParser())->execute($this->includes) : null,
! empty($this->excludes) ? (new PartialsParser())->execute($this->excludes) : null,
! empty($this->only) ? (new PartialsParser())->execute($this->only) : null,
! empty($this->except) ? (new PartialsParser())->execute($this->except) : null,
);
}
}
1 change: 0 additions & 1 deletion src/Concerns/ResponsableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Http\JsonResponse;
use Spatie\LaravelData\Resolvers\PartialsTreeFromRequestResolver;
use Spatie\LaravelData\Support\TransformationType;

trait ResponsableData
{
Expand Down
1 change: 0 additions & 1 deletion src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Spatie\LaravelData\Resolvers\DataFromSomethingResolver;
use Spatie\LaravelData\Resolvers\EmptyDataResolver;
use Spatie\LaravelData\Support\EloquentCasts\DataEloquentCast;
use Spatie\LaravelData\Support\TransformationType;
use Spatie\LaravelData\Transformers\DataTransformer;

/**
Expand Down
1 change: 0 additions & 1 deletion src/DataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Spatie\LaravelData\Exceptions\CannotCastData;
use Spatie\LaravelData\Exceptions\InvalidDataCollectionModification;
use Spatie\LaravelData\Support\EloquentCasts\DataCollectionEloquentCast;
use Spatie\LaravelData\Support\TransformationType;
use Spatie\LaravelData\Transformers\DataCollectionTransformer;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/PartialsTreeFromRequestResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\PartialTrees;
use Spatie\LaravelData\Support\PartialsParser;
use Spatie\LaravelData\Support\PartialTrees;

class PartialsTreeFromRequestResolver
{
Expand Down
1 change: 0 additions & 1 deletion src/Transformers/DataCollectionTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Support\Enumerable;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\PartialTrees;
use Spatie\LaravelData\Support\TransformationType;

class DataCollectionTransformer
{
Expand Down
3 changes: 1 addition & 2 deletions src/Transformers/DataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use Spatie\LaravelData\Lazy;
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\PartialTrees;
use Spatie\LaravelData\Support\Lazy\ConditionalLazy;
use Spatie\LaravelData\Support\Lazy\RelationalLazy;
use Spatie\LaravelData\Support\TransformationType;
use Spatie\LaravelData\Support\PartialTrees;
use Spatie\LaravelData\Undefined;

class DataTransformer
Expand Down
8 changes: 4 additions & 4 deletions tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function it_can_disable_only_data_dynamically_from_the_request()
]));

$this->assertEquals([
'first_name' => 'Ruben'
'first_name' => 'Ruben',
], $response->getData(true));

OnlyData::$allowedOnly = null;
Expand All @@ -503,7 +503,7 @@ public function it_can_disable_only_data_dynamically_from_the_request()

$this->assertEquals([
'first_name' => 'Ruben',
'last_name' => 'Van Assche'
'last_name' => 'Van Assche',
], $response->getData(true));
}

Expand All @@ -518,7 +518,7 @@ public function it_can_disable_except_data_dynamically_from_the_request()

$this->assertEquals([
'first_name' => 'Ruben',
'last_name' => 'Van Assche'
'last_name' => 'Van Assche',
], $response->getData(true));

ExceptData::$allowedExcept = ['first_name'];
Expand All @@ -528,7 +528,7 @@ public function it_can_disable_except_data_dynamically_from_the_request()
]));

$this->assertEquals([
'last_name' => 'Van Assche'
'last_name' => 'Van Assche',
], $response->getData(true));

ExceptData::$allowedExcept = null;
Expand Down
1 change: 0 additions & 1 deletion tests/Fakes/ExceptData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\LaravelData\Tests\Fakes;

use Spatie\LaravelData\Data;
use Spatie\LaravelData\Lazy;

class ExceptData extends Data
{
Expand Down
1 change: 0 additions & 1 deletion tests/Fakes/OnlyData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\LaravelData\Tests\Fakes;

use Spatie\LaravelData\Data;
use Spatie\LaravelData\Lazy;

class OnlyData extends Data
{
Expand Down
64 changes: 31 additions & 33 deletions tests/Resolvers/PartialsTreeFromRequestResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PartialsTreeFromRequestResolverTest extends TestCase
{
private PartialsTreeFromRequestResolver $resolver;

public function setUp() : void
public function setUp(): void
{
parent::setUp();

Expand All @@ -30,24 +30,22 @@ public function it_will_correctly_reduce_a_tree_based_upon_allowed_includes(
?array $dataAllowedIncludes,
?string $requestedAllowedIncludes,
?array $expectedIncludes
)
{
) {
LazyData::$allowedIncludes = $lazyDataAllowedIncludes;

$data = new class(
$data = new class (
'Hello',
LazyData::from('Hello'),
LazyData::collection(['Hello', 'World'])
) extends Data{
) extends Data {
public static ?array $allowedIncludes;

public function __construct(
public string $property,
public LazyData $nested,
#[DataCollectionOf(LazyData::class)]
public DataCollection $collection,
)
{
) {
}

public static function allowedRequestIncludes(): ?array
Expand All @@ -60,9 +58,9 @@ public static function allowedRequestIncludes(): ?array

$request = request();

if($requestedAllowedIncludes !== null){
if ($requestedAllowedIncludes !== null) {
$request->merge([
'include' => $requestedAllowedIncludes
'include' => $requestedAllowedIncludes,
]);
}

Expand All @@ -76,29 +74,29 @@ public static function allowedRequestIncludes(): ?array

public function allowedIncludesDataProvider(): Generator
{
yield 'disallowed property inclusion' => [
yield 'disallowed property inclusion' => [
'lazyDataAllowedIncludes' => [],
'dataAllowedIncludes' => [],
'requestedIncludes' => 'property',
'expectedIncludes' => []
'expectedIncludes' => [],
];

yield 'allowed property inclusion' => [
'lazyDataAllowedIncludes' => [],
'dataAllowedIncludes' => ['property'],
'requestedIncludes' => 'property',
'expectedIncludes' => [
'property' => []
]
'property' => [],
],
];

yield 'allowed data property inclusion without nesting' => [
'lazyDataAllowedIncludes' => [],
'dataAllowedIncludes' => ['nested'],
'requestedIncludes' => 'nested.name',
'expectedIncludes' => [
'nested' => []
]
'nested' => [],
],
];

yield 'allowed data property inclusion with nesting' => [
Expand All @@ -107,18 +105,18 @@ public function allowedIncludesDataProvider(): Generator
'requestedIncludes' => 'nested.name',
'expectedIncludes' => [
'nested' => [
'name' => []
]
]
'name' => [],
],
],
];

yield 'allowed data collection property inclusion without nesting' => [
'lazyDataAllowedIncludes' => [],
'dataAllowedIncludes' => ['collection'],
'requestedIncludes' => 'collection.name',
'expectedIncludes' => [
'collection' => []
]
'collection' => [],
],
];

yield 'allowed data collection property inclusion with nesting' => [
Expand All @@ -127,9 +125,9 @@ public function allowedIncludesDataProvider(): Generator
'requestedIncludes' => 'collection.name',
'expectedIncludes' => [
'collection' => [
'name' => []
]
]
'name' => [],
],
],
];

yield 'allowed nested data property inclusion without defining allowed includes on nested' => [
Expand All @@ -138,27 +136,27 @@ public function allowedIncludesDataProvider(): Generator
'requestedIncludes' => 'nested.name',
'expectedIncludes' => [
'nested' => [
'name' => []
]
]
'name' => [],
],
],
];

yield 'allowed all nested data property inclusion without defining allowed includes on nested' => [
'lazyDataAllowedIncludes' => null,
'dataAllowedIncludes' => ['nested'],
'requestedIncludes' => 'nested.*',
'expectedIncludes' => [
'nested' => ['*']
]
'nested' => ['*'],
],
];

yield 'disallowed all nested data property inclusion ' => [
'lazyDataAllowedIncludes' => ['name'],
'dataAllowedIncludes' => ['nested'],
'requestedIncludes' => 'nested.*',
'expectedIncludes' => [
'nested' => []
]
'nested' => [],
],
];

yield 'multi property inclusion' => [
Expand All @@ -167,15 +165,15 @@ public function allowedIncludesDataProvider(): Generator
'requestedIncludes' => 'nested.*,property',
'expectedIncludes' => [
'property' => [],
'nested' => ['*']
]
'nested' => ['*'],
],
];

yield 'without property inclusion' => [
'lazyDataAllowedIncludes' => null,
'dataAllowedIncludes' => ['nested', 'property'],
'requestedIncludes' => null,
'expectedIncludes' => null
'expectedIncludes' => null,
];
}
}

0 comments on commit 51d3705

Please sign in to comment.