diff --git a/src/Model/AbstractModel.php b/src/Model/AbstractModel.php index f7f36268..42f486f5 100644 --- a/src/Model/AbstractModel.php +++ b/src/Model/AbstractModel.php @@ -207,7 +207,7 @@ public static function first( mixed $query = [], array $projection = [], bool $useCache = false - ): static | stdClass | null { + ): ?static { return self::getBuilderInstance()->first( new static(), $query, @@ -231,7 +231,7 @@ public static function firstOrFail( mixed $query = [], array $projection = [], bool $useCache = false - ): static | stdClass | null { + ): ?static { return self::getBuilderInstance()->firstOrFail( new static(), $query, @@ -246,7 +246,7 @@ public static function firstOrFail( * * @param mixed $id document id */ - public static function firstOrNew(mixed $id): static | stdClass | null + public static function firstOrNew(mixed $id): static { if (!$model = self::first($id)) { $model = new static(); diff --git a/src/Model/Casts/CastResolver.php b/src/Model/Casts/CastResolver.php index cb62a76c..5074183c 100644 --- a/src/Model/Casts/CastResolver.php +++ b/src/Model/Casts/CastResolver.php @@ -12,7 +12,7 @@ class CastResolver private const IMMUTABLE_DATE_TIME = 'immutable_datetime'; /** - * @var array|string[] + * @var string[] */ public static array $validCasts = [ self::DATE_TIME, diff --git a/src/Query/BulkWrite.php b/src/Query/BulkWrite.php index 8e31073c..d27fe4d5 100644 --- a/src/Query/BulkWrite.php +++ b/src/Query/BulkWrite.php @@ -18,7 +18,7 @@ class BulkWrite { /** * Hold bulk write operations to run. - * @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification + * @var array> */ private array $operations = []; diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index c3935cc1..4403b355 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -92,8 +92,6 @@ public function sequence(?int $value = null): int /** * Prepares the field to be the datetime that the document has been created. - * - * @param mixed $value value that will be evaluated */ public function createdAtTimestamp(mixed $value): UTCDateTime { diff --git a/tests/Integration/DateTimeCastTest.php b/tests/Integration/DateTimeCastTest.php index cbb00e75..74732eb1 100644 --- a/tests/Integration/DateTimeCastTest.php +++ b/tests/Integration/DateTimeCastTest.php @@ -58,7 +58,7 @@ public function testShouldSaveAndReadLegacyRecordWithCastedAttibutes(): void // Set $entity = new class extends LegacyRecordUser { /** - * @var array|string[] + * @var string[] */ protected array $casts = [ 'expires_at' => 'datetime', diff --git a/tests/Stubs/ExpirablePrice.php b/tests/Stubs/ExpirablePrice.php index 1f6dc765..02df3da3 100644 --- a/tests/Stubs/ExpirablePrice.php +++ b/tests/Stubs/ExpirablePrice.php @@ -5,7 +5,7 @@ class ExpirablePrice extends Price { /** - * @var array|string[] + * @var array */ protected array $casts = [ 'expires_at' => 'datetime', diff --git a/tests/Stubs/Legacy/LegacyRecordUser.php b/tests/Stubs/Legacy/LegacyRecordUser.php index 0732c8c1..16143f8e 100644 --- a/tests/Stubs/Legacy/LegacyRecordUser.php +++ b/tests/Stubs/Legacy/LegacyRecordUser.php @@ -16,7 +16,7 @@ class LegacyRecordUser extends LegacyRecord protected bool $timestamps = true; /** - * @var array|string[] + * @var string[] */ protected array $fillable = [ 'name', diff --git a/tests/Stubs/Legacy/Product.php b/tests/Stubs/Legacy/Product.php index be69a064..8b971e3d 100644 --- a/tests/Stubs/Legacy/Product.php +++ b/tests/Stubs/Legacy/Product.php @@ -10,7 +10,7 @@ class Product extends LegacyRecord { /** - * @var array + * @var array> */ public array $with = [ 'price' => [ diff --git a/tests/Stubs/PolymorphedReferencedUser.php b/tests/Stubs/PolymorphedReferencedUser.php index c81ac15c..0716b9d1 100644 --- a/tests/Stubs/PolymorphedReferencedUser.php +++ b/tests/Stubs/PolymorphedReferencedUser.php @@ -5,7 +5,7 @@ class PolymorphedReferencedUser extends ReferencedUser { /** - * @var array|string[] + * @var string[] */ protected array $fillable = [ 'type', diff --git a/tests/Stubs/ReferencedUser.php b/tests/Stubs/ReferencedUser.php index f4e0f0c5..854dcc4c 100644 --- a/tests/Stubs/ReferencedUser.php +++ b/tests/Stubs/ReferencedUser.php @@ -14,7 +14,7 @@ class ReferencedUser extends AbstractModel implements PolymorphableModelInterfac protected bool $timestamps = false; /** - * @var array|string[] + * @var string[] */ protected array $fillable = [ 'type', diff --git a/tests/Unit/DataMapper/SchemaMapperTest.php b/tests/Unit/DataMapper/SchemaMapperTest.php index e9859201..1912e540 100644 --- a/tests/Unit/DataMapper/SchemaMapperTest.php +++ b/tests/Unit/DataMapper/SchemaMapperTest.php @@ -3,10 +3,10 @@ namespace Mongolid\DataMapper; use Mockery as m; +use Mockery\MockInterface; use Mongolid\Container\Container; use Mongolid\Schema\Schema; use Mongolid\TestCase; -use Mockery\LegacyMockInterface; class SchemaMapperTest extends TestCase { @@ -182,8 +182,8 @@ public function testShouldMapAnArrayValueToAnotherSchema(): void $schema = m::mock(Schema::class); $mySchema = m::mock(Schema::class); $schemaMapper = new SchemaMapper($schema); + $anotherSchemaMapper = m::mock(SchemaMapper::class); $value = ['foo' => 'bar']; - $test = $this; // Act Container::instance('Xd\MySchema', $mySchema); @@ -191,40 +191,23 @@ public function testShouldMapAnArrayValueToAnotherSchema(): void // When instantiating the SchemaMapper with the specified $param as dependency Container::bind( SchemaMapper::class, - /** - * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter - */ - function ($container, $params) use ($value, $mySchema, $test): LegacyMockInterface { - // Check if mySchema has been injected correctly - $test->assertSame($mySchema, $params['schema']); - - // Instantiate a SchemaMapper with mySchema - $anotherSchemaMapper = m::mock( - SchemaMapper::class, - [$params['schema']] - ); - - // Set expectation to receive a map call - $anotherSchemaMapper->shouldReceive('map') - ->once() - ->with($value) - ->andReturn(['foo' => 'PARSED']); - - return $anotherSchemaMapper; - } + fn (): MockInterface => $anotherSchemaMapper ); - // Assert - $this->assertEquals( - [ - ['foo' => 'PARSED'], - ], - $this->callProtected( - $schemaMapper, - 'mapToSchema', - [$value, 'Xd\MySchema'] - ) + // Set expectation to receive a map call + $anotherSchemaMapper->expects() + ->map($value) + ->andReturn(['foo' => 'PARSED']); + + // Actions + $result = $this->callProtected( + $schemaMapper, + 'mapToSchema', + [$value, 'Xd\MySchema'] ); + + // Assert + $this->assertEquals([['foo' => 'PARSED']], $result); } public function testShouldParseToArrayGettingObjectAttributes(): void diff --git a/tests/Unit/Model/HasAttributesTraitTest.php b/tests/Unit/Model/HasAttributesTraitTest.php index da8b7d1b..ed381c01 100644 --- a/tests/Unit/Model/HasAttributesTraitTest.php +++ b/tests/Unit/Model/HasAttributesTraitTest.php @@ -419,7 +419,7 @@ public function testShouldCastAttributeToUTCDateTimeWhenSettingAttributes(): voi $model = new class () extends AbstractModel { /** - * @var array|string[] + * @var array */ protected array $casts = [ 'expires_at' => 'datetime', diff --git a/tests/Unit/Query/BuilderTest.php b/tests/Unit/Query/BuilderTest.php index 1b44370c..f5d9460f 100644 --- a/tests/Unit/Query/BuilderTest.php +++ b/tests/Unit/Query/BuilderTest.php @@ -253,7 +253,7 @@ public function testShouldUpdateUnsettingFields(): void $model = new class () extends ReplaceCollectionModel { /** - * @var array|string[] + * @var string[] */ public array $fillable = [ 'name',