File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace Cubex \ApiTransport \Responses ;
3
3
4
+ use Cubex \ApiTransport \Exceptions \GenericApiException ;
4
5
use Packaged \Helpers \Objects ;
6
+ use function array_filter ;
7
+ use function is_array ;
5
8
6
9
abstract class AbstractResponse implements ApiResponse
7
10
{
@@ -16,4 +19,23 @@ public function hydrate(object $response): static
16
19
17
20
return $ this ;
18
21
}
22
+
23
+ /**
24
+ * @param string $property
25
+ * @param callable $func
26
+ *
27
+ * @return $this
28
+ * @throws GenericApiException
29
+ */
30
+ public function filterClone (string $ property , callable $ func ): static
31
+ {
32
+ if (!isset ($ this ->$ property ) || !is_array ($ this ->$ property ))
33
+ {
34
+ throw new GenericApiException ();
35
+ }
36
+
37
+ $ resp = clone $ this ;
38
+ $ resp ->$ property = array_filter ($ this ->$ property , $ func );
39
+ return $ resp ;
40
+ }
19
41
}
You can’t perform that action at this time.
0 commit comments