Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
[cs] apply experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 30, 2018
1 parent 84b7698 commit 595f81b
Show file tree
Hide file tree
Showing 36 changed files with 447 additions and 212 deletions.
10 changes: 5 additions & 5 deletions packages/BetterPhpDocParser/src/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
final class PhpDocInfo
{
/**
* @var PhpDocNode
* @var string
*/
private $phpDocNode;
private $originalContent;

/**
* @var mixed[]
Expand All @@ -30,12 +30,12 @@ final class PhpDocInfo
/**
* @var PhpDocNode
*/
private $originalPhpDocNode;
private $phpDocNode;

/**
* @var string
* @var PhpDocNode
*/
private $originalContent;
private $originalPhpDocNode;

/**
* @var PhpDocModifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

final class PositionAwarePhpDocParser extends PhpDocParser
{
/**
* @var bool
*/
private $isComment = false;

/**
* @var PrivatesCaller
*/
Expand All @@ -32,11 +37,6 @@ final class PositionAwarePhpDocParser extends PhpDocParser
*/
private $privatesAccessor;

/**
* @var bool
*/
private $isComment = false;

public function __construct(
TypeParser $typeParser,
ConstExprParser $constExprParser,
Expand Down
22 changes: 11 additions & 11 deletions packages/BetterPhpDocParser/src/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,29 @@
final class PhpDocInfoPrinter
{
/**
* @var NodeWithPositionsObjectStorage|PhpDocNodeInfo[]
* @var int
*/
private $nodeWithPositionsObjectStorage;
private $tokenCount;

/**
* @var int
*/
private $currentTokenPosition;

/**
* @var mixed[]
*/
private $tokens = [];

/**
* @var int
* @var PhpDocNodeInfo[]
*/
private $tokenCount;
private $removedNodePositions = [];

/**
* @var int
* @var NodeWithPositionsObjectStorage|PhpDocNodeInfo[]
*/
private $currentTokenPosition;
private $nodeWithPositionsObjectStorage;

/**
* @var PhpDocNode
Expand All @@ -50,11 +55,6 @@ final class PhpDocInfoPrinter
*/
private $originalPhpDocNode;

/**
* @var PhpDocNodeInfo[]
*/
private $removedNodePositions = [];

/**
* @var OriginalSpacingRestorer
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/ChangelogLinker/src/ChangelogDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class ChangelogDumper
private $previousTag;

/**
* @var GitCommitDateTagResolver
* @var string
*/
private $gitCommitDateTagResolver;
private $content;

/**
* @var string
* @var GitCommitDateTagResolver
*/
private $content;
private $gitCommitDateTagResolver;

/**
* @var ChangelogFormatter
Expand Down
10 changes: 5 additions & 5 deletions packages/ChangelogLinker/src/Github/GithubApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ final class GithubApi
*/
private const URL_PULL_REQUEST_BY_ID = 'https://api.github.com/repos/%s/pulls/%d';

/**
* @var Client
*/
private $client;

/**
* @var string
*/
Expand All @@ -40,6 +35,11 @@ final class GithubApi
*/
private $options = [];

/**
* @var Client
*/
private $client;

/**
* @var ResponseFormatter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
final class LinksToReferencesWorker implements WorkerInterface
{
/**
* @var LinkAppender
* @var string
*/
private $linkAppender;
private $repositoryUrl;

/**
* @var string
* @var LinkAppender
*/
private $repositoryUrl;
private $linkAppender;

public function __construct(string $repositoryUrl, LinkAppender $linkAppender)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symplify\TokenRunner\Analyzer\FixerAnalyzer\DocBlockFinder;
use Symplify\TokenRunner\Wrapper\FixerWrapper\ClassWrapperFactory;
use Symplify\TokenRunner\Wrapper\FixerWrapper\DocBlockWrapperFactory;
use function Safe\usort;

/**
* Inspiration @see \PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
Expand Down Expand Up @@ -121,11 +122,6 @@ public function isCandidate(Tokens $tokens): bool
return $tokens->isAllTokenKindsFound([T_CLASS, T_VARIABLE]);
}

public function getName(): string
{
return self::class;
}

/**
* Needs to run before @see \PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
*/
Expand All @@ -134,6 +130,11 @@ public function getPriority(): int
return 70;
}

public function getName(): string
{
return self::class;
}

protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
for ($i = 1; $i < $tokens->count(); ++$i) {
Expand All @@ -146,15 +147,11 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
$propertyElements = $classWrapper->getPropertyElements();

foreach ($propertyElements as $key => $propertyElement) {
$docBlockPosition = $this->docBlockFinder->findPreviousPosition($tokens, $propertyElement['start'] + 1);

$docBlockWrapper = $this->docBlockWrapperFactory->create(
$tokens,
$docBlockPosition,
$tokens[$docBlockPosition]->getContent()
);
$propertyElements[$key]['rating'] = $this->resolveRatingFromDocType($tokens, $propertyElement);
}

$propertyElements[$key]['types'] = $docBlockWrapper->getVarTypes();
if ($this->shouldSkip($propertyElements)) {
continue;
}

$sortedPropertyElements = $this->sortPropertyWrappers($propertyElements);
Expand Down Expand Up @@ -184,7 +181,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
private function sortPropertyWrappers(array $propertyElements): array
{
usort($propertyElements, function (array $firstPropertyElement, array $secondPropertyElement) {
return $this->getTypeRating($firstPropertyElement['types']) <=> $this->getTypeRating($secondPropertyElement['types']);
return $firstPropertyElement['rating'] <=> $secondPropertyElement['rating'];
});

return $propertyElements;
Expand Down Expand Up @@ -220,4 +217,37 @@ private function getTypeRating(array $types): int

return $rating;
}

/**
* @param mixed[] $propertyElement
*/
private function resolveRatingFromDocType(Tokens $tokens, array $propertyElement): int
{
$docBlockPosition = $this->docBlockFinder->findPreviousPosition($tokens, $propertyElement['start'] + 1);

$docBlockWrapper = $this->docBlockWrapperFactory->create(
$tokens,
$docBlockPosition,
$tokens[$docBlockPosition]->getContent()
);

return $this->getTypeRating($docBlockWrapper->getVarTypes());
}

/**
* @param mixed[] $propertyElements
*/
private function shouldSkip(array $propertyElements): bool
{
$lastRating = null;
foreach ($propertyElements as $propertyElement) {
if ($lastRating && $lastRating > $propertyElement['rating']) {
return false;
}

$lastRating = $propertyElement['rating'];
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ final class UnusedPublicMethodSniff implements Sniff, DualRunInterface
private $runNumber = 1;

/**
* @var string[]
* @var int
*/
private $publicMethodNames = [];
private $position;

/**
* @var string[]
*/
private $calledMethodNames = [];

/**
* @var File
*/
private $file;
private $publicMethodNames = [];

/**
* @var int
* @var string[]
*/
private $position;
private $calledMethodNames = [];

/**
* @var mixed[]
Expand All @@ -61,14 +56,19 @@ final class UnusedPublicMethodSniff implements Sniff, DualRunInterface
private $methodsToIgnore = ['__*', 'test*', 'provide*', 'offset*'];

/**
* @var ClassWrapperFactory
* @var string[]
*/
private $classWrapperFactory;
private $unusedMethodNames = [];

/**
* @var string[]
* @var File
*/
private $unusedMethodNames = [];
private $file;

/**
* @var ClassWrapperFactory
*/
private $classWrapperFactory;

public function __construct(ClassWrapperFactory $classWrapperFactory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ final class NoClassInstantiationSniff implements Sniff
*/
private const ERROR_MESSAGE = 'Use service and constructor injection rather than instantiation with "new %s".';

/**
* @var bool
*/
public $includeEntities = false;

/**
* @var string[]
*/
Expand Down Expand Up @@ -92,11 +97,6 @@ final class NoClassInstantiationSniff implements Sniff
'*CompilerPass',
];

/**
* @var bool
*/
public $includeEntities = false;

/**
* @var File
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class AbstractClassNameSniff implements Sniff
private const ERROR_MESSAGE = 'Abstract class should have prefix "Abstract".';

/**
* @var File
* @var int
*/
private $file;
private $position;

/**
* @var int
* @var File
*/
private $position;
private $file;

/**
* @return int[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class InterfaceNameSniff implements Sniff
private const ERROR_MESSAGE = 'Interface should have suffix "Interface".';

/**
* @var File
* @var int
*/
private $file;
private $position;

/**
* @var int
* @var File
*/
private $position;
private $file;

/**
* @return int[]
Expand Down
8 changes: 4 additions & 4 deletions packages/CodingStandard/src/Sniffs/Naming/TraitNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class TraitNameSniff implements Sniff
private const ERROR_MESSAGE = 'Trait should have suffix "Trait".';

/**
* @var File
* @var int
*/
private $file;
private $position;

/**
* @var int
* @var File
*/
private $position;
private $file;

/**
* @return int[]
Expand Down

0 comments on commit 595f81b

Please sign in to comment.