Skip to content

Commit 6ff314d

Browse files
committed
Exclude ArrayAccess methods from type declarations checks
1 parent b9cbe77 commit 6ff314d

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public function register()
4141
*/
4242
public function process(File $file, $position)
4343
{
44-
if (Helpers::isHookClosure($file, $position) || Helpers::isHookFunction($file, $position)) {
44+
if (Helpers::functionIsArrayAccess($file, $position)
45+
|| Helpers::isHookClosure($file, $position)
46+
|| Helpers::isHookFunction($file, $position)
47+
) {
4548
return;
4649
}
4750

Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function register()
4141
*/
4242
public function process(File $file, $position)
4343
{
44+
if (Helpers::functionIsArrayAccess($file, $position)) {
45+
return;
46+
}
47+
4448
list($functionStart, $functionEnd) = Helpers::functionBoundaries($file, $position);
4549
if (!$functionStart < 0 || $functionEnd <= 0) {
4650
return;

tests/fixtures/argument-type-declaration.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,33 @@ function b(array $foo, $bar);
213213

214214
function d(array $foo, ArrayObject $bar);
215215
}
216+
217+
class FooAccess implements ArrayAccess {
218+
219+
/**
220+
* @inheritdoc
221+
*/
222+
public function offsetExists($offset)
223+
{
224+
return false;
225+
}
226+
227+
/**
228+
* @inheritdoc
229+
*/
230+
public function offsetGet($offset)
231+
{
232+
return false;
233+
}
234+
235+
/**
236+
* @inheritdoc
237+
*/
238+
public function offsetSet($offset, $value)
239+
{
240+
}
241+
242+
public function offsetUnset($offset)
243+
{
244+
}
245+
}

tests/fixtures/return-type-declaration.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,34 @@ public function test2();
192192
* @return bool
193193
*/
194194
public function test3(): bool ;
195+
}
196+
197+
class FooAccess implements ArrayAccess {
198+
199+
/**
200+
* @inheritdoc
201+
*/
202+
public function offsetExists($offset)
203+
{
204+
return false;
205+
}
206+
207+
/**
208+
* @inheritdoc
209+
*/
210+
public function offsetGet($offset)
211+
{
212+
return false;
213+
}
214+
215+
/**
216+
* @inheritdoc
217+
*/
218+
public function offsetSet($offset, $value)
219+
{
220+
}
221+
222+
public function offsetUnset($offset)
223+
{
224+
}
195225
}

0 commit comments

Comments
 (0)