Skip to content

💄 Use strict type #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2019
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
154 changes: 78 additions & 76 deletions SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Classes;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Classes;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Commenting/ClassCommentSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\ClassCommentSniff as PEARClassCommentSniff;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand Down
24 changes: 13 additions & 11 deletions SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -28,7 +30,7 @@ public function process(File $phpcsFile, $stackPtr): void

if (!isset($tokens[$stackPtr]['comment_closer'])
|| ('' === $tokens[$tokens[$stackPtr]['comment_closer']]['content']
&& ($phpcsFile->numTokens - 1) === $tokens[$stackPtr]['comment_closer'])
&& $phpcsFile->numTokens - 1 === $tokens[$stackPtr]['comment_closer'])
) {
// Don't process an unfinished comment during live coding.
return;
Expand All @@ -41,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr): void
T_DOC_COMMENT_STAR,
];

$short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true);
$short = $phpcsFile->findNext($empty, $stackPtr + 1, $commentEnd, true);
if (false === $short) {
// No content at all.
$next = $phpcsFile->findNext(T_WHITESPACE, $commentEnd + 1, null, true);
Expand Down Expand Up @@ -87,7 +89,7 @@ public function process(File $phpcsFile, $stackPtr): void

if ($fix) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($stackPtr + 1); $i < $short; $i++) {
for ($i = $stackPtr + 1; $i < $short; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
$phpcsFile->fixer->addNewline($stackPtr);
Expand All @@ -104,7 +106,7 @@ public function process(File $phpcsFile, $stackPtr): void
}

// Check for additional blank lines at the beginning of the comment.
if ($tokens[$stackPtr]['line'] < ($tokens[$short]['line'] - 1)) {
if ($tokens[$stackPtr]['line'] < $tokens[$short]['line'] - 1) {
$fix = $phpcsFile->addFixableError(
'Additional blank lines found at beginning of doc comment',
$stackPtr,
Expand All @@ -113,8 +115,8 @@ public function process(File $phpcsFile, $stackPtr): void

if ($fix) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($stackPtr + 1); $i < $short; $i++) {
if ($tokens[($i + 1)]['line'] === $tokens[$short]['line']) {
for ($i = $stackPtr + 1; $i < $short; $i++) {
if ($tokens[$i + 1]['line'] === $tokens[$short]['line']) {
break;
}

Expand All @@ -126,7 +128,7 @@ public function process(File $phpcsFile, $stackPtr): void
}

// The last line of the comment should just be the */ code.
$prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true);
$prev = $phpcsFile->findPrevious($empty, $commentEnd - 1, $stackPtr, true);
if (!$isSingleLine && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
$fix = $phpcsFile->addFixableError(
'The close comment tag must be the only content on the line',
Expand All @@ -136,7 +138,7 @@ public function process(File $phpcsFile, $stackPtr): void

if ($fix) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
for ($i = $prev + 1; $i < $commentEnd; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
$phpcsFile->fixer->replaceToken(
Expand All @@ -153,7 +155,7 @@ public function process(File $phpcsFile, $stackPtr): void
}

// Check for additional blank lines at the end of the comment.
if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) {
if ($tokens[$prev]['line'] < $tokens[$commentEnd]['line'] - 1) {
$fix = $phpcsFile->addFixableError(
'Additional blank lines found at end of doc comment',
$commentEnd,
Expand All @@ -162,8 +164,8 @@ public function process(File $phpcsFile, $stackPtr): void

if ($fix) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
if ($tokens[($i + 1)]['line'] === $tokens[$commentEnd]['line']) {
for ($i = $prev + 1; $i < $commentEnd; $i++) {
if ($tokens[$i + 1]['line'] === $tokens[$commentEnd]['line']) {
break;
}

Expand Down
20 changes: 11 additions & 9 deletions SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand All @@ -18,15 +20,15 @@ class FunctionCommentSniff extends PEARFunctionCommentSniff
public function process(File $phpcsFile, $stackPtr): void
{
$tokens = $phpcsFile->getTokens();
$find = Tokens::$methodPrefixes;
$find = Tokens::$methodPrefixes;
$find[] = T_WHITESPACE;

$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
$commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
if (T_COMMENT === $tokens[$commentEnd]['code']) {
// Inline comments might just be closing comments for control structures or functions
// instead of function comments using the wrong comment type.
// If there is other code on the line, assume they relate to that code.
$prev = $phpcsFile->findPrevious($find, ($commentEnd - 1), null, true);
$prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true);
if (false !== $prev && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
$commentEnd = $prev;
}
Expand All @@ -46,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr): void
return;
}

if (($tokens[$stackPtr]['line'] - 1) !== $tokens[$commentEnd]['line']) {
if ($tokens[$stackPtr]['line'] - 1 !== $tokens[$commentEnd]['line']) {
$phpcsFile->addError(
'There must be no blank lines after the function comment',
$commentEnd,
Expand Down Expand Up @@ -183,9 +185,9 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi

if (null !== $throw) {
$exception = null;
if (T_DOC_COMMENT_STRING === $tokens[($throw + 2)]['code']) {
if (T_DOC_COMMENT_STRING === $tokens[$throw + 2]['code']) {
$matches = [];
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($throw + 2)]['content'], $matches);
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[$throw + 2]['content'], $matches);
$exception = $matches[1];
}

Expand Down Expand Up @@ -221,7 +223,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart): voi
private function processWhitespace(File $phpcsFile, int $commentStart, bool $hasComment = true): void
{
$tokens = $phpcsFile->getTokens();
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
$before = $phpcsFile->findPrevious(T_WHITESPACE, $commentStart - 1, null, true);

$startLine = $tokens[$commentStart]['line'];
$prevLine = $tokens[$before]['line'];
Expand All @@ -248,14 +250,14 @@ private function processWhitespace(File $phpcsFile, int $commentStart, bool $has
if ($found > 1) {
$phpcsFile->fixer->beginChangeset();

for ($i = ($before + 1); $i < ($commentStart - 1); $i++) {
for ($i = $before + 1; $i < $commentStart - 1; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
} else {
// Try and maintain indentation.
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
if (T_WHITESPACE === $tokens[$commentStart - 1]['code']) {
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
} else {
$phpcsFile->fixer->addNewlineBefore($commentStart);
Expand Down
10 changes: 6 additions & 4 deletions SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand All @@ -26,7 +28,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr): void
T_WHITESPACE,
];

$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
$commentEnd = $phpcsFile->findPrevious($ignore, $stackPtr - 1, null, true);
if (false === $commentEnd
|| (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
&& T_COMMENT !== $tokens[$commentEnd]['code'])
Expand Down Expand Up @@ -135,7 +137,7 @@ protected function processVariableInString(File $phpcsFile, $stackPtr): void
private function processWhitespace(File $phpcsFile, int $commentStart): void
{
$tokens = $phpcsFile->getTokens();
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
$before = $phpcsFile->findPrevious(T_WHITESPACE, $commentStart - 1, null, true);

$startLine = $tokens[$commentStart]['line'];
$prevLine = $tokens[$before]['line'];
Expand All @@ -159,14 +161,14 @@ private function processWhitespace(File $phpcsFile, int $commentStart): void
if ($found > 1) {
$phpcsFile->fixer->beginChangeset();

for ($i = ($before + 1); $i < ($commentStart - 1); $i++) {
for ($i = $before + 1; $i < $commentStart - 1; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
} else {
// Try and maintain indentation.
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
if (T_WHITESPACE === $tokens[$commentStart - 1]['code']) {
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
} else {
$phpcsFile->fixer->addNewlineBefore($commentStart);
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Errors;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Errors;

use PHP_CodeSniffer\Files\File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Formatting;

use PHP_CodeSniffer\Files\File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Formatting;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Formatting;

use PHP_CodeSniffer\Files\File;
Expand Down
10 changes: 6 additions & 4 deletions SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Formatting;

use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,7 +29,7 @@ public function process(File $phpcsFile, $stackPtr): void
{
$tokens = $phpcsFile->getTokens();

$beginners = Tokens::$booleanOperators;
$beginners = Tokens::$booleanOperators;
$beginners[] = T_IF;
$beginners[] = T_ELSEIF;
$beginners[] = T_EQUAL;
Expand Down Expand Up @@ -65,12 +67,12 @@ public function process(File $phpcsFile, $stackPtr): void
}

// Check if this is a var to var comparison, e.g.: if ( $var1 == $var2 ).
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);

if (isset(Tokens::$castTokens[$tokens[$nextNonEmpty]['code']])) {
$nextNonEmpty = $phpcsFile->findNext(
Tokens::$emptyTokens,
($nextNonEmpty + 1),
$nextNonEmpty + 1,
null,
true
);
Expand All @@ -79,7 +81,7 @@ public function process(File $phpcsFile, $stackPtr): void
if (in_array($tokens[$nextNonEmpty]['code'], [T_SELF, T_PARENT, T_STATIC], true)) {
$nextNonEmpty = $phpcsFile->findNext(
array_merge(Tokens::$emptyTokens, [T_DOUBLE_COLON]),
($nextNonEmpty + 1),
$nextNonEmpty + 1,
null,
true
);
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Functions;

use PHP_CodeSniffer\Files\File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Namespaces;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Namespaces/NamespaceDeclarationSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Namespaces;

use PHP_CodeSniffer\Files\File;
Expand Down
2 changes: 2 additions & 0 deletions SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SymfonyCustom\Sniffs\Namespaces;

use PHP_CodeSniffer\Files\File;
Expand Down
Loading