Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function process(File $phpcsFile, $coalescePointer) : void
$phpcsFile->fixer->endChangeset();
}

private function getEndOfLineBefore(\PHP_CodeSniffer\Files\File $phpcsFile, int $pointer) : int
private function getEndOfLineBefore(File $phpcsFile, int $pointer) : int
{
$tokens = $phpcsFile->getTokens();

Expand Down Expand Up @@ -103,7 +103,7 @@ private function getEndOfLineBefore(\PHP_CodeSniffer\Files\File $phpcsFile, int
return $endOfLineBefore;
}

private function getIndentation(\PHP_CodeSniffer\Files\File $phpcsFile, int $endOfLinePointer) : string
private function getIndentation(File $phpcsFile, int $endOfLinePointer) : string
{
$pointerAfterWhitespace = TokenHelper::findNextExcluding($phpcsFile, \T_WHITESPACE, $endOfLinePointer + 1);
$actualIndentation = TokenHelper::getContent($phpcsFile, $endOfLinePointer + 1, $pointerAfterWhitespace - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,47 @@ public function process(File $phpcsFile, $openTagPointer) : void
$end = TokenHelper::findLastTokenOnLine($phpcsFile, $reference->startPointer);
$lineLength = \strlen(TokenHelper::getContent($phpcsFile, $start, $end));

if (!$shouldBeUsed
|| ($this->count === null || $this->count > $referenced[$canonicalName])
&& ($this->length === null || $this->length > \strlen($canonicalName))
&& ($this->lineLength === null || $this->lineClassLength === null || $this->lineClassLength > \strlen($canonicalName)
|| $this->lineLength > $lineLength)
) {
continue;
$isAlreadyImported = false;

foreach ($useStatements as $useStatement) {
if ($useStatement->getFullyQualifiedTypeName() === $canonicalName) {
$isAlreadyImported = true;

break;
}
}

$isImported = $isFullyQualified && $isAlreadyImported;

if (!$isImported) {
if (!$shouldBeUsed
|| ($this->count === null || $this->count > $referenced[$canonicalName])
&& ($this->length === null || $this->length > \strlen($canonicalName))
&& ($this->lineLength === null || $this->lineClassLength === null || $this->lineClassLength > \strlen($canonicalName)
|| $this->lineLength > $lineLength)
) {
continue;
}
}

$reason = '';

if ($this->count !== null && $referenced[$canonicalName] >= $this->count) {
if ($isImported) {
$reason = 'because it\'s already imported.';
}

if (!$isImported && $this->count !== null && $referenced[$canonicalName] >= $this->count) {
$reason = 'because it\'s used more than ' . $this->count . ' times.';
}

if ($this->length !== null && $this->length <= \strlen($canonicalName)) {
if (!$isImported && $this->length !== null && $this->length <= \strlen($canonicalName)) {
$reason = $reason === ''
? 'because it\'s length is more than ' . $this->length . ' symbols.'
: 'because it\'s used more than ' . $this->count . ' times and it\'s length is more than '
. $this->length . ' symbols.';
}

if ($this->lineLength !== null && $this->lineClassLength !== null && \strlen($canonicalName) >= $this->lineClassLength
if (!$isImported && $this->lineLength !== null && $this->lineClassLength !== null && \strlen($canonicalName) >= $this->lineClassLength
&& $lineLength >= $this->lineLength) {
$reason = 'because line length is more than ' . $this->lineLength
. ' symbols and class length is more than ' . $this->lineClassLength . ' symbols.';
Expand Down Expand Up @@ -370,7 +388,7 @@ static function (bool $carry, string $use) use ($canonicalName) : bool {
$phpcsFile->fixer->endChangeset();
}

private function getUseStatementPlacePointer(\PHP_CodeSniffer\Files\File $phpcsFile, int $openTagPointer, array $useStatements) : int
private function getUseStatementPlacePointer(File $phpcsFile, int $openTagPointer, array $useStatements) : int
{
if (\count($useStatements) !== 0) {
$lastUseStatement = \array_values($useStatements)[\count($useStatements) - 1];
Expand Down Expand Up @@ -418,7 +436,7 @@ private function getUseStatementPlacePointer(\PHP_CodeSniffer\Files\File $phpcsF
return $useStatementPlacePointer;
}

private function getReferences(\PHP_CodeSniffer\Files\File $phpcsFile, int $openTagPointer) : array
private function getReferences(File $phpcsFile, int $openTagPointer) : array
{
$references = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private function checkTypeHint(File $phpcsFile, TypeHint $typeHint) : void

private function getTypeHintContentWithoutNull(
File $phpcsFile,
\SlevomatCodingStandard\Helpers\TypeHint $typeHint,
TypeHint $typeHint,
) : string
{
$tokens = $phpcsFile->getTokens();
Expand Down Expand Up @@ -258,7 +258,7 @@ private function getTypeHintContentWithoutNull(

private function fixTypeHint(
File $phpcsFile,
\SlevomatCodingStandard\Helpers\TypeHint $typeHint,
TypeHint $typeHint,
string $fixedTypeHint,
) : void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) : ?int
}

//@phpcs:ignore Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
protected function processVariable(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr) : void
protected function processVariable(File $phpcsFile, $stackPtr) : void
{
}

//@phpcs:ignore Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
protected function processVariableInString(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr) : void
protected function processVariableInString(File $phpcsFile, $stackPtr) : void
{
}
}