Skip to content

array.syntaxfixable

Ensure that array syntax is consistent

Options

type

Set the type of array syntax to be used. Defaults to "long".

Type: string

Default: long

Possible values: long, short

Examples

  • Examples of correct code for this rule using default options

Arrays are using long syntax

php
<?php
$var = array(1,2,3);
$var = array(
    1,
    2,
    3
);
$var = array(
    1,
    2,
    /* three */ 3,
);
$var = array(
1,
        2,
    /* three */ 3,
 );

$var = array(
    1 => 'one',
    2 => 'two',
    3 => 'three'
);

$var = array(
    1 => 'one',
    2 => 'two',
    /* three */ 3 => 'three',
);

$var = array(
1 => 'one',
        2 => 'two',
    /* three */ 3 => 'three',
    );

$test = array(
    array(
        'foo' => true,
    ),
    'foo' => true,
    'bar' => false,
);

$var = array(
    'one' => function() {
        $foo = array(1,2,3);
        $bar = array(
            1,
            2,
            3);
    },
    'two' => 2,
);

return array(
    array(
        'foo' => true,
    )
);


$var = array(
1 => 'one',
        2 => 'two',
    /* three */ 3 => 'three',
    );

$var = array();
  • Examples of incorrect code for this rule using default options

Arrays are using short syntax

php
<?php
$var = [1,2,3];
$var = [
    1,
    2,
    3
];

$var = [
    1,
    2,
    /* three */ 3,
];
$var = [
1,
        2,
    /* three */ 3,
 ];

$var = [
    1 => 'one',
    2 => 'two',
    3 => 'three'
];

$var = [
    1 => 'one',
    2 => 'two',
    /* three */ 3 => 'three',
];

type

  • Examples of correct code for this rule using type option

Arrays are using short syntax

php
<?php
/* taqwim "taqwim/array.syntax" : {type: "short"} */

$var = [1,2,3];
$var = [
    1,
    2,
    3
];
$var = [
    1,
    2,
    /* three */ 3,
];
$var = [
1,
        2,
    /* three */ 3,
 ];

$var = [
    1 => 'one',
    2 => 'two',
    3 => 'three'
];

$var = [
    1 => 'one',
    2 => 'two',
    /* three */ 3 => 'three',
];

$var = [
1 => 'one',
        2 => 'two',
    /* three */ 3 => 'three',
    ];

$test = [
    [
        'foo' => true,
    ],
    'foo' => true,
    'bar' => false,
];

$var = [
    'one' => function() {
        $foo = [1,2,3];
        $bar = [
            1,
            2,
            3];
    },
    'two' => 2,
];

return [
    [
        'foo' => true,
    ]
];


$var = [
1 => 'one',
        2 => 'two',
    /* three */ 3 => 'three',
    ];

Released under the MIT License.