Skip to content

Commit 3fc4cc3

Browse files
committed
[+]: fixes reported by phpstorm
1 parent 564d2b1 commit 3fc4cc3

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

src/EDI/Analyser.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ public function loadMessageXml(string $message_xml_file)
3333
}
3434

3535
$messageXml = new \SimpleXMLIterator($messageXmlString);
36-
unset($messageXmlString);
37-
$message = [
36+
37+
return [
3838
'defaults' => $this->readMessageDefaults($messageXml),
3939
'segments' => $this->readXmlNodes($messageXml),
4040
];
41-
unset($messageXml);
42-
43-
return $message;
4441
}
4542

4643
/**
@@ -58,7 +55,6 @@ public function loadCodesXml(string $codesXml)
5855
}
5956

6057
$codesXml = new \SimpleXMLIterator($codesXmlString);
61-
unset($codesXmlString);
6258
$codes = [];
6359
foreach ($codesXml as $codeCollection) {
6460
\assert($codeCollection instanceof \SimpleXMLIterator);
@@ -111,12 +107,14 @@ public function loadSegmentsXml(string $segment_xml_file)
111107
$segments_xml = null;
112108

113109
foreach ($xml as $segmentNode) {
110+
\assert($segmentNode instanceof \SimpleXMLElement);
114111

115-
/** @noinspection PhpSillyAssignmentInspection - hack for phpstan */
116-
/* @var \SimpleXMLElement $segmentNode */
117-
$segmentNode = $segmentNode;
112+
$segmentNodeAttributes = $segmentNode->attributes();
113+
if ($segmentNodeAttributes === null) {
114+
continue;
115+
}
118116

119-
$qualifier = (string) $segmentNode->attributes()->id;
117+
$qualifier = (string) $segmentNodeAttributes->id;
120118
$segment = [];
121119
$segment['attributes'] = $this->readAttributesArray($segmentNode);
122120
$details = $this->readXmlNodes($segmentNode);
@@ -193,7 +191,7 @@ public function process(array $data, array $rawSegments = null): string
193191
$r[] = ' length: ' . $d_sub_desc_attr['length'];
194192
}
195193

196-
//check for skipped data
194+
// check for skipped data
197195
unset(
198196
$d_sub_desc_attr['id'],
199197
$d_sub_desc_attr['name'],

src/EDI/Encoder.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,18 @@ public function encodeSegment(array $row): string
119119
$str = '';
120120
$t = \count($row);
121121

122+
/** @noinspection AlterInForeachInspection */
122123
foreach ($row as $i => &$iValue) {
123124
if (\is_array($iValue)) {
124-
if (\count($iValue) === 1
125-
&& \is_array(\reset($iValue))
125+
if (
126+
\count($iValue) === 1
127+
&&
128+
\is_array(\reset($iValue))
126129
) {
127130
$iValue = \array_pop($iValue);
128131
}
129132

133+
/** @noinspection NotOptimalIfConditionsInspection */
130134
if (\is_array($iValue)) {
131135
foreach ($iValue as &$temp) {
132136
$temp = $this->escapeValue($temp);
@@ -145,7 +149,6 @@ public function encodeSegment(array $row): string
145149
}
146150
$str .= $this->sepData;
147151
}
148-
unset($iValue);
149152

150153
$str .= $this->symbEnd;
151154

@@ -182,11 +185,7 @@ public function get(): string
182185
*/
183186
public function setUNA(string $chars, bool $user_call = true): bool
184187
{
185-
if (
186-
\is_string($chars)
187-
&&
188-
\strlen($chars) == 6
189-
) {
188+
if (\strlen($chars) == 6) {
190189
$this->sepComp = $chars[0];
191190
$this->sepData = $chars[1];
192191
$this->sepDec = $chars[2];

src/EDI/Parser.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,14 @@ public function getRawSegments()
342342
*
343343
* @param string $url
344344
*
345-
* @return array
345+
* @return array|false
346346
*/
347-
public function load($url): array
347+
public function load($url)
348348
{
349349
$file = \file_get_contents($url);
350+
if ($file === false) {
351+
return false;
352+
}
350353

351354
return $this->loadString($file);
352355
}
@@ -533,13 +536,21 @@ private function splitSegment(string &$str): array
533536
//
534537
// Question mark is represented by ??
535538

536-
if ($this->symbEnd && \strpos($value, $this->symbEnd) !== false) {
539+
if (
540+
$this->symbEnd
541+
&&
542+
\strpos($value, $this->symbEnd) !== false
543+
) {
537544
if (\preg_match(self::$DELIMITER . '(?<!' . $this->symbRel . ')' . $this->symbEnd . self::$DELIMITER, $value)) {
538545
$this->errors[] = "There's a " . \stripslashes($this->symbEnd) . ' not escaped in the data; string ' . $str;
539546
}
540547
}
541548

542-
if ($this->symbUnescapedRel && \strpos($value, $this->symbUnescapedRel) !== false) {
549+
if (
550+
$this->symbUnescapedRel
551+
&&
552+
\strpos($value, $this->symbUnescapedRel) !== false
553+
) {
543554
if (\preg_match(self::$DELIMITER . '(?<!' . $this->symbRel . ')' . $this->symbRel . '(?!' . $this->symbRel . ')(?!' . $this->sepData . ')(?!' . $this->sepComp . ')(?!' . $this->symbEnd . ')' . self::$DELIMITER, $value)) {
544555
$this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel ?? '') . ' in the data; string ' . $value;
545556
}
@@ -548,7 +559,6 @@ private function splitSegment(string &$str): array
548559
// split on "sepComp"
549560
$value = $this->splitData($value);
550561
}
551-
unset($value);
552562

553563
return $matches;
554564
}

src/EDI/Reader.php

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required =
216216
$filter_elements = false;
217217
}
218218

219+
// init
219220
$segment = false;
220221
$segment_count = 0;
221222

0 commit comments

Comments
 (0)