Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit 6e0879d

Browse files
committed
More array declarations
1 parent 62aa4f9 commit 6e0879d

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,24 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
374374
case T_COMMA:
375375
// The end of an array line "[],".
376376
// Argument in a function "$item->save($data, [...], ...)".
377-
$firstOnLine = $phpcsFile->findFirstOnLine(array(T_VARIABLE, T_CLOSE_SHORT_ARRAY), $prevNonWhitespaceToken);
377+
$starts = array(
378+
T_VARIABLE,
379+
T_VAR,
380+
T_PUBLIC,
381+
T_PRIVATE,
382+
T_PROTECTED,
383+
T_ARRAY_CAST,
384+
T_UNSET_CAST,
385+
T_OBJECT_CAST,
386+
T_STATIC,
387+
T_CONST,
388+
T_RETURN,
389+
T_OBJECT_OPERATOR,
390+
T_CLOSE_SHORT_ARRAY,
391+
T_CONSTANT_ENCAPSED_STRING,
392+
);
393+
394+
$firstOnLine = $phpcsFile->findFirstOnLine($starts, $prevNonWhitespaceToken);
378395
$indentStart = $firstOnLine;
379396
break;
380397
default:
@@ -592,6 +609,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
592609
true
593610
);
594611

612+
if ($nextContent === false) {
613+
break;
614+
}
615+
595616
$currentEntry['value'] = $nextContent;
596617
$indices[] = $currentEntry;
597618
$lastToken = $nextToken;

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,36 @@ class MyClass {
112112
'version' => $version,
113113
'name' => $this->name,
114114
]);
115+
116+
$message->setCustomProperty('user_info', array(
117+
'id' => $id,
118+
'name' => 'Test message'
119+
)
120+
);
121+
122+
$users = [
123+
[
124+
'id' => 1,
125+
'name' => 'John',
126+
'email' => 'john@example.com',
127+
'fact' => 'Loves coding',
128+
],
129+
[
130+
'id' => 2,
131+
'name' => 'Jim',
132+
'email' => 'jim@example.com',
133+
'fact' => 'Developed on CodeIgniter',
134+
],
135+
[
136+
'id' => 3,
137+
'name' => 'Jane',
138+
'email' => 'jane@example.com',
139+
'fact' => 'Lives in the USA', [
140+
'hobbies' => [
141+
'guitar',
142+
'cycling',
143+
],
144+
]
145+
],
146+
];
115147
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,36 @@ class MyClass {
178178
'version' => $version,
179179
'name' => $this->name,
180180
]);
181+
182+
$message->setCustomProperty('user_info', [
183+
'id' => $id,
184+
'name' => 'Test message',
185+
]
186+
);
187+
188+
$users = [
189+
[
190+
'id' => 1,
191+
'name' => 'John',
192+
'email' => 'john@example.com',
193+
'fact' => 'Loves coding',
194+
],
195+
[
196+
'id' => 2,
197+
'name' => 'Jim',
198+
'email' => 'jim@example.com',
199+
'fact' => 'Developed on CodeIgniter',
200+
],
201+
[
202+
'id' => 3,
203+
'name' => 'Jane',
204+
'email' => 'jane@example.com',
205+
'fact' => 'Lives in the USA', [
206+
'hobbies' => [
207+
'guitar',
208+
'cycling',
209+
],
210+
]
211+
],
212+
];
181213
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function getErrorList()
9292
107 => 1,
9393
112 => 1,
9494
113 => 1,
95+
116 => 1,
96+
117 => 1,
97+
118 => 1,
98+
119 => 1,
9599
);
96100

97101
}//end getErrorList()

0 commit comments

Comments
 (0)