Skip to content

Commit d59c782

Browse files
authored
Merge pull request #150 from apisearch-io/feature/item-for-deletion
Added item for deletion model class
2 parents fe33755 + 7d2bb96 commit d59c782

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

Model/Item.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function create(
159159
array $exactMatchingMetadata = [],
160160
array $suggest = []
161161
) {
162-
return new self(
162+
return new static(
163163
$uuid,
164164
null,
165165
$metadata,
@@ -192,7 +192,7 @@ public static function createLocated(
192192
array $exactMatchingMetadata = [],
193193
array $suggest = []
194194
) {
195-
return new self(
195+
return new static(
196196
$uuid,
197197
$coordinate,
198198
$metadata,
@@ -617,7 +617,7 @@ public static function createFromArray(array $array): self
617617
}
618618

619619
$item = isset($array['coordinate'])
620-
? self::createLocated(
620+
? static::createLocated(
621621
ItemUUID::createFromArray($array['uuid']),
622622
Coordinate::createFromArray($array['coordinate']),
623623
$array['metadata'] ?? [],
@@ -626,7 +626,7 @@ public static function createFromArray(array $array): self
626626
$array['exact_matching_metadata'] ?? [],
627627
$array['suggest'] ?? []
628628
)
629-
: self::create(
629+
: static::create(
630630
ItemUUID::createFromArray($array['uuid']),
631631
$array['metadata'] ?? [],
632632
$array['indexed_metadata'] ?? [],

Model/ItemForDeletion.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch PHP Client.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Model;
17+
18+
class ItemForDeletion extends Item
19+
{
20+
/**
21+
* @param ItemUUID $uuid
22+
*
23+
* @return Item
24+
*/
25+
public static function createByUUID(ItemUUID $uuid)
26+
{
27+
return static::create($uuid);
28+
}
29+
}

Tests/Model/ItemForDeletionTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch PHP Client.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Tests\Model;
17+
18+
use Apisearch\Model\ItemForDeletion;
19+
use Apisearch\Model\ItemUUID;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class ItemForDeletionTest extends TestCase
23+
{
24+
public function testCreation()
25+
{
26+
$item = ItemForDeletion::createByUUID(ItemUUID::createByComposedUUID('1~product'));
27+
$this->assertEquals('1~product', $item->composeUUID());
28+
$this->assertInstanceOf(ItemForDeletion::class, $item);
29+
$item = ItemForDeletion::createFromArray($item->toArray());
30+
$this->assertEquals('1~product', $item->composeUUID());
31+
$this->assertInstanceOf(ItemForDeletion::class, $item);
32+
}
33+
}

0 commit comments

Comments
 (0)