Skip to content

Commit 3c18ea1

Browse files
committed
refactor API interfaces #10
1 parent 7fdb01d commit 3c18ea1

File tree

5 files changed

+77
-69
lines changed

5 files changed

+77
-69
lines changed

src/Api/IArray.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
/**
1111
* Interface IArray
1212
*
13-
* API extend the logic of values to contain member elements.
13+
* API arrays extend the logic of elements to contain member elements. They are
14+
* the basis for structs and tables.
1415
*
1516
* @package phpsap\interfaces\Api
1617
* @author Gregor J.
1718
* @license MIT
1819
*/
19-
interface IArray extends IValue
20+
interface IArray extends IElement
2021
{
2122
/**
2223
* JSON configuration key for members array.
@@ -25,12 +26,12 @@ interface IArray extends IValue
2526

2627
/**
2728
* Cast a given output value to the implemented value.
28-
* @param array $value The output array to typecast.
29-
* @return array
29+
* @param array<int|string, mixed> $value The output array to typecast.
30+
* @return array<int|string, mixed>
3031
* @throws IArrayElementMissingException
3132
* @throws IInvalidArgumentException
3233
*/
33-
public function cast($value): array;
34+
public function cast(array $value): array;
3435

3536
/**
3637
* Return an array of member elements.

src/Api/IElement.php

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
/**
1313
* Interface IElement
1414
*
15-
* API elements are struct or table members and have no direction or optional flag
16-
* of their own.
15+
* API elements build the basis for API values, structs and tables. They have a
16+
* name, a type, a direction and an optional flag. However, they don't contain
17+
* any values.
1718
*
1819
* @package phpsap\interfaces\Api
1920
* @author Gregor J.
@@ -22,60 +23,34 @@
2223
interface IElement extends IJsonSerializable
2324
{
2425
/**
25-
* API element that casts to PHP string.
26-
*/
27-
public const TYPE_STRING = 'string';
28-
29-
/**
30-
* API element that casts to PHP int.
31-
*/
32-
public const TYPE_INTEGER = 'int';
33-
34-
/**
35-
* API element that casts to PHP bool.
36-
*/
37-
public const TYPE_BOOLEAN = 'bool';
38-
39-
/**
40-
* API element that casts to PHP float.
41-
*/
42-
public const TYPE_FLOAT = 'float';
43-
44-
/**
45-
* API element that casts to a hexadecimal encoded binary to a binary.
46-
* (direction: output)
47-
*/
48-
public const TYPE_HEXBIN = 'hexbin';
49-
50-
/**
51-
* API date element that casts to a DateTime object.
26+
* JSON configuration key for type value.
5227
*/
53-
public const TYPE_DATE = 'date';
28+
public const JSON_TYPE = 'type';
5429

5530
/**
56-
* API time element that casts to a DateTime object.
31+
* JSON configuration key for name value.
5732
*/
58-
public const TYPE_TIME = 'time';
33+
public const JSON_NAME = 'name';
5934

6035
/**
61-
* API virtual timestamp element (e.g. string) that casts to a DateTime object.
36+
* API input element.
6237
*/
63-
public const TYPE_TIMESTAMP = 'timestamp';
38+
public const DIRECTION_INPUT = 'input';
6439

6540
/**
66-
* API virtual calendar week element (e.g. string) that casts to a DateTime object.
41+
* API output element.
6742
*/
68-
public const TYPE_WEEK = 'week';
43+
public const DIRECTION_OUTPUT = 'output';
6944

7045
/**
71-
* JSON configuration key for type value.
46+
* JSON configuration key for direction value.
7247
*/
73-
public const JSON_TYPE = 'type';
48+
public const JSON_DIRECTION = 'direction';
7449

7550
/**
76-
* JSON configuration key for name value.
51+
* JSON configuration key for is optional flag.
7752
*/
78-
public const JSON_NAME = 'name';
53+
public const JSON_OPTIONAL = 'optional';
7954

8055
/**
8156
* The PHP type of the element.
@@ -90,10 +65,15 @@ public function getType(): string;
9065
public function getName(): string;
9166

9267
/**
93-
* Cast a given output value to the implemented value.
94-
* @param bool|int|float|string $value The output to typecast.
95-
* @return bool|int|float|string|SapDateTime|SapDateInterval
96-
* @throws IInvalidArgumentException
68+
* Get the direction of the parameter.
69+
* interface.
70+
* @return string
71+
*/
72+
public function getDirection(): string;
73+
74+
/**
75+
* Is the element optional?
76+
* @return bool
9777
*/
98-
public function cast($value);
78+
public function isOptional(): bool;
9979
}

