Skip to content

Commit

Permalink
Remove typehints to support PHP 5 (#47)
Browse files Browse the repository at this point in the history
* Remove scalar typehints

It turns out that scalar typehints were not added until PHP 7.

* Remove return types

Return type declarations were added in PHP 7

* Update circleci container to supported version
  • Loading branch information
sirbrillig authored Sep 8, 2018
1 parent 71cbcdb commit d7652af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/php:7.1.19-fpm-node-browsers
- image: circleci/php:7.0-apache-stretch-node-browsers
steps:
- checkout
- run: composer install
Expand Down
16 changes: 8 additions & 8 deletions VariableAnalysis/Lib/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHP_CodeSniffer\Files\File;

class Helpers {
public static function findContainingOpeningBracket(File $phpcsFile, int $stackPtr) {
public static function findContainingOpeningBracket(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['nested_parenthesis'])) {
$openPtrs = array_keys($tokens[$stackPtr]['nested_parenthesis']);
Expand All @@ -14,7 +14,7 @@ public static function findContainingOpeningBracket(File $phpcsFile, int $stackP
return false;
}

public static function findParenthesisOwner(File $phpcsFile, int $stackPtr) {
public static function findParenthesisOwner(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
return $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
}
Expand All @@ -40,7 +40,7 @@ public static function areAnyConditionsAClass(array $conditions) {
return false;
}

public static function findPreviousFunctionPtr(File $phpcsFile, int $openPtr) {
public static function findPreviousFunctionPtr(File $phpcsFile, $openPtr) {
// Function names are T_STRING, and return-by-reference is T_BITWISE_AND,
// so we look backwards from the opening bracket for the first thing that
// isn't a function name, reference sigil or whitespace and check if it's a
Expand All @@ -49,7 +49,7 @@ public static function findPreviousFunctionPtr(File $phpcsFile, int $openPtr) {
return $phpcsFile->findPrevious($functionPtrTypes, $openPtr - 1, null, true, null, true);
}

public static function findFunctionCall(File $phpcsFile, int $stackPtr) {
public static function findFunctionCall(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();

$openPtr = Helpers::findContainingOpeningBracket($phpcsFile, $stackPtr);
Expand Down Expand Up @@ -103,7 +103,7 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr) {
return $argPtrs;
}

public static function findWhereAssignExecuted(File $phpcsFile, int $stackPtr) {
public static function findWhereAssignExecuted(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();

// Write should be recorded at the next statement to ensure we treat the
Expand Down Expand Up @@ -132,7 +132,7 @@ public static function findWhereAssignExecuted(File $phpcsFile, int $stackPtr) {
return $assignEndTokens[0];
}

public static function isNextThingAnAssign(File $phpcsFile, int $stackPtr) {
public static function isNextThingAnAssign(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();

// Is the next non-whitespace an assignment?
Expand All @@ -149,7 +149,7 @@ public static function normalizeVarName($varName) {
return preg_replace('/[{}$]/', '', $varName);
}

public static function findFunctionPrototype(File $phpcsFile, int $stackPtr) {
public static function findFunctionPrototype(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];

Expand All @@ -164,7 +164,7 @@ public static function findFunctionPrototype(File $phpcsFile, int $stackPtr) {
return false;
}

public static function findVariableScope(File $phpcsFile, int $stackPtr) {
public static function findVariableScope(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function register() {
];
}

private function getPassByReferenceFunction(string $functionName) {
private function getPassByReferenceFunction($functionName) {
$passByRefFunctions = Constants::getPassByReferenceFunctions();
// Magic to modfy $passByRefFunctions with any site-specific settings.
if (!empty($this->sitePassByRefFunctions)) {
Expand Down
12 changes: 6 additions & 6 deletions VariableAnalysis/Tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHP_CodeSniffer\Config;

class BaseTestCase extends TestCase {
public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): LocalFile {
public function prepareLocalFileForSniffs($sniffFiles, $fixtureFile) {
$config = new Config();
$ruleset = new Ruleset($config);
if (! is_array($sniffFiles)) {
Expand All @@ -21,25 +21,25 @@ public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): Loc
return new LocalFile($fixtureFile, $ruleset, $config);
}

public function getLineNumbersFromMessages(array $messages): array {
public function getLineNumbersFromMessages(array $messages) {
$lines = array_keys($messages);
sort($lines);
return $lines;
}

public function getWarningLineNumbersFromFile(LocalFile $phpcsFile): array {
public function getWarningLineNumbersFromFile(LocalFile $phpcsFile) {
return $this->getLineNumbersFromMessages($phpcsFile->getWarnings());
}

public function getErrorLineNumbersFromFile(LocalFile $phpcsFile): array {
public function getErrorLineNumbersFromFile(LocalFile $phpcsFile) {
return $this->getLineNumbersFromMessages($phpcsFile->getErrors());
}

public function getSniffFiles(): array {
public function getSniffFiles() {
return [__DIR__ . '/../../VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php'];
}

public function getFixture(string $fixtureFilename): string {
public function getFixture($fixtureFilename) {
return __DIR__ . '/CodeAnalysis/fixtures/' . $fixtureFilename;
}
}

0 comments on commit d7652af

Please sign in to comment.