Importing to shorten class names

Continuing the discussion from Using the ::class constant instead of string literals:

@bwaidelich brought this up right after I pushed those changes:

$this->assertInstanceOf(\TYPO3\Eel\Tests\Functional\FlowQuery\Fixtures\ExampleFinalOperationWithHigherPriority::class, ... vs
$this->assertInstanceOf(ExampleFinalOperationWithHigherPriority::class, ...

I think it increases readability dramatically… and at no real expense (it’s just syntactic sugar). If there are cases where it’s ambiguous (e.g. Context) I’d suggest to rename the class (if viable) or at least alias the import (Context as SecurityContext)

Yes, I’d love to import, but to keep the change “small” and easier to review I did not import in the change introducing the ::CLASS constant. And there is already a bunch of changes by Rens shortening names; this could probably refreshed.

We just need to find a common guideline for when to import. For a single occurrence? Three? Always, because IDEs can do that?

Fair enough, that makes sense of course!

Personally I enabled Auto Import in PhpStorm and think the code got so much more readable and easier to work with since.

1 Like