src/Api/IStruct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Interface IStruct
99
*
10-
* API extend the logic of arrays to contain member elements.
10+
* API structs extend the logic of arrays to contain an associative array.
1111
*
1212
* @package phpsap\interfaces\Api
1313
* @author Gregor J.

src/Api/ITable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
/**
88
* Interface ITable
99
*
10-
* API extend the logic of arrays but contains rows of member elements.
10+
* API tables extend the logic of arrays to contain an array of associative
11+
* arrays.
1112
*
1213
* @package phpsap\interfaces\Api
1314
* @author Gregor J.

src/Api/IValue.php

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
namespace phpsap\interfaces\Api;
66

7+
use phpsap\DateTime\SapDateInterval;
8+
use phpsap\DateTime\SapDateTime;
9+
use phpsap\interfaces\exceptions\IInvalidArgumentException;
10+
711
/**
812
* Interface IValue
913
*
10-
* API values extend the logic of an element but have a direction (input or output)
11-
* and an optional flag, unlike elements.
14+
* API values extend the logic of an element. They describe primitive values,
15+
* like integers, booleans, strings, etc., but also more complex values, like
16+
* date and time, or intervals.
1217
*
1318
* @package phpsap\interfaces\Api
1419
* @author Gregor J.
@@ -17,35 +22,56 @@
1722
interface IValue extends IElement
1823
{
1924
/**
20-
* API input element.
25+
* API element that casts to PHP string.
26+
*/
27+
public const TYPE_STRING = 'string';
28+
29+
/**
30+
* API element that casts to PHP int.
31+
*/
32+
public const TYPE_INTEGER = 'int';
33+
34+
/**
35+
* API element that casts to PHP bool.
36+
*/
37+
public const TYPE_BOOLEAN = 'bool';
38+
39+
/**
40+
* API element that casts to PHP float.
41+
*/
42+
public const TYPE_FLOAT = 'float';
43+
44+
/**
45+
* API element that casts to a hexadecimal encoded binary to a binary.
46+
* (direction: output)
2147
*/
22-
public const DIRECTION_INPUT = 'input';
48+
public const TYPE_HEXBIN = 'hexbin';
2349

2450
/**
25-
* API output element.
51+
* API date element that casts to a DateTime object.
2652
*/
27-
public const DIRECTION_OUTPUT = 'output';
53+
public const TYPE_DATE = 'date';
2854

2955
/**
30-
* JSON configuration key for direction value.
56+
* API time element that casts to a DateTime object.
3157
*/
32-
public const JSON_DIRECTION = 'direction';
58+
public const TYPE_TIME = 'time';
3359

3460
/**
35-
* JSON configuration key for is optional flag.
61+
* API virtual timestamp element (e.g. string) that casts to a DateTime object.
3662
*/
37-
public const JSON_OPTIONAL = 'optional';
63+
public const TYPE_TIMESTAMP = 'timestamp';
3864

3965
/**
40-
* Get the direction of the parameter.
41-
* interface.
42-
* @return string
66+
* API virtual calendar week element (e.g. string) that casts to a DateTime object.
4367
*/
44-
public function getDirection(): string;
68+
public const TYPE_WEEK = 'week';
4569

4670
/**
47-
* Is the element optional?
48-
* @return bool
71+
* Cast a given output value to the implemented value.
72+
* @param bool|int|float|string $value The output to typecast.
73+
* @return bool|int|float|string|SapDateTime|SapDateInterval
74+
* @throws IInvalidArgumentException
4975
*/
50-
public function isOptional(): bool;
76+
public function cast(bool|int|float|string $value): bool|int|float|string|SapDateTime|SapDateInterval;
5177
}

0 commit comments

Comments
 (0)