Initial commit: apps.supersam24.ru
This commit is contained in:
commit
e955e1da36
6566 files changed
+1271095
No files matched your search
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace CakePHP\Sniffs\PHP;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
/**
|
||||
* Adds trailing commas in multiline arrays.
|
||||
*
|
||||
* Heredoc patch taken from slevomat/coding-standard project.
|
||||
*
|
||||
* @author Mark Scherer
|
||||
* @license MIT
|
||||
*/
|
||||
class CommaAfterArrayItemSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $enableAfterHeredoc = PHP_VERSION_ID >= 70300;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [
|
||||
T_OPEN_SHORT_ARRAY,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$arrayToken = $tokens[$stackPtr];
|
||||
$closeParenthesisPointer = $arrayToken['bracket_closer'];
|
||||
$openParenthesisToken = $tokens[$arrayToken['bracket_opener']];
|
||||
$closeParenthesisToken = $tokens[$closeParenthesisPointer];
|
||||
if ($openParenthesisToken['line'] === $closeParenthesisToken['line']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previousToCloseParenthesisPointer = $phpcsFile->findPrevious(Tokens::$emptyTokens, $closeParenthesisPointer - 1, 0, true);
|
||||
$previousToCloseParenthesisToken = $tokens[$previousToCloseParenthesisPointer];
|
||||
if (
|
||||
$previousToCloseParenthesisPointer === $arrayToken['bracket_opener']
|
||||
|| $previousToCloseParenthesisToken['code'] === T_COMMA
|
||||
|| $closeParenthesisToken['line'] === $previousToCloseParenthesisToken['line']
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!$this->enableAfterHeredoc && in_array($previousToCloseParenthesisToken['code'], [T_END_HEREDOC, T_END_NOWDOC], true)) {
|
||||
return;
|
||||
}
|
||||
$fix = $phpcsFile->addFixableError(
|
||||
'Multi-line arrays must have a trailing comma after the last element.',
|
||||
$previousToCloseParenthesisPointer,
|
||||
'MissingTrailingComma'
|
||||
);
|
||||
if (!$fix) {
|
||||
return;
|
||||
}
|
||||
|
||||
$phpcsFile->fixer->beginChangeset();
|
||||
$phpcsFile->fixer->addContent($previousToCloseParenthesisPointer, ',');
|
||||
$phpcsFile->fixer->endChangeset();
|
||||
}
|
||||
}
|
||||
+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 0.1.14
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Disallow short open tags
|
||||
*
|
||||
* But permit short-open echo tags (<?=) [T_OPEN_TAG_WITH_ECHO] as they are part of PHP 5.4+
|
||||
*
|
||||
*/
|
||||
namespace CakePHP\Sniffs\PHP;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
class DisallowShortOpenTagSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* If short open tags are NOT enabled, <? is not considered a T_OPEN_TAG
|
||||
* So include T_INLINE_HTML which is what "<?" is detected as
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return [
|
||||
T_OPEN_TAG,
|
||||
T_INLINE_HTML,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$openTag = $tokens[$stackPtr];
|
||||
|
||||
if (trim($openTag['content']) === '<?') {
|
||||
$error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
|
||||
$data = [trim($openTag['content'])];
|
||||
$phpcsFile->addError($error, $stackPtr, 'Found', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* 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
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Asserts that type casts are in the short form:
|
||||
* - bool instead of boolean
|
||||
* - int instead of integer
|
||||
*/
|
||||
namespace CakePHP\Sniffs\PHP;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Util\Tokens;
|
||||
|
||||
class TypeCastingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* Note, that this sniff only checks the value and casing of a cast.
|
||||
* It does not check for whitespace issues regarding casts, as
|
||||
* - Squiz.WhiteSpace.CastSpacing.ContainsWhiteSpace checks for whitespace in the cast
|
||||
* - Generic.Formatting.NoSpaceAfterCast.SpaceFound checks for whitespace after the cast
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array_merge(Tokens::$castTokens, [T_BOOLEAN_NOT]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Process !! casts
|
||||
if ($tokens[$stackPtr]['code'] == T_BOOLEAN_NOT) {
|
||||
$nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
|
||||
if (!$nextToken) {
|
||||
return;
|
||||
}
|
||||
if ($tokens[$nextToken]['code'] != T_BOOLEAN_NOT) {
|
||||
return;
|
||||
}
|
||||
$error = 'Usage of !! cast is not allowed. Please use (bool) to cast.';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotAllowed');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Only allow short forms if both short and long forms are possible
|
||||
$matching = [
|
||||
'(boolean)' => '(bool)',
|
||||
'(integer)' => '(int)',
|
||||
];
|
||||
$content = $tokens[$stackPtr]['content'];
|
||||
$key = strtolower($content);
|
||||
if (isset($matching[$key])) {
|
||||
$error = 'Please use ' . $matching[$key] . ' instead of ' . $content . '.';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotAllowed');
|
||||
|
||||
return;
|
||||
}
|
||||
if ($content !== $key) {
|
||||
$error = 'Please use ' . $key . ' instead of ' . $content . '.';
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotAllowed');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user