Skip to content

Convert all "long" array syntax to "short" syntax #7191

Description

@swampopus

The overall idea:

In core, we stop using array(1, 2, 3) in favor of [1, 2, 3].

Example:

$x = [
  'key' => 'val',
];
function ($x = []) {}
return l('foo', 'bar', ['attributes' => ['class' => 'fun']]);

Previous work

@quicksketch has already created a working proof of concept for a rapid conversion to short syntax: backdrop/backdrop#4936

In case the blog post he mentioned disappears one day, here is what it said to do:

  1. Require code sniffer in your project (you are using composer, right?)

composer require --dev squizlabs/php_codesniffer

  1. Run CBF using the DisallowLongArraySyntax sniff

vendor/bin/phpcbf . --standard=Generic --sniffs=Generic.Arrays.DisallowLongArraySyntax

That will apply to everything in the current directory, so simply change the . to whichever specific files/folders you want to affect.

-- from https://philipjohn.blog/2023/02/10/convert-php-arrays-to-short-array-syntax-in-seconds/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions