Skip to content

Commit

Permalink
Require PHP5.4 from now on and add editorconfig file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 21, 2016
1 parent bccb1da commit ecd0b09
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 127 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.bat]
end_of_line = crlf

[*.yml]
indent_style = space
indent_size = 2
10 changes: 5 additions & 5 deletions CakePHP/Sniffs/Commenting/DocBlockAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CakePHP_Sniffs_Commenting_DocBlockAlignmentSniff implements PHP_CodeSniffe
*/
public function register()
{
return array(T_DOC_COMMENT_OPEN_TAG);
return [T_DOC_COMMENT_OPEN_TAG];
}

/**
Expand All @@ -40,18 +40,18 @@ public function register()
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$leftWall = array(
$leftWall = [
T_CLASS,
T_NAMESPACE,
T_INTERFACE,
T_TRAIT,
T_USE
);
$oneIndentation = array(
];
$oneIndentation = [
T_FUNCTION,
T_VARIABLE,
T_CONST
);
];
$allTokens = array_merge($leftWall, $oneIndentation);
$notFlatFile = $phpcsFile->findNext(T_NAMESPACE, 0);
$next = $phpcsFile->findNext($allTokens, $stackPtr + 1);
Expand Down
42 changes: 21 additions & 21 deletions CakePHP/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
// Check return type (can be multiple, separated by '|').
list($types,) = explode(' ', $content);
$typeNames = explode('|', $types);
$suggestedNames = array();
$suggestedNames = [];
foreach ($typeNames as $i => $typeName) {
if ($typeName === 'integer') {
$suggestedName = 'int';
} elseif ($typeName === 'boolean') {
$suggestedName = 'bool';
} elseif (in_array($typeName, array('int', 'bool'))) {
} elseif (in_array($typeName, ['int', 'bool'])) {
$suggestedName = $typeName;
} else {
$suggestedName = PHP_CodeSniffer::suggestType($typeName);
Expand All @@ -147,10 +147,10 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
if ($types !== $suggestedType) {
$error = 'Function return type "%s" is invalid';
$error = 'Expected "%s" but found "%s" for function return type';
$data = array(
$data = [
$suggestedType,
$types,
);
];
$phpcsFile->addError($error, $return, 'InvalidReturn', $data);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
// If return type is not void, there needs to be a return statement
// somewhere in the function that returns something.
if (!in_array('mixed', $typeNames, true) && !in_array('void', $typeNames, true)) {
$returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $stackPtr, $endToken);
$returnToken = $phpcsFile->findNext([T_RETURN, T_YIELD], $stackPtr, $endToken);
if ($returnToken === false) {
$error = 'Function return type is not void, but function has no return statement';
$phpcsFile->addWarning($error, $return, 'InvalidNoReturn');
Expand Down Expand Up @@ -218,15 +218,15 @@ protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
{
$tokens = $phpcsFile->getTokens();

$throws = array();
$throws = [];
foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) {
if ($tokens[$tag]['content'] !== '@throws') {
continue;
}

$exception = $comment = null;
if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) {
$matches = array();
$matches = [];
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($tag + 2)]['content'], $matches);
$exception = $matches[1];
if (isset($matches[2]) === true) {
Expand Down Expand Up @@ -288,7 +288,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co

$tokens = $phpcsFile->getTokens();

$params = array();
$params = [];
$maxType = $maxVar = 0;
foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) {
if ($tokens[$tag]['content'] !== '@param') {
Expand All @@ -297,9 +297,9 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co

$type = $var = $comment = '';
$typeSpace = $varSpace = 0;
$commentLines = array();
$commentLines = [];
if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) {
$matches = array();
$matches = [];
preg_match('/([^$&]+)(?:((?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);

$typeLen = strlen($matches[1]);
Expand All @@ -320,11 +320,11 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
if (isset($matches[4]) === true) {
$varSpace = strlen($matches[3]);
$comment = $matches[4];
$commentLines[] = array(
$commentLines[] = [
'comment' => $comment,
'token' => ($tag + 2),
'indent' => $varSpace,
);
];

// Any strings until the next tag belong to this comment.
if (isset($tokens[$commentStart]['comment_tags'][($pos + 1)]) === true) {
Expand All @@ -341,17 +341,17 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
}

$comment .= ' ' . $tokens[$i]['content'];
$commentLines[] = array(
$commentLines[] = [
'comment' => $tokens[$i]['content'],
'token' => $i,
'indent' => $indent,
);
];
}
}
} else {
$error = 'Missing parameter comment';
$phpcsFile->addError($error, $tag, 'MissingParamComment');
$commentLines[] = array('comment' => '');
$commentLines[] = ['comment' => ''];
}//end if
} else {
$error = 'Missing parameter name';
Expand All @@ -366,7 +366,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
}//end foreach

$realParams = $phpcsFile->getMethodParameters($stackPtr);
$foundParams = array();
$foundParams = [];

foreach ($params as $pos => $param) {
// If the type is empty, the whole line is empty.
Expand All @@ -381,15 +381,15 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$suggestedName = 'int';
} elseif ($typeName === 'boolean') {
$suggestedName = 'bool';
} elseif (in_array($typeName, array('int', 'bool'))) {
} elseif (in_array($typeName, ['int', 'bool'])) {
$suggestedName = $typeName;
} else {
$suggestedName = PHP_CodeSniffer::suggestType($typeName);
}

if ($typeName !== $suggestedName) {
$error = 'Expected "%s" but found "%s" for parameter type';
$data = array($suggestedName, $typeName);
$data = [$suggestedName, $typeName];

$fix = $phpcsFile->addFixableError($error, $param['tag'], 'IncorrectParamVarName', $data);
if ($fix === true) {
Expand All @@ -414,7 +414,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$realName = $realParams[$pos]['name'];
if ($realName !== $param['var']) {
$code = 'ParamNameNoMatch';
$data = array($param['var'], $realName);
$data = [$param['var'], $realName];

$error = 'Doc comment for parameter %s does not match ';
if (strtolower($param['var']) === strtolower($realName)) {
Expand Down Expand Up @@ -459,7 +459,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
}
}//end foreach

$realNames = array();
$realNames = [];
foreach ($realParams as $realParam) {
$realNames[] = $realParam['name'];
}
Expand All @@ -468,7 +468,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$diff = array_diff($realNames, $foundParams);
foreach ($diff as $neededParam) {
$error = 'Doc comment for parameter "%s" missing';
$data = array($neededParam);
$data = [$neededParam];
$phpcsFile->addWarning($error, $commentStart, 'MissingParamTag', $data);
}

Expand Down
12 changes: 6 additions & 6 deletions CakePHP/Sniffs/Commenting/FunctionCommentTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CakePHP_Sniffs_Commenting_FunctionCommentTypeSniff implements PHP_CodeSnif
*/
public function register()
{
return array(T_DOC_COMMENT);
return [T_DOC_COMMENT];
}

