Initial commit: apps.prometeysev.ru
This commit is contained in:
commit
96ccabcd8b
6561 files changed
+1270349
No files matched your search
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace CakePHP\Sniffs\Formatting;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
/**
|
||||
* Throws errors if there's no blank line before return statements.
|
||||
*
|
||||
* @author Authors <Symfony2-coding-standard@escapestudios.github.com>
|
||||
* @license http://spdx.org/licenses/MIT MIT License
|
||||
* @link https://github.com/escapestudios/Symfony2-coding-standard
|
||||
*/
|
||||
class BlankLineBeforeReturnSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = [
|
||||
'PHP',
|
||||
'JS',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_RETURN];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$current = $stackPtr;
|
||||
$previousLine = $tokens[$stackPtr]['line'] - 1;
|
||||
$prevLineTokens = [];
|
||||
|
||||
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
|
||||
if (
|
||||
$tokens[$current]['line'] == $previousLine
|
||||
&& $tokens[$current]['type'] !== 'T_WHITESPACE'
|
||||
&& $tokens[$current]['type'] !== 'T_COMMENT'
|
||||
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_OPEN_TAG'
|
||||
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_TAG'
|
||||
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_STRING'
|
||||
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_CLOSE_TAG'
|
||||
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_WHITESPACE'
|
||||
) {
|
||||
$prevLineTokens[] = $tokens[$current]['type'];
|
||||
}
|
||||
$current--;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($prevLineTokens[0])
|
||||
&& ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET'
|
||||
|| $prevLineTokens[0] === 'T_COLON'
|
||||
|| $prevLineTokens[0] === 'T_OPEN_TAG')
|
||||
) {
|
||||
return;
|
||||
} elseif (count($prevLineTokens) > 0) {
|
||||
$fix = $phpcsFile->addFixableError(
|
||||
'Missing blank line before return statement',
|
||||
$stackPtr,
|
||||
'BlankLineBeforeReturn'
|
||||
);
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->beginChangeset();
|
||||
$phpcsFile->fixer->addNewlineBefore($stackPtr - 1);
|
||||
$phpcsFile->fixer->endChangeset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+154
@@ -0,0 +1,154 @@
|
||||
<?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)
|
||||
* @since CakePHP CodeSniffer 0.1.10
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
namespace CakePHP\Sniffs\Formatting;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
/**
|
||||
* Ensures all the use are in alphabetical order.
|
||||
*
|
||||
*/
|
||||
class UseInAlphabeticalOrderSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Processed files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_processed = [];
|
||||
|
||||
/**
|
||||
* The list of use statements, their content and scope.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_uses = [];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [T_USE];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
if (isset($this->_processed[$phpcsFile->getFilename()])) {
|
||||
return;
|
||||
}
|
||||
$filename = $phpcsFile->getFilename();
|
||||
|
||||
$this->_uses = [];
|
||||
$next = $stackPtr;
|
||||
|
||||
while ($next !== false) {
|
||||
$this->_checkUseToken($phpcsFile, $next);
|
||||
$next = $phpcsFile->findNext(T_USE, $next + 1);
|
||||
}
|
||||
|
||||
// Prevent multiple uses in the same file from entering
|
||||
$this->_processed[$phpcsFile->getFilename()] = true;
|
||||
|
||||
foreach ($this->_uses as $scope => $used) {
|
||||
$defined = $sorted = array_keys($used);
|
||||
|
||||
natcasesort($sorted);
|
||||
$sorted = array_values($sorted);
|
||||
if ($sorted === $defined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($defined as $i => $name) {
|
||||
if ($name !== $sorted[$i]) {
|
||||
$error = 'Use classes must be in alphabetical order. Was expecting ' . $sorted[$i];
|
||||
$phpcsFile->addError($error, $used[$name], 'UseInAlphabeticalOrder');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all the use tokens in a file.
|
||||
*
|
||||
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file to check.
|
||||
* @param int $stackPtr The index of the first use token.
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkUseToken($phpcsFile, $stackPtr)
|
||||
{
|
||||
// If the use token is for a closure we want to ignore it.
|
||||
$isClosure = $this->_isClosure($phpcsFile, $stackPtr);
|
||||
if ($isClosure) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$scope = 'use';
|
||||
$useType = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
|
||||
if ($useType !== false && $tokens[$useType]['code'] === T_STRING) {
|
||||
$useContent = strtolower($tokens[$useType]['content']);
|
||||
if ($useContent === 'function' || $useContent === 'const') {
|
||||
$scope .= ' ' . $useContent;
|
||||
$stackPtr = $useType + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$end = $phpcsFile->findNext([T_SEMICOLON, T_OPEN_CURLY_BRACKET], $stackPtr);
|
||||
$useTokens = array_slice($tokens, $stackPtr, $end - $stackPtr, true);
|
||||
|
||||
foreach ($useTokens as $index => $token) {
|
||||
if ($token['code'] === T_STRING || $token['code'] === T_NS_SEPARATOR) {
|
||||
$content .= $token['content'];
|
||||
}
|
||||
}
|
||||
|
||||
// Check for class scoping on use. Traits should be
|
||||
// ordered independently.
|
||||
if (!empty($token['conditions'])) {
|
||||
$scope .= key($token['conditions']);
|
||||
}
|
||||
$this->_uses[$scope][$content] = $stackPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current stackPtr is a use token that is for a closure.
|
||||
*
|
||||
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The index of the first use token.
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isClosure($phpcsFile, $stackPtr)
|
||||
{
|
||||
return $phpcsFile->findPrevious(
|
||||
[T_CLOSURE],
|
||||
($stackPtr - 1),
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user