Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Aug 9, 2023
1 parent ee88af9 commit cf65208
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class ForbidMethodDeclarationSniff implements Sniff
public const FORBIDDEN_METHOD_DECLARATION = 'ForbiddenMethodDeclaration';

/**
* A list of methods which should not be declared
* in specific.
* A list of forbidden to declare methods.
* @var array<string, string>
*/
public $forbiddenMethods = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@

final class CamelCaseRouteNameSniff implements Sniff
{
private const CAMEL_CASE_PATTERN = '/^[^-_\s]++$/';

public const CODE_NOT_CAMEL_CASE_ROUTE_NAME = 'NotCamelCaseRouteName';

private const PATTERN_CAMEL_CASE = '/^[^-_\s]++$/';

/** @inheritDoc */
public function register(): array
{
return [\T_STRING];
}

/** @inheritDoc */
public function process(File $phpcsFile, $stackPtr): void
public function process(File $phpcsFile, $stringPointer): void
{
$tokens = $phpcsFile->getTokens();
$currentToken = $tokens[$stackPtr];
$currentToken = $tokens[$stringPointer];

if ($currentToken['content'] !== 'name') {
return;
}

$this->processRouteName($phpcsFile, $stackPtr, $tokens);
$this->processRouteName($phpcsFile, $stringPointer, $tokens);
}

/**
* Finds the route name and tests it against the camel case pattern.
* If an issue is found, it adds an error.
* @param array<string, int, array<string>> $tokens
**/
public function processRouteName(File $phpcsFile, int $stackPtr, array $tokens): void
public function processRouteName(File $phpcsFile, int $stackPointer, array $tokens): void
{
$routeNameLocation = $phpcsFile->findNext(\T_CONSTANT_ENCAPSED_STRING, $stackPtr);
$routeNameLocation = $phpcsFile->findNext(\T_CONSTANT_ENCAPSED_STRING, $stackPointer);
$routeName = $tokens[$routeNameLocation]['content'];

if (!$this->isCamelCase($routeName)) {
Expand All @@ -58,7 +58,7 @@ private function isCamelCase(string $routeName): bool
$parts = explode('.', $routeName);

foreach ($parts as $part) {
if (preg_match(self::CAMEL_CASE_PATTERN, $part) !== 1) {
if (preg_match(self::PATTERN_CAMEL_CASE, $part) !== 1) {
return false;
}
}
Expand Down

0 comments on commit cf65208

Please sign in to comment.