Skip to content

Commit 0a5c6e6

Browse files
committed
[~]: use &references for string|array parameter from private methods
1 parent c69917f commit 0a5c6e6

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/EDI/Encoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function encodeSegment($row): string
159159
*
160160
* @return string
161161
*/
162-
private function escapeValue($str): string
162+
private function escapeValue(&$str): string
163163
{
164164
$search = [
165165
$this->symbRel,

src/EDI/Interpreter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function prepare($parsed): array
183183
*
184184
* @return array
185185
*/
186-
private function splitMessages($parsed, &$errors): array
186+
private function splitMessages(&$parsed, &$errors): array
187187
{
188188
// init
189189
$messages = [];
@@ -267,7 +267,7 @@ private function splitMessages($parsed, &$errors): array
267267
*
268268
* @return array
269269
*/
270-
private function loopMessage($message, $xml, &$errors): array
270+
private function loopMessage(&$message, $xml, &$errors): array
271271
{
272272
// init
273273
$groupedEdi = [];
@@ -363,7 +363,7 @@ private function processXmlGroup($elm, &$message, &$segmentIdx, &$array, &$error
363363
*
364364
* @return void
365365
*/
366-
private function processXmlSegment($elm, $message, &$segmentIdx, &$array, &$errors)
366+
private function processXmlSegment($elm, &$message, &$segmentIdx, &$array, &$errors)
367367
{
368368
$segmentVisited = false;
369369
for ($i = 0; $i < $elm['maxrepeat']; $i++) {
@@ -412,7 +412,7 @@ private function processXmlSegment($elm, $message, &$segmentIdx, &$array, &$erro
412412
*
413413
* @return void
414414
*/
415-
private function doAddArray(&$array, $jsonMessage)
415+
private function doAddArray(&$array, &$jsonMessage)
416416
{
417417
if (isset($array[$jsonMessage['key']])) {
418418
if (
@@ -440,7 +440,7 @@ private function doAddArray(&$array, $jsonMessage)
440440
*
441441
* @return array
442442
*/
443-
private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null): array
443+
private function processSegment(&$segment, &$xmlMap, $segmentIdx, &$errors = null): array
444444
{
445445
$id = $segment[0];
446446

@@ -535,10 +535,10 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
535535
*
536536
* @return array
537537
*/
538-
private function processService($segments): array
538+
private function processService(&$segments): array
539539
{
540540
$processed = [];
541-
foreach ($segments as $seg) {
541+
foreach ($segments as &$seg) {
542542
$jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
543543
$processed[$jsonsegment['key']] = $jsonsegment['value'];
544544
}

src/EDI/Parser.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function __construct($url = null)
111111
if ($this->unaChecked !== false) {
112112
$this->resetUNA();
113113
}
114+
114115
if ($this->unbChecked !== false) {
115116
$this->resetUNB();
116117
}
@@ -122,25 +123,25 @@ public function __construct($url = null)
122123
return;
123124
}
124125
if (\is_array($url)) {
125-
/**
126-
* Object constructed with an array as argument
127-
*/
126+
//
127+
// Object constructed with an array as argument
128+
//
128129
if (\count($url) == 1) {
129130
$url = $this->unwrap($url[0]);
130131
}
131132
$this->rawSegments = $url;
132133
/** @noinspection UnusedFunctionResultInspection */
133134
$this->parse($url);
134135
} elseif (file_exists($url)) {
135-
/**
136-
* Object constructed with a path to a file as argument
137-
*/
136+
//
137+
// Object constructed with a path to a file as argument
138+
//
138139
/** @noinspection UnusedFunctionResultInspection */
139140
$this->load($url);
140141
} else {
141-
/**
142-
* Object constructed with a string as argument
143-
*/
142+
//
143+
// Object constructed with a string as argument
144+
//
144145
/** @noinspection UnusedFunctionResultInspection */
145146
$this->loadString($url);
146147
}
@@ -159,17 +160,13 @@ public function parse(&$file2): array
159160
for ($i = 1; $i <= $t; $i++) {
160161
$line = \array_shift($file2);
161162

162-
/**
163-
* Null byte and carriage return removal (CR+LF)
164-
*/
163+
// Null byte and carriage return removal (CR+LF)
165164
$line = \preg_replace('#[\x00\r\n]#', '', $line);
166165
if (\preg_match($this->stripChars, $line)) {
167166
$this->errors[] = "There's a not printable character on line " . $i . ": " . $line;
168167
}
169168

170-
/**
171-
* Basic sanitization, remove non printable chars
172-
*/
169+
// Basic sanitization, remove non printable chars
173170
$line = \preg_replace($this->stripChars, '', \trim($line));
174171
if (\strlen($line) < 2) {
175172
continue;
@@ -316,11 +313,12 @@ public function analyseUNH($line)
316313
*
317314
* @return string[]
318315
*/
319-
private function unwrap($string): array
316+
private function unwrap(&$string): array
320317
{
321318
if (!$this->unaChecked && \strpos($string, "UNA") === 0) {
322319
$this->analyseUNA(\preg_replace("#^UNA#", "", substr($string, 0, 9)));
323320
}
321+
324322
if (!$this->unbChecked && \strpos($string, "UNB") === 0) {
325323
$this->analyseUNB(\preg_replace("#^UNB\+#", "", substr($string, 0, 8)));
326324
}
@@ -350,7 +348,7 @@ private function unwrap($string): array
350348
*
351349
* @return array[]|string[]
352350
*/
353-
private function splitSegment($str): array
351+
private function splitSegment(&$str): array
354352
{
355353
// remove ending symbEnd
356354
$str = \trim(
@@ -405,7 +403,7 @@ private function splitSegment($str): array
405403
*
406404
* @return mixed
407405
*/
408-
private function splitData($str)
406+
private function splitData(&$str)
409407
{
410408
$replace = function ($string) {
411409
$regex = self::$DELIMITER . $this->symbRel . "(?=" . $this->symbRel . ")|" . $this->symbRel . "(?=" . $this->sepData . ")|" . $this->symbRel . "(?=" . $this->sepComp . ")|" . $this->symbRel . "(?=" . $this->symbEnd . ")" . self::$DELIMITER;

0 commit comments

Comments
 (0)