<?php

/*
 * Good.
 */
$good = array();

$good = array( 1, 2, 3 );
$good = [ 'a', 'b', 'c' ];

$good = array(
	1,
	2,
	3,
);
$good = [
	'a',
	'b',
	'c',
];

$good = array(
	1 => 'value',
	2 => array( 1 ),
	3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);
$good = [
	'a' => 'value',          // Comment - the extra spacing is fine, might be for alignment with other comments.
	'b' => array( 1 ),
	'c' => apply_filters( 'filter', $input, $var ),
];

// OK: that this should be a multi-line array is not the concern of this sniff.
$good = array( 1 => 'a', 2 => 'b', 3 => 'c' );
$good = [ 'a' => 1, 'b' => 2, 'c' => 3 ];

$good = array( 1, 2, // OK: that each item should be on its own line or single line array is not the concern of this sniff.
	3, ); // OK: that the brace should be on another line is not the concern of this sniff.

/*
 * Bad.
 */
// Spacing before comma.
$bad = array( 1, 2, 3 ); // Bad x2.
$bad = [ 'a', 'b', 'c' ]; // Bad x2.

// Spacing after comma.
$bad = array( 1, 2, 3 ); // Bad x2.
$bad = [ 'a', 'b', 'c' ]; // Bad x2.

// Comma after last.
$bad = array( 1, 2, 3 );
$bad = [ 'a', 'b', 'c' ];

// Spacing before comma.
$bad = array(
	1 => 'value',
	2 => array( 1 ),
	3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);
$bad = [
	'a' => 'value',          // Comment - the extra spacing is fine, might be for alignment with other comments.
	'b' => array( 1 ),
	'c' => apply_filters( 'filter', $input, $var ),
];

// NO spacing after comma.
$bad = array(
	3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);
$bad = [
	'a' => 'value', // Comment.
];

// NO comma after last.
$bad = array(
	1 => 'value',
	2 => array( 1 ),
	3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);
$bad = [
	'a' => 'value',          // Comment - the extra spacing is fine, might be for alignment with other comments.
	'b' => array( 1 ),
	'c' => apply_filters( 'filter', $input, $var ),
];

$bad = array( 1 => 'a', 2 => 'b', 3 => 'c' );
$bad = [ 'a' => 1, 'b' => 2, 'c' => 3 ];

$bad = array( 1, 2,
	3, );

// Combining a lot of errors in a nested array.
$bad = array(
	1 => 'value',
	2 => [
		'a' => 'value', // Comment - the extra spacing is fine, might be for alignment with other comments.
		'b' => array(
			1,
		),
		'c' => apply_filters( 'filter', $input, $var ),
	],
	3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);

// Alternative array style.
$bad = array(
          1 => 'value', 2 => array( 1 ), 3 => apply_filters( 'filter', $input, $var ), /* Comment. */
);
$bad = [
	  'a' => 'value',          // Comment - the extra spacing is fine, might be for alignment with other comments.
 'b' => array( 1 ), 'c' => apply_filters( 'filter', $input, $var ),
];
$bad = [
	 'a' => 'value',          // Comment - the extra spacing is fine, might be for alignment with other comments.
'b' => array( 1 ), 'c' => apply_filters( 'filter', $input, $var ),
];

$bad = array(
         'first',
         'second',
         //'third',
        );

$bad = array(
 'key3' => function($bar) {
    return $bar;
 },
);

// Issue #998.
$a = array(
	'foo' => bar( 1, 29 ), );

// Issue #986.
get_current_screen()->add_help_tab( array(
		'id'		=> <<<EOD
Here comes some text.
EOD
,
) );

get_current_screen()->add_help_tab( array(
'id'		=> <<<EOD
Here comes some text.
EOD
. '</hr>',
) );

// Test various situations using PHPCS annotations.
// Combining a lot of errors in a nested array.
$bad = array(
	1 => 'value',
	2 => [
		'a' => 'value', // phpcs:disable Standard.Category.Sniff - the extra spacing is fine, might be for alignment with other comments.
		'b' => array(
			1,
		),
		'c' => apply_filters( 'filter', $input, $var ),
	],
	3 => apply_filters( 'filter', $input, $var ), /* phpcs:ignore Standard.Category.Sniff */
);

// Alternative array style.
$bad = array(
          1 => 'value', 2 => array( 1 ), 3 => apply_filters( 'filter', $input, $var ), /* phpcs:ignore Standard.Category.Sniff. */
);
$bad = [
	  'a' => 'value',          // phpcs:disable Standard.Category.Sniff - the extra spacing is fine, might be for alignment with other comments.
 'b' => array( 1 ), 'c' => apply_filters( 'filter', $input, $var ),
];
$bad = [
	 'a' => 'value',          // phpcs:disable Standard.Category.Sniff - the extra spacing is fine, might be for alignment with other comments.
'b' => array( 1 ), 'c' => apply_filters( 'filter', $input, $var ),
];

$bad = array(
         'first', // phpcs:disable Standard.Category.Sniff
         'second',
         // phpcs:enable Standard.Category.Sniff
        );

/*
 * Issue #1692: Test distinguishing between short array and short list.
 */
// Empty list, not allowed since PHP 7.0, but not our concern.
[,,] = $array; // OK.

[$var1, $var2,] = $array; // OK.

// Keyed list.
['enabled' => $enabled, 'compression' => $compression,] = [ 'enabled' => true, 'compression' => 'gzip' ]; // Bad x 1 - only for the short array, not the short list.

// Nested short lists.
[$var1, , [$var2, $var3,], $var4,] = $array; // OK.

// Destructuring - multiline.
[
	'prop1' => $prop1,
	'prop2' => $prop2
] = $some_var;
