Skip to content

Commit

Permalink
refactor: apply new coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Aug 2, 2024
1 parent 3c0d30b commit 8597cbf
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"friendsofphp/php-cs-fixer": ">=3.59.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.60",
"phpspec/phpspec": "^7.0",
"sebastian/diff": "^4.0",
"twig/twig": "^3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function isCandidate(Tokens $tokens): bool

public function getName(): string
{
return sprintf('PedroTroller/%s', parent::getName());
return \sprintf('PedroTroller/%s', parent::getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ private function getMethodsNames(array $elements): array
$methods = [];

foreach ($this->getPropertiesNames($elements) as $name) {
$methods[] = sprintf('get%s', ucfirst($name));
$methods[] = sprintf('is%s', ucfirst($name));
$methods[] = sprintf('has%s', ucfirst($name));
$methods[] = \sprintf('get%s', ucfirst($name));
$methods[] = \sprintf('is%s', ucfirst($name));
$methods[] = \sprintf('has%s', ucfirst($name));
$methods[] = lcfirst($name);
$methods[] = sprintf('set%s', ucfirst($name));
$methods[] = \sprintf('set%s', ucfirst($name));
}

return $methods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ private function cleanupMessage(Token $token): Token
return $token;
}

return new Token([T_CONSTANT_ENCAPSED_STRING, sprintf('%s%s.%s', $quotes, implode('', $chars), $quotes)]);
return new Token([T_CONSTANT_ENCAPSED_STRING, \sprintf('%s%s.%s', $quotes, implode('', $chars), $quotes)]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void

if (\in_array($token->getContent(), $this->configuration['functions'], true)) {
$end = $this->analyze($tokens)->getEndOfTheLine($index);
$tokens[$end] = new Token([T_WHITESPACE, sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]);
$tokens[$end] = new Token([T_WHITESPACE, \sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ private function formatComments(array $comments, string $indentation): string
$comments = implode("\n", $comments);
$comments = trim($comments, " \n");

return sprintf("/**\n%s %s\n%s */", $indentation, $comments, $indentation);
return \sprintf("/**\n%s %s\n%s */", $indentation, $comments, $indentation);
}
}
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurableFixerInterface
{
use ConfigurableFixerTrait;

/**
* @var string[]
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/PhpspecFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private function filterElementsByMethodName(string $regex, array $elements): arr
$filter = [];

foreach ($this->filterElementsByType('method', $elements) as $index => $method) {
if (0 !== preg_match(sprintf('/^%s$/', $regex), $method['methodName'])) {
if (0 !== preg_match(\sprintf('/^%s$/', $regex), $method['methodName'])) {
$filter[$index] = $method;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/PedroTroller/CS/Fixer/TokensAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function getNextSemiColon($index)
public function getReturnedType($index)
{
if (false === $this->tokens[$index]->isGivenKind(T_FUNCTION)) {
throw new Exception(sprintf('Expected token: T_FUNCTION Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
throw new Exception(\sprintf('Expected token: T_FUNCTION Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
}

$methodName = $this->tokens->getNextMeaningfulToken($index);
Expand Down Expand Up @@ -317,7 +317,7 @@ public function endOfTheStatement(int $index): ?int
public function getClosingParenthesis($index)
{
if ('(' !== $this->tokens[$index]->getContent()) {
throw new Exception(sprintf('Expected token: (. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
throw new Exception(\sprintf('Expected token: (. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
}

for ($i = $index + 1; $i < $this->tokens->count(); ++$i) {
Expand Down Expand Up @@ -345,7 +345,7 @@ public function getClosingParenthesis($index)
public function getClosingBracket($index)
{
if ('[' !== $this->tokens[$index]->getContent()) {
throw new Exception(sprintf('Expected token: [. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
throw new Exception(\sprintf('Expected token: [. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
}

for ($i = $index + 1; $i < $this->tokens->count(); ++$i) {
Expand Down Expand Up @@ -373,7 +373,7 @@ public function getClosingBracket($index)
public function getClosingCurlyBracket($index)
{
if ('{' !== $this->tokens[$index]->getContent()) {
throw new Exception(sprintf('Expected token: {. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
throw new Exception(\sprintf('Expected token: {. Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
}

for ($i = $index + 1; $i < $this->tokens->count(); ++$i) {
Expand Down Expand Up @@ -401,7 +401,7 @@ public function getClosingCurlyBracket($index)
public function getClosingAttribute($index)
{
if (false === $this->tokens[$index]->isGivenKind(T_ATTRIBUTE)) {
throw new Exception(sprintf('Expected token: T_ATTRIBUTE Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
throw new Exception(\sprintf('Expected token: T_ATTRIBUTE Token %d id contains %s.', $index, $this->tokens[$index]->getContent()));
}

for ($i = $index + 1; $i < $this->tokens->count(); ++$i) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Orchestra.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function assert(FixerInterface $fixer)
*/
public function before(FixerInterface $other)
{
echo sprintf("\nRun %s before %s\n", $this->fixer->getName(), $other->getName());
echo \sprintf("\nRun %s before %s\n", $this->fixer->getName(), $other->getName());

Assert::greaterThan(
$this->fixer->getPriority(),
Expand All @@ -80,7 +80,7 @@ public function before(FixerInterface $other)
*/
public function after(FixerInterface $other)
{
echo sprintf("\nRun %s after %s\n", $this->fixer->getName(), $other->getName());
echo \sprintf("\nRun %s after %s\n", $this->fixer->getName(), $other->getName());

Assert::lessThan(
$this->fixer->getPriority(),
Expand Down
10 changes: 5 additions & 5 deletions tests/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function run(): void

set_error_handler(
static function ($type, $message, $file, $line) use (&$deprecations): void {
$deprecations[$message][] = sprintf('%s at line %d', $file, $line);
$deprecations[$message][] = \sprintf('%s at line %d', $file, $line);
$deprecations[$message] = array_unique($deprecations[$message]);

sort($deprecations[$message]);
Expand All @@ -35,12 +35,12 @@ static function ($type, $message, $file, $line) use (&$deprecations): void {
if (false === empty($deprecations)) {
ksort($deprecations);

$message = sprintf(
$message = \sprintf(
"Deprecations : \n\n%s",
implode(
"\n\n",
array_map(
static fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)),
static fn ($message, array $files) => \sprintf("%s\n%s", $message, implode("\n", $files)),
array_keys($deprecations),
$deprecations
)
Expand All @@ -53,7 +53,7 @@ static function ($type, $message, $file, $line) use (&$deprecations): void {

private static function runUseCases(): void
{
$directory = sprintf('%s/UseCase', __DIR__);
$directory = \sprintf('%s/UseCase', __DIR__);

$finder = new Finder();
$finder
Expand Down Expand Up @@ -100,7 +100,7 @@ private static function runUseCases(): void

private static function runAnalyzerIntegrations(): void
{
$directory = sprintf('%s/TokensAnalyzerIntegration', __DIR__);
$directory = \sprintf('%s/TokensAnalyzerIntegration', __DIR__);

$finder = new Finder();
$finder
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function tokensContaining(Tokens $tokens, $content)
}

if (empty($indexes)) {
throw new Exception(sprintf('There is no token containing %s.', $content));
throw new Exception(\sprintf('There is no token containing %s.', $content));
}

return $indexes;
Expand Down
4 changes: 2 additions & 2 deletions tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function getFixers(): iterable

public function getRawScript(): string
{
return file_get_contents(sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__));
return file_get_contents(\sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__));
}

public function getExpectation(): string
{
return file_get_contents(sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__));
return file_get_contents(\sprintf('%s/Case1/CamelizeNamingStrategy.php.text', __DIR__));
}

public function getMinSupportedPhpVersion(): int
Expand Down
4 changes: 2 additions & 2 deletions tests/UseCase/Phpspec/Regression/Case1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function getFixers(): iterable

public function getRawScript(): string
{
return file_get_contents(sprintf('%s/Case1/file.php.txt', __DIR__));
return file_get_contents(\sprintf('%s/Case1/file.php.txt', __DIR__));
}

public function getExpectation(): string
{
return file_get_contents(sprintf('%s/Case1/file.php.txt', __DIR__));
return file_get_contents(\sprintf('%s/Case1/file.php.txt', __DIR__));
}

public function getMinSupportedPhpVersion(): int
Expand Down
4 changes: 2 additions & 2 deletions tests/UseCase/Phpspec/Regression/Case2.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public function getFixers(): iterable

public function getRawScript(): string
{
return file_get_contents(sprintf('%s/Case2/file.php.txt', __DIR__));
return file_get_contents(\sprintf('%s/Case2/file.php.txt', __DIR__));
}

public function getExpectation(): string
{
return file_get_contents(sprintf('%s/Case2/file.php.txt', __DIR__));
return file_get_contents(\sprintf('%s/Case2/file.php.txt', __DIR__));
}

public function getMinSupportedPhpVersion(): int
Expand Down

0 comments on commit 8597cbf

Please sign in to comment.