Skip to content

Commit

Permalink
Baseline updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jan 11, 2024
1 parent d150fe2 commit 6a1251d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
60 changes: 60 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,26 @@ parameters:
count: 1
path: src/Casts/DateTimeInterfaceCast.php

-
message: "#^Instanceof between \\*NEVER\\* and Spatie\\\\LaravelData\\\\Contracts\\\\BaseDataCollectable will always evaluate to false\\.$#"
count: 1
path: src/Data.php

-
message: "#^Method Spatie\\\\LaravelData\\\\Data\\:\\:validateAndCreate\\(\\) should return static\\(Spatie\\\\LaravelData\\\\Data\\) but returns Spatie\\\\LaravelData\\\\Contracts\\\\BaseData\\.$#"
count: 1
path: src/Data.php

-
message: "#^PHPDoc tag @return with type Spatie\\\\LaravelData\\\\DataCollection\\<int, TValue\\> is not subtype of native type static\\(Spatie\\\\LaravelData\\\\DataCollection\\<TKey of \\(int\\|string\\), TValue\\>\\)\\.$#"
count: 1
path: src/DataCollection.php

-
message: "#^Method Spatie\\\\LaravelData\\\\Dto\\:\\:validateAndCreate\\(\\) should return static\\(Spatie\\\\LaravelData\\\\Dto\\) but returns Spatie\\\\LaravelData\\\\Contracts\\\\BaseData\\.$#"
count: 1
path: src/Dto.php

-
message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Pagination\\\\Paginator\\:\\:count\\(\\)\\.$#"
count: 1
Expand All @@ -85,6 +100,51 @@ parameters:
count: 1
path: src/Resolvers/DataFromArrayResolver.php

-
message: "#^PHPDoc tag @var for variable \\$dataClass has invalid type Spatie\\\\LaravelData\\\\Concerns\\\\EmptyData\\.$#"
count: 1
path: src/Resolvers/EmptyDataResolver.php

-
message: "#^Instanceof between \\*NEVER\\* and Spatie\\\\LaravelData\\\\Contracts\\\\BaseDataCollectable will always evaluate to false\\.$#"
count: 1
path: src/Resource.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Support/DataConfig.php

-
message: "#^Match expression does not handle remaining values\\: \\(class\\-string\\<ReflectionIntersectionType\\>&literal\\-string\\)\\|\\(class\\-string\\<ReflectionUnionType\\>&literal\\-string\\)$#"
count: 1
path: src/Support/Factories/DataTypeFactory.php

-
message: "#^Match expression does not handle remaining values\\: \\(class\\-string\\<ReflectionParameter\\>&literal\\-string\\)\\|\\(class\\-string\\<ReflectionProperty\\>&literal\\-string\\)$#"
count: 1
path: src/Support/Factories/DataTypeFactory.php

-
message: "#^Parameter \\#1 \\$storage of method SplObjectStorage\\<Spatie\\\\LaravelData\\\\Support\\\\Partials\\\\Partial,null\\>\\:\\:removeAll\\(\\) expects SplObjectStorage\\<object, mixed\\>, Spatie\\\\LaravelData\\\\Support\\\\Partials\\\\PartialsCollection given\\.$#"
count: 1
path: src/Support/Transformation/DataContext.php

-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
count: 2
path: src/Support/Types/MultiType.php

-
message: "#^Parameter \\#1 \\$type of static method Spatie\\\\LaravelData\\\\Support\\\\Types\\\\PartialType\\:\\:create\\(\\) expects ReflectionNamedType, ReflectionType given\\.$#"
count: 1
path: src/Support/Types/MultiType.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Support/Types/MultiType.php

-
message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
count: 1
Expand Down
3 changes: 2 additions & 1 deletion src/Concerns/ValidateableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Validator;
use Spatie\LaravelData\Contracts\ValidateableData as ValidateableDataContract;
use Spatie\LaravelData\Resolvers\DataValidationRulesResolver;
use Spatie\LaravelData\Resolvers\DataValidatorResolver;
use Spatie\LaravelData\Support\Validation\DataRules;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static function validate(Arrayable|array $payload): Arrayable|array
return $validator->validated();
}

