diff --git a/Samples/browser.php b/Samples/browser.php index b6cc2db4..16c26522 100644 --- a/Samples/browser.php +++ b/Samples/browser.php @@ -46,9 +46,9 @@ function handleRequest(\stdClass $request, \Fhp\FinTs $fints) case 'getTanMedia': return array_map(function ($medium) { return ['name' => $medium->getName(), 'phoneNumber' => $medium->getPhoneNumber()]; - }, $fints->getTanMedia(intval($request->tanmode))); + }, $fints->getTanMedia((int)$request->tanmode)); case 'login': - $fints->selectTanMode(intval($request->tanmode), $request->tanmedium ?? null); + $fints->selectTanMode((int)$request->tanmode, $request->tanmedium ?? null); $login = $fints->login(); if ($login->needsTan()) { $tanRequest = $login->getTanRequest(); diff --git a/Samples/tanModesAndMedia.php b/Samples/tanModesAndMedia.php index d2455071..1f7ce215 100644 --- a/Samples/tanModesAndMedia.php +++ b/Samples/tanModesAndMedia.php @@ -25,11 +25,11 @@ echo "Which one do you want to use? Index:\n"; $tanModeIndex = trim(fgets(STDIN)); -if (!is_numeric($tanModeIndex) || !array_key_exists(intval($tanModeIndex), $tanModes)) { +if (!is_numeric($tanModeIndex) || !array_key_exists((int)$tanModeIndex, $tanModes)) { echo 'Invalid index!'; return; } -$tanMode = $tanModes[intval($tanModeIndex)]; +$tanMode = $tanModes[(int)$tanModeIndex]; echo 'You selected ' . $tanMode->getName() . "\n"; // In case the selected TAN mode requires a TAN medium (e.g. if the user picked mTAN, they may have to pick the mobile @@ -49,11 +49,11 @@ echo "Which one do you want to use? Index:\n"; $tanMediumIndex = trim(fgets(STDIN)); - if (!is_numeric($tanMediumIndex) || !array_key_exists(intval($tanMediumIndex), $tanMedia)) { + if (!is_numeric($tanMediumIndex) || !array_key_exists((int)$tanMediumIndex, $tanMedia)) { echo 'Invalid index!'; return; } - $tanMedium = $tanMedia[intval($tanMediumIndex)]; + $tanMedium = $tanMedia[(int)$tanMediumIndex]; echo 'You selected ' . $tanMedium->getName() . "\n"; } else { $tanMedium = null; diff --git a/src/MT535/MT535.php b/src/MT535/MT535.php index 3733d8b1..d7caf5af 100644 --- a/src/MT535/MT535.php +++ b/src/MT535/MT535.php @@ -27,7 +27,7 @@ public function parseDepotWert(): float { preg_match('/:16R:ADDINFO(.*?):16S:ADDINFO/sm', $this->cleanedRawData, $block); preg_match('/EUR(.*)/sm', $block[1], $matches); - return floatval(str_replace(',', '.', $matches[1])); + return (float) str_replace(',', '.', $matches[1]); } public function parseHoldings(): StatementOfHoldings @@ -66,12 +66,12 @@ public function parseHoldings(): StatementOfHoldings $holding->setCurrency($r[1]); // Price preg_match('/^.{14}(.*)/sm', $iwn[2], $r); - $holding->setPrice(floatval(str_replace(',', '.', $r[1]))); + $holding->setPrice((float) str_replace(',', '.', $r[1])); } elseif ($iwn[1] == 'A') { $holding->setCurrency('%'); // Price preg_match('/^.{11}(.*)/sm', $iwn[2], $r); - $holding->setPrice(floatval(str_replace(',', '.', $r[1])) / 100); + $holding->setPrice((float) str_replace(',', '.', $r[1]) / 100); } } @@ -80,7 +80,7 @@ public function parseHoldings(): StatementOfHoldings if (preg_match('/:93B::(.*?):/sm', $block, $iwn)) { // Amount preg_match('/^.{11}(.*)/sm', $iwn[1], $r); - $holding->setAmount(floatval(str_replace(',', '.', $r[1]))); + $holding->setAmount((float) str_replace(',', '.', $r[1])); } if ($holding->getAmount() !== null && $holding->getPrice() !== null) { diff --git a/src/Model/StatementOfAccount/Transaction.php b/src/Model/StatementOfAccount/Transaction.php index 7ebb9d7c..31e959b1 100644 --- a/src/Model/StatementOfAccount/Transaction.php +++ b/src/Model/StatementOfAccount/Transaction.php @@ -350,7 +350,7 @@ public function getPN(): int */ public function setPN($nr): static { - $this->pn = intval($nr); + $this->pn = (int) $nr; return $this; } @@ -370,7 +370,7 @@ public function getTextKeyAddition(): int */ public function setTextKeyAddition($textKeyAddition): static { - $this->textKeyAddition = intval($textKeyAddition); + $this->textKeyAddition = (int) $textKeyAddition; return $this; } } diff --git a/src/Protocol/Message.php b/src/Protocol/Message.php index 853f64dc..558a727b 100644 --- a/src/Protocol/Message.php +++ b/src/Protocol/Message.php @@ -264,7 +264,7 @@ public static function createWrappedMessage($plainSegments, FinTsOptions $option $message->plainSegments = $plainSegments instanceof MessageBuilder ? $plainSegments->segments : $plainSegments; $tanMode = $tanMode instanceof NoPsd2TanMode ? null : $tanMode; - $randomReference = strval(rand(1000000, 9999999)); // Call unqualified rand() for unit test mocking to work. + $randomReference = (string) rand(1000000, 9999999); // Call unqualified rand() for unit test mocking to work. $signature = BenutzerdefinierteSignaturV1::create($credentials->getPin(), $tan); $numPlainSegments = count($message->plainSegments); // This is N, see $encryptedSegments. diff --git a/src/Segment/BaseDescriptor.php b/src/Segment/BaseDescriptor.php index b7db851e..650afbe8 100644 --- a/src/Segment/BaseDescriptor.php +++ b/src/Segment/BaseDescriptor.php @@ -171,7 +171,7 @@ private static function getIntAnnotation(string $name, string $docComment): ?int if (!is_numeric($val)) { throw new \InvalidArgumentException("Annotation $name has non-integer value $val"); } - return intval($val); + return (int) $val; } /** diff --git a/src/Segment/DegDescriptor.php b/src/Segment/DegDescriptor.php index a85f17a2..99238d47 100644 --- a/src/Segment/DegDescriptor.php +++ b/src/Segment/DegDescriptor.php @@ -39,7 +39,7 @@ protected function __construct(string $class) // Check if the name ends in V2 or so, implicitly assume V1. if (preg_match('/^[A-Z]+[vV]([0-9]+)$/', $clazz->getShortName(), $match) === 1) { - $this->version = intval($match[1]); + $this->version = (int) $match[1]; } } catch (\ReflectionException $e) { throw new \RuntimeException($e); diff --git a/src/Segment/HNHBK/HNHBKv3.php b/src/Segment/HNHBK/HNHBKv3.php index a9cbe96b..9d5a1fa3 100644 --- a/src/Segment/HNHBK/HNHBKv3.php +++ b/src/Segment/HNHBK/HNHBKv3.php @@ -35,7 +35,7 @@ class HNHBKv3 extends BaseSegment public function getNachrichtengroesse(): int { - return intval($this->nachrichtengroesse); + return (int) $this->nachrichtengroesse; } /** diff --git a/src/Segment/SegmentDescriptor.php b/src/Segment/SegmentDescriptor.php index 366eb7ee..47882b7e 100644 --- a/src/Segment/SegmentDescriptor.php +++ b/src/Segment/SegmentDescriptor.php @@ -44,8 +44,8 @@ protected function __construct(string $class) if (preg_match('/^([A-Z]+)v([0-9]+)$/', $clazz->getShortName(), $match) !== 1) { throw new \InvalidArgumentException("Invalid segment class name: $class"); } - $this->kennung = strval($match[1]); - $this->version = intval($match[2]); + $this->kennung = $match[1]; + $this->version = (int) $match[2]; } catch (\ReflectionException $e) { throw new \RuntimeException($e); } diff --git a/src/Segment/VPP/VopHelper.php b/src/Segment/VPP/VopHelper.php index 1bc5cefe..26018a73 100644 --- a/src/Segment/VPP/VopHelper.php +++ b/src/Segment/VPP/VopHelper.php @@ -121,7 +121,7 @@ public static function checkVopConfirmationRequired( // For a single transaction, we can do better than "CompletedPartialMatch", // which can indicate either CompletedCloseMatch or CompletedNoMatch - if (intval($report->CstmrPmtStsRpt->OrgnlGrpInfAndSts->OrgnlNbOfTxs ?: 0) === 1 + if ((int) ($report->CstmrPmtStsRpt->OrgnlGrpInfAndSts->OrgnlNbOfTxs ?: 0) === 1 && $verificationResult === VopVerificationResult::CompletedPartialMatch && $verificationResultCode = $report->CstmrPmtStsRpt->OrgnlPmtInfAndSts->TxInfAndSts?->TxSts ) { diff --git a/src/Syntax/Parser.php b/src/Syntax/Parser.php index 018d272b..c84ce517 100644 --- a/src/Syntax/Parser.php +++ b/src/Syntax/Parser.php @@ -63,7 +63,7 @@ public static function splitEscapedString(string $delimiter, string $str, bool $ break; } $matchedStr = $match[0][0]; // $match[0] refers to the entire matched string. [0] has the content - $matchedOffset = intval($match[0][1]); // and [1] has the offset within $str. + $matchedOffset = (int) $match[0][1]; // and [1] has the offset within $str. if ($matchedStr === '?') { // It's an escape character, so we should ignore this character and the next one. $offset = $matchedOffset + 2; @@ -79,7 +79,7 @@ public static function splitEscapedString(string $delimiter, string $str, bool $ // Note: The FinTS specification says that the length of the binary block is given in bytes (not // characters) and PHP's string functions like substr() or preg_match() also operate on byte offsets, so // this is fine. - $offset = $matchedOffset + strlen($matchedStr) + intval($binaryLength); + $offset = $matchedOffset + strlen($matchedStr) + (int) $binaryLength; if ($offset > strlen($str)) { throw new \InvalidArgumentException( "Incomplete binary block at offset $matchedOffset, declared length $binaryLength, but " @@ -124,13 +124,13 @@ public static function parseDataElement(string $rawValue, string $type) if (!is_numeric($rawValue)) { throw new \InvalidArgumentException("Invalid int: $rawValue"); } - return intval($rawValue); + return (int) $rawValue; } elseif ($type === 'float') { $rawValue = str_replace(',', '.', $rawValue, $numCommas); if (!is_numeric($rawValue) || $numCommas !== 1) { throw new \InvalidArgumentException("Invalid float: $rawValue"); } - return floatval($rawValue); + return (float) $rawValue; } elseif ($type === 'bool' || $type === 'boolean') { if ($rawValue === 'J') { return true; @@ -170,7 +170,7 @@ public static function parseBinaryBlock(string $rawValue): ?Bin throw new \InvalidArgumentException("Invalid binary block length: $lengthStr"); } - $length = intval($lengthStr); + $length = (int) $lengthStr; $result = new Bin(substr($rawValue, $delimiterPos + 1)); $actualLength = strlen($result->getData()); diff --git a/src/Syntax/Serializer.php b/src/Syntax/Serializer.php index c66eb829..fcc134f5 100644 --- a/src/Syntax/Serializer.php +++ b/src/Syntax/Serializer.php @@ -35,7 +35,7 @@ public static function serializeDataElement($value, string $type): string if ($type === 'int' || $type === 'integer' || $type === 'string') { // Convert UTF-8 (PHP's encoding) to ISO-8859-1 (FinTS wire format encoding) - return static::escape(mb_convert_encoding(strval($value), 'ISO-8859-1', 'UTF-8')); + return static::escape(mb_convert_encoding((string) $value, 'ISO-8859-1', 'UTF-8')); } if ($type === 'float') {