Initial commit: apps.prometeysev.ru
This commit is contained in:
commit
96ccabcd8b
6561 files changed
+1270349
No files matched your search
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.14
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensures no whitespaces and one whitespace is placed around each comma
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class CommaSpacingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_COMMA];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
|
||||
|
||||
if ($tokens[$next]['code'] !== T_WHITESPACE && ($next !== $stackPtr + 2)) {
|
||||
// Skip if immediate char is comma
|
||||
if ($tokens[$next]['code'] === T_COMMA) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Last character in a line is ok.
|
||||
if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
|
||||
$error = 'Missing space after comma';
|
||||
$fix = $phpcsFile->addFixableError($error, $next, 'MissingSpaceAfterComma');
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->beginChangeset();
|
||||
$phpcsFile->fixer->addContent($stackPtr, ' ');
|
||||
$phpcsFile->fixer->endChangeset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$previous = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
|
||||
|
||||
if ($tokens[$previous]['code'] !== T_WHITESPACE && ($previous !== $stackPtr - 1)) {
|
||||
$error = 'Space before comma, expected none, though';
|
||||
$phpcsFile->addError($error, $next, 'SpaceBeforeComma');
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 2.4.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensures that not more than one blank line occurs
|
||||
*
|
||||
* @author Mark Scherer
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class EmptyLinesSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_WHITESPACE];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
// If the current and next two tokens are newlines
|
||||
// We can remove the next token (the first newline)
|
||||
if (
|
||||
$tokens[$stackPtr]['content'] === $phpcsFile->eolChar
|
||||
&& isset($tokens[$stackPtr + 1])
|
||||
&& $tokens[$stackPtr + 1]['content'] === $phpcsFile->eolChar
|
||||
&& isset($tokens[$stackPtr + 2])
|
||||
&& $tokens[$stackPtr + 2]['content'] === $phpcsFile->eolChar
|
||||
) {
|
||||
$error = 'Found more than a single empty line between content';
|
||||
$fix = $phpcsFile->addFixableError($error, $stackPtr + 2, 'EmptyLines');
|
||||
if ($fix) {
|
||||
$phpcsFile->fixer->replaceToken($stackPtr + 2, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.12
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks the separation between methods in a class or interface.
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
class FunctionCallSpacingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [
|
||||
T_ISSET,
|
||||
T_EMPTY,
|
||||
T_STRING,
|
||||
T_INCLUDE,
|
||||
T_INCLUDE_ONCE,
|
||||
T_REQUIRE,
|
||||
T_REQUIRE_ONCE,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Find the next non-empty token.
|
||||
$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
|
||||
|
||||
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
|
||||
// Not a function call.
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for funcName (
|
||||
if (($stackPtr + 1) !== $openBracket) {
|
||||
$error = 'Space before opening parenthesis of function call not allowed';
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpaceBeforeOpenBracket');
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* This file is originally written by Greg Sherwood and Marc McIntyre, but
|
||||
* modified for CakePHP.
|
||||
*
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.1
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks that there is one empty line before the closing brace of a function.
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class FunctionClosingBraceSpaceSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_FUNCTION];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
|
||||
// Probably an interface method.
|
||||
return;
|
||||
}
|
||||
|
||||
$closeBrace = $tokens[$stackPtr]['scope_closer'];
|
||||
$prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true);
|
||||
|
||||
$braceLine = $tokens[$closeBrace]['line'];
|
||||
$prevLine = $tokens[$prevContent]['line'];
|
||||
|
||||
$found = ($braceLine - $prevLine - 1);
|
||||
if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true || isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
|
||||
// Nested function.
|
||||
if ($found < 0) {
|
||||
$error = 'Closing brace of nested function must be on a new line';
|
||||
$phpcsFile->addError($error, $closeBrace, 'ContentBeforeClose');
|
||||
} elseif ($found > 0) {
|
||||
$error = 'Expected 0 blank lines before closing brace of nested function; %s found';
|
||||
$data = [$found];
|
||||
$phpcsFile->addError($error, $closeBrace, 'SpacingBeforeNestedClose', $data);
|
||||
}
|
||||
} else {
|
||||
if ($found !== 0) {
|
||||
$error = 'Expected 0 blank lines before closing function brace; %s found';
|
||||
$data = [$found];
|
||||
$phpcsFile->addError($error, $closeBrace, 'SpacingBeforeClose', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* This file is originally written by Greg Sherwood and Marc McIntyre, but
|
||||
* modified for CakePHP.
|
||||
*
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.1
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks that there is no empty line after the opening brace of a function.
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class FunctionOpeningBraceSpaceSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_FUNCTION];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
|
||||
// Probably an interface method.
|
||||
return;
|
||||
}
|
||||
|
||||
$openBrace = $tokens[$stackPtr]['scope_opener'];
|
||||
$nextContent = $phpcsFile->findNext(T_WHITESPACE, ($openBrace + 1), null, true);
|
||||
|
||||
if ($nextContent === $tokens[$stackPtr]['scope_closer']) {
|
||||
// The next bit of content is the closing brace, so this
|
||||
// is an empty function and should have a blank line
|
||||
// between the opening and closing braces.
|
||||
return;
|
||||
}
|
||||
|
||||
$braceLine = $tokens[$openBrace]['line'];
|
||||
$nextLine = $tokens[$nextContent]['line'];
|
||||
|
||||
$found = ($nextLine - $braceLine - 1);
|
||||
if ($found > 0) {
|
||||
$error = 'Expected 0 blank lines after opening function brace; %s found';
|
||||
$data = [$found];
|
||||
$phpcsFile->addError($error, $openBrace, 'SpacingAfter', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
||||
*
|
||||
* This file is originally written by Greg Sherwood and Marc McIntyre, but
|
||||
* modified for CakePHP.
|
||||
*
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @link https://github.com/cakephp/cakephp-codesniffer
|
||||
* @since CakePHP CodeSniffer 0.1.1
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks the separation between methods in a class or interface.
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
/**
|
||||
* There should always be newlines around functions/methods.
|
||||
*/
|
||||
class FunctionSpacingSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_FUNCTION];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpCsFile, $stackPointer)
|
||||
{
|
||||
$tokens = $phpCsFile->getTokens();
|
||||
|
||||
$level = $tokens[$stackPointer]['level'];
|
||||
if ($level < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$openingBraceIndex = $phpCsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPointer + 1);
|
||||
// Fix interface methods
|
||||
if (!$openingBraceIndex) {
|
||||
$openingParenthesisIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPointer + 1);
|
||||
$closingParenthesisIndex = $tokens[$openingParenthesisIndex]['parenthesis_closer'];
|
||||
|
||||
$semicolonIndex = $phpCsFile->findNext(T_SEMICOLON, $closingParenthesisIndex + 1);
|
||||
|
||||
$nextContentIndex = $phpCsFile->findNext(T_WHITESPACE, $semicolonIndex + 1, null, true);
|
||||
|
||||
// Do not mess with the end of the class
|
||||
if ($tokens[$nextContentIndex]['type'] === 'T_CLOSE_CURLY_BRACKET') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[$nextContentIndex]['line'] - $tokens[$semicolonIndex]['line'] <= 1) {
|
||||
$fix = $phpCsFile->addFixableError('Every function/method needs a newline afterwards', $closingParenthesisIndex, 'Abstract');
|
||||
if ($fix) {
|
||||
$phpCsFile->fixer->addNewline($semicolonIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$closingBraceIndex = $tokens[$openingBraceIndex]['scope_closer'];
|
||||
|
||||
// Ignore closures
|
||||
$nextIndex = $phpCsFile->findNext(Tokens::$emptyTokens, $closingBraceIndex + 1, null, true);
|
||||
if (in_array($tokens[$nextIndex]['content'], [';', ',', ')'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nextContentIndex = $phpCsFile->findNext(T_WHITESPACE, $closingBraceIndex + 1, null, true);
|
||||
|
||||
// Do not mess with the end of the class
|
||||
if ($tokens[$nextContentIndex]['type'] === 'T_CLOSE_CURLY_BRACKET') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertNewLineAtTheEnd($phpCsFile, $closingBraceIndex, $nextContentIndex);
|
||||
$this->assertNewLineAtTheBeginning($phpCsFile, $stackPointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PHP_CodeSniffer\Files\File $phpCsFile File
|
||||
* @param int $closingBraceIndex Index
|
||||
* @param int|null $nextContentIndex Index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function assertNewLineAtTheEnd(File $phpCsFile, $closingBraceIndex, $nextContentIndex)
|
||||
{
|
||||
$tokens = $phpCsFile->getTokens();
|
||||
|
||||
if (!$nextContentIndex || $tokens[$nextContentIndex]['line'] - $tokens[$closingBraceIndex]['line'] <= 1) {
|
||||
$fix = $phpCsFile->addFixableError('Every function/method needs a newline afterwards', $closingBraceIndex, 'Concrete');
|
||||
if ($fix) {
|
||||
$phpCsFile->fixer->addNewline($closingBraceIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts newline at the beginning, including the doc block.
|
||||
*
|
||||
* @param \PHP_CodeSniffer\Files\File $phpCsFile File
|
||||
* @param int $stackPointer Stack pointer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function assertNewLineAtTheBeginning(File $phpCsFile, $stackPointer)
|
||||
{
|
||||
$tokens = $phpCsFile->getTokens();
|
||||
|
||||
$line = $tokens[$stackPointer]['line'];
|
||||
$firstTokenInLineIndex = $stackPointer;
|
||||
while ($tokens[$firstTokenInLineIndex - 1]['line'] === $line) {
|
||||
$firstTokenInLineIndex--;
|
||||
}
|
||||
|
||||
$prevContentIndex = $phpCsFile->findPrevious(T_WHITESPACE, $firstTokenInLineIndex - 1, null, true);
|
||||
if ($tokens[$prevContentIndex]['type'] === 'T_DOC_COMMENT_CLOSE_TAG') {
|
||||
$firstTokenInLineIndex = $tokens[$prevContentIndex]['comment_opener'];
|
||||
while ($tokens[$firstTokenInLineIndex - 1]['line'] === $line) {
|
||||
$firstTokenInLineIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
$prevContentIndex = $phpCsFile->findPrevious(T_WHITESPACE, $firstTokenInLineIndex - 1, null, true);
|
||||
|
||||
// Do not mess with the start of the class
|
||||
if ($tokens[$prevContentIndex]['type'] === 'T_OPEN_CURLY_BRACKET') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[$prevContentIndex]['line'] < $tokens[$firstTokenInLineIndex]['line'] - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fix = $phpCsFile->addFixableError('Every function/method needs a newline before', $firstTokenInLineIndex, 'Concrete');
|
||||
if ($fix) {
|
||||
$phpCsFile->fixer->addNewline($prevContentIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* This file is originally written by Greg Sherwood and Marc McIntyre, but
|
||||
* modified for CakePHP.
|
||||
*
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.1
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensure there is no whitespace after an object operator.
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
class ObjectOperatorSpacingSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_OBJECT_OPERATOR];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$nextType = $tokens[($stackPtr + 1)]['code'];
|
||||
if (in_array($nextType, Tokens::$emptyTokens) === true) {
|
||||
$error = 'Space found after object operator';
|
||||
$phpcsFile->addError($error, $stackPtr, 'After');
|
||||
}
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* This file is originally written by Greg Sherwood and Marc McIntyre, but
|
||||
* modified for CakePHP.
|
||||
*
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.6
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
/**
|
||||
* Verifies that operators have valid spacing surrounding them.
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
class OperatorSpacingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = [
|
||||
'PHP',
|
||||
'JS',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$comparison = Tokens::$comparisonTokens;
|
||||
$operators = Tokens::$operators;
|
||||
$assignment = Tokens::$assignmentTokens;
|
||||
|
||||
return array_unique(array_merge($comparison, $operators, $assignment));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Skip default values in function declarations.
|
||||
// and declare statements
|
||||
if (
|
||||
$tokens[$stackPtr]['code'] === T_EQUAL
|
||||
|| $tokens[$stackPtr]['code'] === T_MINUS
|
||||
) {
|
||||
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
|
||||
$parenthesis = array_keys($tokens[$stackPtr]['nested_parenthesis']);
|
||||
$bracket = array_pop($parenthesis);
|
||||
if (isset($tokens[$bracket]['parenthesis_owner']) === true) {
|
||||
$function = $tokens[$bracket]['parenthesis_owner'];
|
||||
if (
|
||||
$tokens[$function]['code'] === T_FUNCTION ||
|
||||
$tokens[$function]['code'] === T_DECLARE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[$stackPtr]['code'] === T_EQUAL) {
|
||||
// Skip for '=&' case.
|
||||
if (isset($tokens[($stackPtr + 1)]) === true && $tokens[($stackPtr + 1)]['code'] === T_BITWISE_AND) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[$stackPtr]['code'] === T_BITWISE_AND) {
|
||||
// If its not a reference, then we expect one space either side of the
|
||||
// bitwise operator.
|
||||
if (!$phpcsFile->isReference($stackPtr) && !$this->_isVariable($stackPtr, $tokens, $phpcsFile)) {
|
||||
// Check there is one space before the & operator.
|
||||
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = 'Expected 1 space before "&" operator; 0 found';
|
||||
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBeforeAmp');
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Check there is one space after the & operator.
|
||||
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = 'Expected 1 space after "&" operator; 0 found';
|
||||
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfterAmp');
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->addContent($stackPtr, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($tokens[$stackPtr]['code'] === T_MINUS) {
|
||||
// Skip declaration of negative value in new array format; eg. $arr = [-1].
|
||||
if ($tokens[($stackPtr - 1)]['code'] === T_OPEN_SHORT_ARRAY) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check minus spacing, but make sure we aren't just assigning
|
||||
// a minus value or returning one.
|
||||
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
|
||||
if ($tokens[$prev]['code'] === T_RETURN) {
|
||||
// Just returning a negative value; eg. return -1.
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($tokens[$prev]['code'], Tokens::$operators) === true) {
|
||||
// Just trying to operate on a negative value; eg. ($var * -1).
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($tokens[$prev]['code'], Tokens::$comparisonTokens) === true) {
|
||||
// Just trying to compare a negative value; eg. ($var === -1).
|
||||
return;
|
||||
}
|
||||
|
||||
// A list of tokens that indicate that the token is not
|
||||
// part of an arithmetic operation.
|
||||
$invalidTokens = [
|
||||
T_COMMA,
|
||||
T_OPEN_PARENTHESIS,
|
||||
T_OPEN_SQUARE_BRACKET,
|
||||
T_DOUBLE_ARROW,
|
||||
T_COLON,
|
||||
T_INLINE_THEN,
|
||||
T_INLINE_ELSE,
|
||||
T_CASE,
|
||||
];
|
||||
|
||||
if (in_array($tokens[$prev]['code'], $invalidTokens) === true) {
|
||||
// Just trying to use a negative value; eg. myFunction($var, -2).
|
||||
return;
|
||||
}
|
||||
if (in_array($tokens[$prev]['code'], Tokens::$assignmentTokens) === true) {
|
||||
// Just trying to assign a negative value; eg. ($var = -1).
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$operator = $tokens[$stackPtr]['content'];
|
||||
|
||||
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = "Expected 1 space before \"$operator\"; 0 found";
|
||||
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore');
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
|
||||
$error = "Expected 1 space after \"$operator\"; 0 found";
|
||||
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceAfter');
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->addContent($stackPtr, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current token is inside an array.
|
||||
*
|
||||
* @param int $stackPtr The current token offset.
|
||||
* @param array $tokens The current token list.
|
||||
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isVariable($stackPtr, $tokens, $phpcsFile)
|
||||
{
|
||||
$tokenAfter = $phpcsFile->findNext(
|
||||
Tokens::$emptyTokens,
|
||||
($stackPtr + 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
$tokenBefore = $phpcsFile->findNext(
|
||||
Tokens::$emptyTokens,
|
||||
($stackPtr - 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
return ($tokens[$tokenAfter]['code'] === T_VARIABLE &&
|
||||
(
|
||||
$tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS ||
|
||||
$tokens[$tokenBefore]['code'] === T_COMMA ||
|
||||
$tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer_CakePHP
|
||||
* @since CakePHP CodeSniffer 0.1.11
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check for any line starting with 2 spaces - which would indicate space indenting
|
||||
* Also check for "\t " - a tab followed by a space, which is a common similar mistake
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class TabAndSpaceSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = [
|
||||
'PHP',
|
||||
'JS',
|
||||
'CSS',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_WHITESPACE];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$line = $tokens[$stackPtr]['line'];
|
||||
if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] !== $line) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($tokens[$stackPtr]['content'], ' ') !== false) {
|
||||
$error = 'Double space found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'DoubleSpace');
|
||||
}
|
||||
if (strpos($tokens[$stackPtr]['content'], " \t") !== false) {
|
||||
$error = 'Space and tab found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpaceAndTab');
|
||||
}
|
||||
if (strpos($tokens[$stackPtr]['content'], "\t ") !== false) {
|
||||
$error = 'Tab and space found';
|
||||
$phpcsFile->addError($error, $stackPtr, 'TabAndSpace');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user