public static function validateAndCreate(Arrayable|array $payload): static
public static function validateAndCreate(Arrayable|array $payload): ValidateableDataContract
{
return static::factory()
->alwaysValidate()
Expand Down
6 changes: 5 additions & 1 deletion src/Contracts/ValidateableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Validation\Validator;
use Spatie\LaravelData\Contracts\ValidateableData as ValidateableDataContract;

interface ValidateableData
{
public static function validate(Arrayable|array $payload): Arrayable|array;

public static function validateAndCreate(Arrayable|array $payload): static;
/**
* @return static
*/
public static function validateAndCreate(Arrayable|array $payload): ValidateableDataContract;

public static function withValidator(Validator $validator): void;
}
5 changes: 3 additions & 2 deletions src/Resolvers/DataValidatorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Validator as ValidatorFacade;
use Illuminate\Validation\Validator;
use Spatie\LaravelData\Contracts\DataObject;
use Spatie\LaravelData\Contracts\BaseData;
use Spatie\LaravelData\Contracts\ValidateableData;
use Spatie\LaravelData\Support\Validation\DataRules;
use Spatie\LaravelData\Support\Validation\ValidationPath;

Expand All @@ -17,7 +18,7 @@ public function __construct(
) {
}

/** @param class-string<DataObject> $dataClass */
/** @param class-string<ValidateableData&BaseData> $dataClass */
public function execute(string $dataClass, Arrayable|array $payload): Validator
{
$payload = $payload instanceof Arrayable ? $payload->toArray() : $payload;
Expand Down
21 changes: 13 additions & 8 deletions src/Resolvers/EmptyDataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\LaravelData\Resolvers;

use Spatie\LaravelData\Concerns\EmptyData;
use Spatie\LaravelData\Exceptions\DataPropertyCanOnlyHaveOneType;
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\DataProperty;
Expand Down Expand Up @@ -35,29 +36,33 @@ public function execute(string $class, array $extra = []): array

protected function getValueForProperty(DataProperty $property): mixed
{
if ($property->type->isMixed()) {
$propertyType = $property->type;
if ($propertyType->isMixed()) {
return null;
}

if ($property->type->type instanceof MultiType && $property->type->type->acceptedTypesCount() > 1) {
if ($propertyType->type instanceof MultiType && $propertyType->type->acceptedTypesCount() > 1) {
throw DataPropertyCanOnlyHaveOneType::create($property);
}

if ($property->type->type->acceptsType('array')) {
if ($propertyType->type->acceptsType('array')) {
return [];
}

if ($property->type->kind->isDataObject()
&& $this->dataConfig->getDataClass($property->type->dataClass)->emptyData
if ($propertyType->kind->isDataObject()
&& $this->dataConfig->getDataClass($propertyType->dataClass)->emptyData
) {
return $property->type->dataClass::empty();
/** @var class-string<EmptyData> $dataClass */
$dataClass = $propertyType->dataClass;

return $dataClass::empty();
}

if ($property->type->kind->isDataCollectable()) {
if ($propertyType->kind->isDataCollectable()) {
return [];
}

if ($property->type->type->findAcceptedTypeForBaseType(Traversable::class) !== null) {
if ($propertyType->type->findAcceptedTypeForBaseType(Traversable::class) !== null) {
return [];
}

Expand Down
1 change: 1 addition & 0 deletions src/Support/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\LaravelData\Support;

use Spatie\LaravelData\Contracts\BaseData;
use Spatie\LaravelData\Contracts\EmptyData;
use Spatie\LaravelData\Enums\DataTypeKind;
use Spatie\LaravelData\Support\Types\Type;

Expand Down

0 comments on commit 6a1251d

Please sign in to comment.