- Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
After upgrade to phpcs 2.4
or 2.5
I get errors about indentation in arrays. Following code:
public function provideFiles() { return array( 'long description' => array(0, 'something'), 'another long description' => array(1, "something else") ); }
returns error: 6 | Line indented incorrectly; expected at least 16 spaces, found 12. So it should like this:
public function provideFiles() { return array( 'long description' => array(0, 'something'), 'another long description' => array(1, "something else") ); }
I found that It's also fixed when I use short array syntax:
public function provideFiles() { return [ 'long description' => [0, 'something'], 'another long description' => [1, "something else"] ]; }
Short array syntax isn't always solution. This code returns same indentation error at line with 'service 2'
:
$services = array( 'service 1' => Mockery::mock('class 1') ->shouldReceive('setFilter')->once() ->shouldReceive('getNbResults')->atLeast()->once() ->shouldReceive('getSlice')->once()->andReturn(array()) ->getMock(), 'service 2' => Mockery::mock('class 2') ->shouldReceive('__invoke')->once() ->getMock() );
It can be fixed only with temporary variable. Error is caused by line with andReturn(array())
(or andReturn([])
). If I delete this line or use temporary variable it works.
$emptyArray = array(); $services = array( 'service 1' => Mockery::mock('class 1') ->shouldReceive('setFilter')->once() ->shouldReceive('getNbResults')->atLeast()->once() ->shouldReceive('getSlice')->once()->andReturn($emptyArray) ->getMock(), 'service 2' => Mockery::mock('class 2') ->shouldReceive('__invoke')->once() ->getMock() );