9
9
use Terminal42 \CashctrlApi \Exception \DomainException ;
10
10
use Terminal42 \CashctrlApi \Result ;
11
11
12
+ /**
13
+ * @template T of EntityInterface
14
+ */
12
15
abstract class AbstractCRUDEndpoint
13
16
{
14
17
public function __construct (
@@ -17,6 +20,9 @@ public function __construct(
17
20
) {
18
21
}
19
22
23
+ /**
24
+ * @return EntityInterface<T>|null
25
+ */
20
26
public function read (int $ id ): EntityInterface |null
21
27
{
22
28
$ result = $ this ->get ('read.json ' , ['id ' => $ id ], false );
@@ -28,6 +34,9 @@ public function read(int $id): EntityInterface|null
28
34
return $ this ->createInstance ($ result ->data ());
29
35
}
30
36
37
+ /**
38
+ * @param EntityInterface<T> $entity
39
+ */
31
40
public function create (EntityInterface $ entity ): Result
32
41
{
33
42
if (null !== $ entity ->getId ()) {
@@ -37,6 +46,9 @@ public function create(EntityInterface $entity): Result
37
46
return $ this ->post ('create.json ' , $ entity ->toArray ());
38
47
}
39
48
49
+ /**
50
+ * @param EntityInterface<T> $entity
51
+ */
40
52
public function update (EntityInterface $ entity ): Result
41
53
{
42
54
if (null === $ entity ->getId ()) {
@@ -46,12 +58,15 @@ public function update(EntityInterface $entity): Result
46
58
return $ this ->post ('update.json ' , $ entity ->toArray ());
47
59
}
48
60
61
+ /**
62
+ * @param array<int> $ids
63
+ */
49
64
public function delete (array $ ids ): Result
50
65
{
51
- return $ this ->post ('delete.json ' , ['ids ' => $ ids ]);
66
+ return $ this ->post ('delete.json ' , ['ids ' => implode ( ' , ' , $ ids) ]);
52
67
}
53
68
54
- protected function get (string $ url , array $ params = [], bool $ throwValidationError = true )
69
+ protected function get (string $ url , array $ params = [], bool $ throwValidationError = true ): Result | string
55
70
{
56
71
return $ this ->client ->get ($ this ->urlPrefix .'/ ' .$ url , $ params , $ throwValidationError );
57
72
}
@@ -61,5 +76,8 @@ protected function post(string $url, array $params, bool $throwValidationError =
61
76
return $ this ->client ->post ($ this ->urlPrefix .'/ ' .$ url , $ params , $ throwValidationError );
62
77
}
63
78
79
+ /**
80
+ * @return EntityInterface<T>
81
+ */
64
82
abstract protected function createInstance (array $ data ): EntityInterface ;
65
83
}
0 commit comments