/**
Expand All @@ -44,7 +44,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

// We are only interested in function/class/interface doc block comments.
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
$ignore = array(
$ignore = [
T_CLASS,
T_INTERFACE,
T_FUNCTION,
Expand All @@ -53,7 +53,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
T_PROTECTED,
T_STATIC,
T_ABSTRACT,
);
];

if (in_array($tokens[$nextToken]['code'], $ignore) === false) {
// Could be a file comment.
Expand All @@ -63,10 +63,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}

$types = array(
$types = [
'boolean' => 'bool',
'integer' => 'int',
);
];
foreach ($types as $from => $to) {
$this->_check($phpcsFile, $stackPtr, $from, $to);
}
Expand All @@ -85,7 +85,7 @@ protected function _check(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $from, $to
$tokens = $phpcsFile->getTokens();
$content = $tokens[$stackPtr]['content'];

$matches = array();
$matches = [];
if (preg_match('/\@(\w+)\s+([\w\\|\\\\]*?)' . $from . '\b/i', $content, $matches) === 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CakePHP_Sniffs_ControlStructures_ControlStructuresSniff implements PHP_Cod
*/
public function register()
{
return array(T_IF, T_ELSEIF, T_ELSE, T_FOREACH, T_FOR);
return [T_IF, T_ELSEIF, T_ELSE, T_FOREACH, T_FOR];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CakePHP_Sniffs_ControlStructures_ElseIfDeclarationSniff implements PHP_Cod
*/
public function register()
{
return array(T_ELSE);
return [T_ELSE];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CakePHP/Sniffs/ControlStructures/WhileStructuresSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CakePHP_Sniffs_ControlStructures_WhileStructuresSniff implements PHP_CodeS
*/
public function register()
{
return array(T_DO, T_WHILE);
return [T_DO, T_WHILE];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions CakePHP/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class CakePHP_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSn
*
* @var array
*/
public $supportedTokenizers = array(
public $supportedTokenizers = [
'PHP',
'JS',
);
];

/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -25,7 +25,7 @@ class CakePHP_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSn
*/
public function register()
{
return array(T_RETURN);
return [T_RETURN];
}

/**
Expand All @@ -42,7 +42,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();
$current = $stackPtr;
$previousLine = $tokens[$stackPtr]['line'] - 1;
$prevLineTokens = array();
$prevLineTokens = [];

while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
if ($tokens[$current]['line'] == $previousLine
Expand Down
6 changes: 3 additions & 3 deletions CakePHP/Sniffs/Formatting/OneClassPerUseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CakePHP_Sniffs_Formatting_OneClassPerUseSniff implements PHP_CodeSniffer_S
*/
public function register()
{
return array(T_USE);
return [T_USE];
}

/**
Expand All @@ -45,13 +45,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$i = 2; // Ignore use word and whitespace
$filename = $phpcsFile->getFilename();

while (in_array($tokens[$stackPtr + $i]['code'], array(T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_AS))) {
while (in_array($tokens[$stackPtr + $i]['code'], [T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_AS])) {
$i++;
}

if ($tokens[$stackPtr + $i]['code'] === T_COMMA) {
$error = 'Only one class is allowed per use';
$phpcsFile->addError($error, $stackPtr, 'OneClassPerUse', array());
$phpcsFile->addError($error, $stackPtr, 'OneClassPerUse', []);
}
}
}
Loading

0 comments on commit ecd0b09

Please sign in to comment.