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

Commit 68237c5

Browse files
committed
Another array declaration type
1 parent 7a58ab9 commit 68237c5

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,17 @@ public function arrayDeclaredAt($phpcsFile, $stackPtr)
351351
}
352352
}//end if
353353

354+
// - $obj->arr[] = [];
355+
if ($tokens[$before1]['code'] === T_CLOSE_SQUARE_BRACKET) {
356+
$before1 = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$before1]['bracket_opener'] - 1), null, true);
357+
}
358+
354359
// Is it a string?, if so expect object or constant.
355360
// - '$obj->arr = [];'.
356361
// - 'MY_CONST = [];'
357362
// - 'const MY_CONST = [];.
358363
if ($tokens[$before1]['code'] === T_STRING) {
359364
$before2 = $phpcsFile->findPrevious(T_WHITESPACE, ($before1 - 1), null, true);
360-
361365
// Is it a constant?
362366
if ($tokens[$before2]['code'] === T_CONST) {
363367
$indentStart = $before2;

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,15 @@ class MyClass {
7171
'message' => pg_last_error($this->connID)
7272
];
7373
}
74+
75+
public function error2()
76+
{
77+
$this->QBWhere[] = ['condition' => $like_statement, 'escape' => $escape];
78+
79+
$this->QBWhere[] = [
80+
'condition' => $like_statement,
81+
'escape' => $escape,
82+
];
83+
84+
}
7485
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,18 @@ class MyClass {
135135
'message' => pg_last_error($this->connID),
136136
];
137137
}
138+
139+
public function error2()
140+
{
141+
$this->QBWhere[] = [
142+
'condition' => $like_statement,
143+
'escape' => $escape,
144+
];
145+
146+
$this->QBWhere[] = [
147+
'condition' => $like_statement,
148+
'escape' => $escape,
149+
];
150+
151+
}
138152
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function getErrorList()
7373
64 => 1,
7474
70 => 1,
7575
71 => 1,
76+
77 => 1,
77+
80 => 1,
78+
81 => 1,
79+
82 => 1,
7680
);
7781

7882
}//end getErrorList()

0 commit comments

Comments
 (0)