OrderedImportsFixer
extends AbstractFixer
in package
implements
ConfigurableFixerInterface, WhitespacesAwareFixerInterface
uses
ConfigurableFixerTrait
Tags
Table of Contents
Interfaces
Constants
- SUPPORTED_SORT_ALGORITHMS = [self::SORT_ALPHA, self::SORT_LENGTH, self::SORT_NONE]
- Array of supported sort algorithms in configuration.
- SUPPORTED_SORT_TYPES = [self::IMPORT_TYPE_CLASS, self::IMPORT_TYPE_CONST, self::IMPORT_TYPE_FUNCTION]
- Array of supported sort types in configuration.
Methods
- getDefinition() : FixerDefinitionInterface
- Returns the definition of the fixer.
- getPriority() : int
- Returns the priority of the fixer.
- isCandidate() : bool
- Check if the fixer is a candidate for given Tokens collection.
- applyFix() : void
- createConfigurationDefinition() : FixerConfigurationResolverInterface
- getNewOrder() : array<int, _UseImportInfo>
- prepareNamespace() : string
- setNewOrder() : void
- sortAlphabetically() : int
- This method is used for sorting the uses in a namespace.
- sortByAlgorithm() : array<int, _UseImportInfo>
- sortByLength() : int
- This method is used for sorting the uses statements in a namespace by length.
Constants
SUPPORTED_SORT_ALGORITHMS
Array of supported sort algorithms in configuration.
private
array<int, string>
SUPPORTED_SORT_ALGORITHMS
= [self::SORT_ALPHA, self::SORT_LENGTH, self::SORT_NONE]
SUPPORTED_SORT_TYPES
Array of supported sort types in configuration.
private
array<int, string>
SUPPORTED_SORT_TYPES
= [self::IMPORT_TYPE_CLASS, self::IMPORT_TYPE_CONST, self::IMPORT_TYPE_FUNCTION]
Methods
getDefinition()
Returns the definition of the fixer.
public
getDefinition() : FixerDefinitionInterface
Return values
FixerDefinitionInterfacegetPriority()
Returns the priority of the fixer.
public
getPriority() : int
Must run before BlankLineBetweenImportGroupsFixer. Must run after FullyQualifiedStrictTypesFixer, GlobalNamespaceImportFixer, NoLeadingImportSlashFixer.
Return values
intisCandidate()
Check if the fixer is a candidate for given Tokens collection.
public
isCandidate(Tokens $tokens) : bool
Fixer is a candidate when the collection contains tokens that may be fixed during fixer work. This could be considered as some kind of bloom filter. When this method returns true then to the Tokens collection may or may not need a fixing, but when this method returns false then the Tokens collection need no fixing for sure.
Parameters
- $tokens : Tokens
Return values
boolapplyFix()
protected
applyFix(SplFileInfo $file, Tokens $tokens) : void
Parameters
- $file : SplFileInfo
- $tokens : Tokens
createConfigurationDefinition()
protected
createConfigurationDefinition() : FixerConfigurationResolverInterface
Return values
FixerConfigurationResolverInterfacegetNewOrder()
private
getNewOrder(array<int, int> $uses, Tokens $tokens) : array<int, _UseImportInfo>
Parameters
- $uses : array<int, int>
- $tokens : Tokens
Return values
array<int, _UseImportInfo>prepareNamespace()
private
prepareNamespace(string $namespace) : string
Parameters
- $namespace : string
Return values
stringsetNewOrder()
private
setNewOrder(Tokens $tokens, array<int, _UseImportInfo> $usesOrder) : void
Parameters
- $tokens : Tokens
- $usesOrder : array<int, _UseImportInfo>
sortAlphabetically()
This method is used for sorting the uses in a namespace.
private
sortAlphabetically(_UseImportInfo $first, _UseImportInfo $second) : int
Parameters
- $first : _UseImportInfo
- $second : _UseImportInfo
Return values
intsortByAlgorithm()
private
sortByAlgorithm(array<int, _UseImportInfo> $indices) : array<int, _UseImportInfo>
Parameters
- $indices : array<int, _UseImportInfo>
Return values
array<int, _UseImportInfo>sortByLength()
This method is used for sorting the uses statements in a namespace by length.
private
sortByLength(_UseImportInfo $first, _UseImportInfo $second) : int
Parameters
- $first : _UseImportInfo
- $second : _UseImportInfo