Proposed solution

  1. use statements MUST be located after the initial @file phpDoc block.
  2. use statements SHOULD be "ordered by":
    1. (FullyQualifiedClassName == framework/vendor namespace)
    2. FullyQualifiedClassName

Example


/**
 * @file
 * Contains Drupal\node\Node.
 */

namespace Drupal\node;

use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Entity\EntityFieldQuery;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\file\File;
use Drupal\user\User;

Comments

Lars Toomre’s picture

Wonderful... What is the Drupal policy? Alphabetical order?

Crell’s picture

There is currently no Drupal policy. I couldn't find the previous issue where this was discussed and ended up with a general "meh".

Most of my code has been putting all Symfony classes together in one block, then all Drupal stuff together in a separate block, ordered roughly by component/subsystem. I don't know that a hard alphabetical order is necessary; it's not like it actually means anything to the compiler either way, and we're not going to be doing deployment based on the diffs (like for CMI objects).

Anonymous’s picture

This was also discussed here: #1624564: Coding standards for "use" statements

Personally, I like the suggestion as the code looks cleaner (to me), but the issue that was raised there was more that it's another coding standards issue to enforce, and that some people may be resistant.

If there are starting to be large numbers of these, though, I would prefer a standard.

sun’s picture

Status: Active » Closed (duplicate)

Oh. Sorry, I was not aware that we had an issue already. Marking as duplicate. Moved everything over.