Skip to content

Commit a7a44ee

Browse files
committed
adapt code for sapnwrfc 2.1.0
1 parent c518a0c commit a7a44ee

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/SapRfc.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use phpsap\exceptions\IncompleteConfigException;
1212
use phpsap\exceptions\SapLogicException;
1313
use phpsap\exceptions\UnknownFunctionException;
14+
use phpsap\interfaces\Config\IConfiguration;
1415
use phpsap\interfaces\exceptions\IIncompleteConfigException;
1516
use phpsap\interfaces\exceptions\IInvalidArgumentException;
1617
use phpsap\saprfc\Traits\ApiTrait;
@@ -20,6 +21,7 @@
2021
use SAPNWRFC\ConnectionException as ModuleConnectionException;
2122
use SAPNWRFC\FunctionCallException as ModuleFunctionCallException;
2223
use SAPNWRFC\RemoteFunction;
24+
use TypeError;
2325

2426
use function array_merge;
2527
use function get_object_vars;
@@ -133,14 +135,19 @@ protected function getConnection(): Connection
133135
try {
134136
if ($config->getTrace() !== null) {
135137
/**
136-
* \SAPNWRFC\Connection::TRACE_LEVEL_* uses the same values
137-
* as \phpsap\interfaces\Config\IConfigCommon::TRACE_*.
138-
* Therefore, no mapping is necessary.
138+
* SAPNWRFC introduced TRACE_DETAILED (3) in v2.1.0 which
139+
* is not available via the interface.
139140
*/
140-
Connection::setTraceLevel($config->getTrace());
141+
$trace = match ($config->getTrace()) {
142+
IConfiguration::TRACE_FULL => 4,
143+
IConfiguration::TRACE_VERBOSE => 2,
144+
IConfiguration::TRACE_BRIEF => 1,
145+
default => 0,
146+
};
147+
Connection::setTraceLevel($trace);
141148
}
142149
$this->connection = new Connection($moduleConfig);
143-
} catch (ModuleConnectionException $exception) {
150+
} catch (TypeError | ModuleConnectionException $exception) {
144151
throw new ConnectionFailedException(sprintf(
145152
'Connection creation failed: %s',
146153
$exception->getMessage()
@@ -155,9 +162,6 @@ protected function getConnection(): Connection
155162
*/
156163
public function extractApi(): RemoteApi
157164
{
158-
/**
159-
* InvalidArgumentException is never thrown, because no parameter is given.
160-
*/
161165
$api = new RemoteApi();
162166
foreach ($this->saprfcFunctionInterface() as $name => $element) {
163167
try {
@@ -192,13 +196,7 @@ public function extractApi(): RemoteApi
192196
*/
193197
public function saprfcFunctionInterface(): array
194198
{
195-
$function = $this->getFunction();
196-
if (method_exists($function, 'getFunctionDescription')) {
197-
return $function->getFunctionDescription();
198-
}
199-
$result = get_object_vars($function);
200-
unset($result['name']);
201-
return $result;
199+
return $this->getFunction()->getFunctionDescription();
202200
}
203201

204202
/**
@@ -227,7 +225,7 @@ public function invoke(): array
227225
$result = $this
228226
->getFunction()
229227
->invoke($params, self::$invokeOptions);
230-
} catch (ModuleFunctionCallException $exception) {
228+
} catch (TypeError | ModuleFunctionCallException $exception) {
231229
throw new FunctionCallException(sprintf(
232230
'Function call %s failed: %s',
233231
$this->getName(),

src/Traits/ApiTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ private function mapType(string $type): string
8282
'RFCTYPE_NUM' => IValue::TYPE_INTEGER,
8383
'RFCTYPE_INT1' => IValue::TYPE_INTEGER,
8484
'RFCTYPE_INT2' => IValue::TYPE_INTEGER,
85-
'RFCTYPE_BCD' => IValue::TYPE_FLOAT,
85+
'RFCTYPE_INT8' => IValue::TYPE_INTEGER,
86+
'RFCTYPE_BCD' => IValue::TYPE_STRING,
8687
'RFCTYPE_FLOAT' => IValue::TYPE_FLOAT,
8788
'RFCTYPE_CHAR' => IValue::TYPE_STRING,
8889
'RFCTYPE_STRING' => IValue::TYPE_STRING,

0 commit comments

Comments
 (0)