mirror of
https://github.com/joomla/joomla-cms.git
synced 2024-06-16 09:02:52 +00:00
[4.0] Codestyle fixes for new CMS codestyle Batch 8/16? (#25459)
This commit is contained in:
parent
d7f0a94629
commit
47688cd4de
14
.drone.yml
14
.drone.yml
|
@ -26,23 +26,15 @@ steps:
|
|||
- composer install --no-progress --no-suggest
|
||||
|
||||
- name: phpcs
|
||||
image: joomlaprojects/docker-phpcs
|
||||
depends_on: [ composer ]
|
||||
commands:
|
||||
- echo $(date)
|
||||
- /root/.composer/vendor/bin/phpcs --report=full --encoding=utf-8 --extensions=php -p --standard=build/phpcs/Joomla .
|
||||
- echo $(date)
|
||||
|
||||
- name: phpcs-new
|
||||
image: joomlaprojects/docker-images:php7.2
|
||||
depends_on: [ phpcs ]
|
||||
depends_on: [ composer ]
|
||||
failure: ignore
|
||||
commands:
|
||||
- echo $(date)
|
||||
- ./libraries/vendor/bin/phpcs --config-set installed_paths ../../joomla/cms-coding-standards/lib,../../joomla/coding-standards/Joomla/ExampleRulesets,../../joomla/coding-standards
|
||||
- ./libraries/vendor/bin/phpcs --config-set colors 1
|
||||
- ./libraries/vendor/bin/phpcs --config-set php_version 70200
|
||||
- ./libraries/vendor/bin/phpcs --report=full --encoding=utf-8 --extensions=php --ignore=libraries/vendor/*,tests/*,build/* -p --standard=libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS .
|
||||
- ./libraries/vendor/bin/phpcs --report=full --encoding=utf-8 --extensions=php --ignore=libraries/vendor/*,tests/*,build/*,node_modules/*,media/* -p --standard=libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS .
|
||||
- echo $(date)
|
||||
|
||||
- name: npm
|
||||
|
@ -205,6 +197,6 @@ services:
|
|||
|
||||
---
|
||||
kind: signature
|
||||
hmac: f2199008e0ddb27a8ec0e09ba1664580419939ae7fb5a7cb082181fc2b83af90
|
||||
hmac: ef1c05e085f4ebed5febfa696b2b0dfb60afe24397859138a22d1ba146f98d8a
|
||||
|
||||
...
|
||||
|
|
|
@ -11,8 +11,10 @@ namespace Joomla\Component\Installer\Administrator\View\Manage;
|
|||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\Pagination\Pagination;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;
|
||||
|
||||
|
@ -23,10 +25,25 @@ use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as Installe
|
|||
*/
|
||||
class HtmlView extends InstallerViewDefault
|
||||
{
|
||||
/**
|
||||
* List of updatesites
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $items;
|
||||
|
||||
/**
|
||||
* Pagination object
|
||||
*
|
||||
* @var Pagination
|
||||
*/
|
||||
protected $pagination;
|
||||
|
||||
/**
|
||||
* Form object
|
||||
*
|
||||
* @var Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,8 +11,10 @@ namespace Joomla\Component\Installer\Administrator\View\Updatesites;
|
|||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\Pagination\Pagination;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;
|
||||
|
||||
|
@ -25,10 +27,25 @@ use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as Installe
|
|||
*/
|
||||
class HtmlView extends InstallerViewDefault
|
||||
{
|
||||
/**
|
||||
* List of updatesites
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $items;
|
||||
|
||||
/**
|
||||
* Pagination object
|
||||
*
|
||||
* @var Pagination
|
||||
*/
|
||||
protected $pagination;
|
||||
|
||||
/**
|
||||
* Form object
|
||||
*
|
||||
* @var Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,11 @@ use Joomla\CMS\Helper\ContentHelper;
|
|||
*/
|
||||
class NewsfeedsHelper extends ContentHelper
|
||||
{
|
||||
/**
|
||||
* Name of the extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $extension = 'com_newsfeeds';
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,11 @@ use Joomla\Registry\Registry;
|
|||
*/
|
||||
class RedirectHelper
|
||||
{
|
||||
/**
|
||||
* Extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $extension = 'com_redirect';
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<arg value="--encoding=utf-8" />
|
||||
<arg value="-p" />
|
||||
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
|
||||
<arg value="--standard=${basedir}/build/phpcs/Joomla" />
|
||||
<arg value="--standard=${basedir}/libraries/vendor/joomla/cms-coding-standards/lib/Joomla-CMS" />
|
||||
<arg path="${source}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Ensures that new classes are instantiated without brackets if they do not
|
||||
* have any parameters.
|
||||
*
|
||||
* @category Classes
|
||||
* @package Joomla.CodeSniffer
|
||||
* @author Nikolai Plath
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensures that new classes are instantiated without brackets if they do not
|
||||
* have any parameters.
|
||||
*
|
||||
* @category Classes
|
||||
* @package Joomla.CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Classes_InstantiateNewClassesSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
/**
|
||||
* Registers the token types that this sniff wishes to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_NEW);
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Process the tokens that this sniff is listening for.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$running = true;
|
||||
$valid = false;
|
||||
$started = false;
|
||||
|
||||
$cnt = $stackPtr + 1;
|
||||
|
||||
do
|
||||
{
|
||||
if( ! isset($tokens[$cnt]))
|
||||
{
|
||||
$running = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($tokens[$cnt]['code'])
|
||||
{
|
||||
case T_SEMICOLON:
|
||||
case T_COMMA :
|
||||
$valid = true;
|
||||
$running = false;
|
||||
break;
|
||||
|
||||
case T_OPEN_PARENTHESIS :
|
||||
$started = true;
|
||||
break;
|
||||
|
||||
case T_VARIABLE :
|
||||
case T_STRING :
|
||||
case T_LNUMBER :
|
||||
case T_CONSTANT_ENCAPSED_STRING :
|
||||
case T_DOUBLE_QUOTED_STRING :
|
||||
case T_ARRAY :
|
||||
case T_TRUE :
|
||||
case T_FALSE :
|
||||
case T_NULL :
|
||||
if($started === true)
|
||||
{
|
||||
$valid = true;
|
||||
$running = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case T_CLOSE_PARENTHESIS :
|
||||
if($started === false)
|
||||
{
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
$running = false;
|
||||
break;
|
||||
|
||||
case T_WHITESPACE :
|
||||
break;
|
||||
}//switch
|
||||
|
||||
$cnt ++;
|
||||
}
|
||||
}
|
||||
while ($running === true);
|
||||
|
||||
if($valid === false)
|
||||
{
|
||||
$error = 'Instanciating new classes without parameters does not require brackets.';
|
||||
$phpcsFile->addError($error, $stackPtr, 'New class');
|
||||
}
|
||||
}//function
|
||||
}//class
|
|
@ -1,93 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Verifies that class members have scope modifiers.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: MemberVarScopeSniff.php 8 2010-11-06 00:40:23Z elkuku $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if(class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false)
|
||||
{
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that class members have scope modifiers.
|
||||
*
|
||||
* Example:
|
||||
* class Foo
|
||||
* {
|
||||
* <b class="good">private $foo</b>
|
||||
* <b class="bad">var $foo</b>
|
||||
* }
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC1
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Classes_MemberVarScopeSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
|
||||
{
|
||||
/**
|
||||
* Processes the function tokens within the class.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
|
||||
|
||||
if(($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']))
|
||||
{
|
||||
$error = sprintf('Scope modifier not specified for member variable "%s"'
|
||||
, $tokens[$stackPtr]['content']);
|
||||
|
||||
$phpcsFile->addWarning($error, $stackPtr, 'Missing');
|
||||
}
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes normal variables.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We don't care about normal variables.
|
||||
return;
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes variables in double quoted strings.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We don't care about normal variables.
|
||||
return;
|
||||
}//function
|
||||
}//class
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Verifies that class members have scope modifiers.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: MethodScopeSniff.php 8 2010-11-06 00:40:23Z elkuku $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if(class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false)
|
||||
{
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that class members have scope modifiers.
|
||||
*
|
||||
* Example:
|
||||
* class Foo
|
||||
* {
|
||||
* <b class="good">public function foo()</b>
|
||||
* {
|
||||
* }
|
||||
*
|
||||
* <b class="bad">function foo()</b>
|
||||
* {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC1
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Classes_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
|
||||
{
|
||||
/**
|
||||
* Constructs a Squiz_Sniffs_Scope_MethodScopeSniff.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION));
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes the function tokens within the class.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
* @param integer $currScope The current scope opener token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$methodName = $phpcsFile->getDeclarationName($stackPtr);
|
||||
|
||||
if($methodName === null)
|
||||
{
|
||||
// Ignore closures.
|
||||
return;
|
||||
}
|
||||
|
||||
$modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
|
||||
|
||||
if(($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']))
|
||||
{
|
||||
$error = sprintf('No scope modifier specified for function "%s"'
|
||||
, $methodName);
|
||||
|
||||
$phpcsFile->addWarning($error, $stackPtr, 'Missing');
|
||||
}
|
||||
}//function
|
||||
}//class
|
|
@ -1,299 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Parses and verifies the doc comments for classes.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: ClassCommentSniff.php 301632 2010-07-28 01:57:56Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
require_once 'FileCommentSniff.php';
|
||||
|
||||
if (class_exists('Joomla_Sniffs_Commenting_FileCommentSniff', true) === false) {
|
||||
$error = 'Class Joomla_Sniffs_Commenting_FileCommentSniff not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and verifies the doc comments for classes.
|
||||
*
|
||||
* Verifies that :
|
||||
* <ul>
|
||||
* <li>A doc comment exists.</li>
|
||||
* <li>There is a blank newline after the short description.</li>
|
||||
* <li>There is a blank newline between the long and short description.</li>
|
||||
* <li>There is a blank newline between the long description and tags.</li>
|
||||
* <li>Check the order of the tags.</li>
|
||||
* <li>Check the indentation of each tag.</li>
|
||||
* <li>Check required and optional tags and the format of their content.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Commenting_ClassCommentSniff extends Joomla_Sniffs_Commenting_FileCommentSniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Tags in correct order and related info.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tags = array(
|
||||
'version' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'is first',
|
||||
),
|
||||
'category' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @version (if used)',
|
||||
),
|
||||
'package' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @category (if used)',
|
||||
),
|
||||
'subpackage' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @package',
|
||||
),
|
||||
'author' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'is first',
|
||||
),
|
||||
'copyright' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @author (if used) or @subpackage (if used) or @package',
|
||||
),
|
||||
'license' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @copyright (if used)',
|
||||
),
|
||||
'link' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @version (if used)',
|
||||
),
|
||||
'see' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @link (if used)',
|
||||
),
|
||||
'since' => array(
|
||||
'required' => true,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @see (if used) or @link (if used)',
|
||||
),
|
||||
'deprecated' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @since (if used) or @see (if used) or @link (if used)',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_CLASS,
|
||||
T_INTERFACE,
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$this->currentFile = $phpcsFile;
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$type = strtolower($tokens[$stackPtr]['content']);
|
||||
$errorData = array($type);
|
||||
$find = array(
|
||||
T_ABSTRACT,
|
||||
T_WHITESPACE,
|
||||
T_FINAL,
|
||||
);
|
||||
|
||||
// Extract the class comment docblock.
|
||||
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
|
||||
|
||||
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_COMMENT) {
|
||||
$error = 'You must use "/**" style comments for a %s comment';
|
||||
$phpcsFile->addError($error, $stackPtr, 'WrongStyle', $errorData);
|
||||
return;
|
||||
} else if ($commentEnd === false
|
||||
|| $tokens[$commentEnd]['code'] !== T_DOC_COMMENT
|
||||
) {
|
||||
$phpcsFile->addError('Missing %s doc comment', $stackPtr, 'Missing', $errorData);
|
||||
return;
|
||||
}
|
||||
|
||||
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
|
||||
$commentNext = $phpcsFile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
|
||||
|
||||
// Distinguish file and class comment.
|
||||
$prevClassToken = $phpcsFile->findPrevious(T_CLASS, ($stackPtr - 1));
|
||||
if ($prevClassToken === false) {
|
||||
// This is the first class token in this file, need extra checks.
|
||||
$prevNonComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true);
|
||||
if ($prevNonComment !== false) {
|
||||
$prevComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1));
|
||||
if ($prevComment === false) {
|
||||
// There is only 1 doc comment between open tag and class token.
|
||||
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
|
||||
if ($newlineToken !== false) {
|
||||
$newlineToken = $phpcsFile->findNext(
|
||||
T_WHITESPACE,
|
||||
($newlineToken + 1),
|
||||
$stackPtr,
|
||||
false,
|
||||
$phpcsFile->eolChar
|
||||
);
|
||||
|
||||
if ($newlineToken !== false) {
|
||||
// Blank line between the class and the doc block.
|
||||
// The doc block is most likely a file comment.
|
||||
$error = 'Missing %s doc comment';
|
||||
$phpcsFile->addError($error, ($stackPtr + 1), 'Missing', $errorData);
|
||||
return;
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
$comment = $phpcsFile->getTokensAsString(
|
||||
$commentStart,
|
||||
($commentEnd - $commentStart + 1)
|
||||
);
|
||||
|
||||
// Parse the class comment.docblock.
|
||||
try {
|
||||
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
|
||||
$this->commentParser->parse();
|
||||
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
|
||||
$line = ($e->getLineWithinComment() + $commentStart);
|
||||
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
|
||||
return;
|
||||
}
|
||||
|
||||
$comment = $this->commentParser->getComment();
|
||||
if (is_null($comment) === true) {
|
||||
$error = 'Doc comment is empty for %s';
|
||||
$phpcsFile->addError($error, $commentStart, 'Empty', $errorData);
|
||||
return;
|
||||
}
|
||||
|
||||
// No extra newline before short description.
|
||||
$short = $comment->getShortComment();
|
||||
$newlineCount = 0;
|
||||
$newlineSpan = strspn($short, $phpcsFile->eolChar);
|
||||
if ($short !== '' && $newlineSpan > 0) {
|
||||
$error = 'Extra newline(s) found before %s comment short description';
|
||||
$phpcsFile->addError($error, ($commentStart + 1), 'SpacingBeforeShort', $errorData);
|
||||
}
|
||||
|
||||
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
|
||||
|
||||
// Exactly one blank line between short and long description.
|
||||
$long = $comment->getLongComment();
|
||||
if (empty($long) === false) {
|
||||
$between = $comment->getWhiteSpaceBetween();
|
||||
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
|
||||
if ($newlineBetween !== 2) {
|
||||
$error = 'There must be exactly one blank line between descriptions in %s comments';
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1), 'SpacingAfterShort', $errorData);
|
||||
}
|
||||
|
||||
$newlineCount += $newlineBetween;
|
||||
}
|
||||
|
||||
// Exactly one blank line before tags.
|
||||
$tags = $this->commentParser->getTagOrders();
|
||||
if (count($tags) > 1) {
|
||||
$newlineSpan = $comment->getNewlineAfter();
|
||||
if ($newlineSpan !== 2) {
|
||||
$error = 'There must be exactly one blank line before the tags in %s comments';
|
||||
if ($long !== '') {
|
||||
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
|
||||
}
|
||||
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount), 'SpacingBeforeTags', $errorData);
|
||||
$short = rtrim($short, $phpcsFile->eolChar.' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Check each tag.
|
||||
$this->processTags($commentStart, $commentEnd);
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Process the version tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVersion($errorPos)
|
||||
{
|
||||
$version = $this->commentParser->getVersion();
|
||||
if ($version !== null) {
|
||||
$content = $version->getContent();
|
||||
$matches = array();
|
||||
if (empty($content) === true) {
|
||||
$error = 'Content missing for @version tag in doc comment';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyVersion');
|
||||
} else if ((strstr($content, 'Release:') === false)) {
|
||||
$error = 'Invalid version "%s" in doc comment; consider "Release: <package_version>" instead';
|
||||
$data = array($content);
|
||||
$this->currentFile->addWarning($error, $errorPos, 'InvalidVersion', $data);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processVersion()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,803 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Parses and verifies the doc comments for files.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: FileCommentSniff.php 301632 2010-07-28 01:57:56Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and verifies the doc comments for files.
|
||||
*
|
||||
* Verifies that :
|
||||
* <ul>
|
||||
* <li>A doc comment exists.</li>
|
||||
* <li>There is a blank newline after the short description.</li>
|
||||
* <li>There is a blank newline between the long and short description.</li>
|
||||
* <li>There is a blank newline between the long description and tags.</li>
|
||||
* <li>A PHP version is specified.</li>
|
||||
* <li>Check the order of the tags.</li>
|
||||
* <li>Check the indentation of each tag.</li>
|
||||
* <li>Check required and optional tags and the format of their content.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
class Joomla_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* The header comment parser for the current file.
|
||||
*
|
||||
* @var PHP_CodeSniffer_Comment_Parser_ClassCommentParser
|
||||
*/
|
||||
protected $commentParser = null;
|
||||
|
||||
/**
|
||||
* The current PHP_CodeSniffer_File object we are processing.
|
||||
*
|
||||
* @var PHP_CodeSniffer_File
|
||||
*/
|
||||
protected $currentFile = null;
|
||||
|
||||
/**
|
||||
* Tags in correct order and related info.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tags = array(
|
||||
'version' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must be first',
|
||||
),
|
||||
'category' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'precedes @package',
|
||||
),
|
||||
'package' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follows @category (if used)',
|
||||
),
|
||||
'subpackage' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @package',
|
||||
),
|
||||
'author' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @subpackage (if used) or @package',
|
||||
),
|
||||
'copyright' => array(
|
||||
'required' => true,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @author (if used), @subpackage (if used) or @package',
|
||||
),
|
||||
'license' => array(
|
||||
'required' => true,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @copyright',
|
||||
),
|
||||
'link' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @license',
|
||||
),
|
||||
'see' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => true,
|
||||
'order_text' => 'must follow @link (if used) or @license',
|
||||
),
|
||||
'since' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follows @see (if used), @link (if used) or @license',
|
||||
),
|
||||
'deprecated' => array(
|
||||
'required' => false,
|
||||
'allow_multiple' => false,
|
||||
'order_text' => 'must follow @since (if used), @see (if used), @link (if used) or @license',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OPEN_TAG);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$this->currentFile = $phpcsFile;
|
||||
|
||||
// We are only interested if this is the first open tag.
|
||||
if ($stackPtr !== 0) {
|
||||
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Find the next non whitespace token.
|
||||
$commentStart
|
||||
= $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
|
||||
|
||||
// Allow declare() statements at the top of the file.
|
||||
if ($tokens[$commentStart]['code'] === T_DECLARE) {
|
||||
$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($commentStart + 1));
|
||||
$commentStart
|
||||
= $phpcsFile->findNext(T_WHITESPACE, ($semicolon + 1), null, true);
|
||||
}
|
||||
|
||||
// Ignore vim header.
|
||||
if ($tokens[$commentStart]['code'] === T_COMMENT) {
|
||||
if (strstr($tokens[$commentStart]['content'], 'vim:') !== false) {
|
||||
$commentStart = $phpcsFile->findNext(
|
||||
T_WHITESPACE,
|
||||
($commentStart + 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$errorToken = ($stackPtr + 1);
|
||||
if (isset($tokens[$errorToken]) === false) {
|
||||
$errorToken--;
|
||||
}
|
||||
|
||||
if ($tokens[$commentStart]['code'] === T_CLOSE_TAG) {
|
||||
// We are only interested if this is the first open tag.
|
||||
return;
|
||||
} else if ($tokens[$commentStart]['code'] === T_COMMENT) {
|
||||
$error = 'You must use "/**" style comments for a file comment';
|
||||
$phpcsFile->addError($error, $errorToken, 'WrongStyle');
|
||||
return;
|
||||
} else if ($commentStart === false
|
||||
|| $tokens[$commentStart]['code'] !== T_DOC_COMMENT
|
||||
) {
|
||||
$phpcsFile->addError('Missing file doc comment', $errorToken, 'Missing');
|
||||
return;
|
||||
} else {
|
||||
|
||||
// Extract the header comment docblock.
|
||||
$commentEnd = $phpcsFile->findNext(
|
||||
T_DOC_COMMENT,
|
||||
($commentStart + 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$commentEnd--;
|
||||
|
||||
// Check if there is only 1 doc comment between the
|
||||
// open tag and class token.
|
||||
$nextToken = array(
|
||||
T_ABSTRACT,
|
||||
T_CLASS,
|
||||
T_FUNCTION,
|
||||
T_DOC_COMMENT,
|
||||
);
|
||||
|
||||
$commentNext = $phpcsFile->findNext($nextToken, ($commentEnd + 1));
|
||||
if ($commentNext !== false
|
||||
&& $tokens[$commentNext]['code'] !== T_DOC_COMMENT
|
||||
) {
|
||||
// Found a class token right after comment doc block.
|
||||
$newlineToken = $phpcsFile->findNext(
|
||||
T_WHITESPACE,
|
||||
($commentEnd + 1),
|
||||
$commentNext,
|
||||
false,
|
||||
$phpcsFile->eolChar
|
||||
);
|
||||
|
||||
if ($newlineToken !== false) {
|
||||
$newlineToken = $phpcsFile->findNext(
|
||||
T_WHITESPACE,
|
||||
($newlineToken + 1),
|
||||
$commentNext,
|
||||
false,
|
||||
$phpcsFile->eolChar
|
||||
);
|
||||
|
||||
if ($newlineToken === false) {
|
||||
// No blank line between the class token and the doc block.
|
||||
// The doc block is most likely a class comment.
|
||||
$error = 'Missing file doc comment';
|
||||
$phpcsFile->addError($error, $errorToken, 'Missing');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
$comment = $phpcsFile->getTokensAsString(
|
||||
$commentStart,
|
||||
($commentEnd - $commentStart + 1)
|
||||
);
|
||||
|
||||
// Parse the header comment docblock.
|
||||
try {
|
||||
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
|
||||
$this->commentParser->parse();
|
||||
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
|
||||
$line = ($e->getLineWithinComment() + $commentStart);
|
||||
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
|
||||
return;
|
||||
}
|
||||
|
||||
$comment = $this->commentParser->getComment();
|
||||
if (is_null($comment) === true) {
|
||||
$error = 'File doc comment is empty';
|
||||
$phpcsFile->addError($error, $commentStart, 'Empty');
|
||||
return;
|
||||
}
|
||||
|
||||
// No extra newline before short description.
|
||||
$short = $comment->getShortComment();
|
||||
$newlineCount = 0;
|
||||
$newlineSpan = strspn($short, $phpcsFile->eolChar);
|
||||
if ($short !== '' && $newlineSpan > 0) {
|
||||
$error = 'Extra newline(s) found before file comment short description';
|
||||
$phpcsFile->addError($error, ($commentStart + 1), 'SpacingBefore');
|
||||
}
|
||||
|
||||
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
|
||||
|
||||
// Exactly one blank line between short and long description.
|
||||
$long = $comment->getLongComment();
|
||||
if (empty($long) === false) {
|
||||
$between = $comment->getWhiteSpaceBetween();
|
||||
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
|
||||
if ($newlineBetween !== 2) {
|
||||
$error = 'There must be exactly one blank line between descriptions in file comment';
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1), 'DescriptionSpacing');
|
||||
}
|
||||
|
||||
$newlineCount += $newlineBetween;
|
||||
}
|
||||
|
||||
// Exactly one blank line before tags if short description is present.
|
||||
$tags = $this->commentParser->getTagOrders();
|
||||
if (count($tags) > 1 && $short !== '' && $newlineSpan > 0) {
|
||||
$newlineSpan = $comment->getNewlineAfter();
|
||||
if ($newlineSpan !== 2) {
|
||||
$error = 'There must be exactly one blank line before the tags in file comment';
|
||||
if ($long !== '') {
|
||||
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
|
||||
}
|
||||
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount), 'SpacingBeforeTags');
|
||||
$short = rtrim($short, $phpcsFile->eolChar.' ');
|
||||
}
|
||||
}
|
||||
|
||||
// // Check the PHP Version.
|
||||
// $this->processPHPVersion($commentStart, $commentEnd, $long);
|
||||
|
||||
// Check each tag.
|
||||
$this->processTags($commentStart, $commentEnd);
|
||||
}//end if
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
// /**
|
||||
// * Check that the PHP version is specified.
|
||||
// *
|
||||
// * @param int $commentStart Position in the stack where the comment started.
|
||||
// * @param int $commentEnd Position in the stack where the comment ended.
|
||||
// * @param string $commentText The text of the function comment.
|
||||
// *
|
||||
// * @return void
|
||||
// */
|
||||
// protected function processPHPVersion($commentStart, $commentEnd, $commentText)
|
||||
// {
|
||||
// if (strstr(strtolower($commentText), 'php version') === false) {
|
||||
// $error = 'PHP version not specified';
|
||||
// $this->currentFile->addWarning($error, $commentEnd, 'MissingVersion');
|
||||
// }
|
||||
//
|
||||
// }//end processPHPVersion()
|
||||
|
||||
|
||||
/**
|
||||
* Processes each required or optional tag.
|
||||
*
|
||||
* @param int $commentStart Position in the stack where the comment started.
|
||||
* @param int $commentEnd Position in the stack where the comment ended.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processTags($commentStart, $commentEnd)
|
||||
{
|
||||
$docBlock = (get_class($this) === 'Joomla_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
|
||||
$foundTags = $this->commentParser->getTagOrders();
|
||||
$orderIndex = 0;
|
||||
$indentation = array();
|
||||
$longestTag = 0;
|
||||
$errorPos = 0;
|
||||
|
||||
foreach ($this->tags as $tag => $info) {
|
||||
|
||||
// Required tag missing.
|
||||
if ($info['required'] === true && in_array($tag, $foundTags) === false) {
|
||||
// We don't use package tags in namespaced code or the bootstrap file
|
||||
if ($tag == 'package') {
|
||||
// this should return 0 if there is no namespaced tokens
|
||||
$namespaced = $this->currentFile->findNext(T_NAMESPACE, 0);
|
||||
|
||||
if ($namespaced !== 0 || strpos($this->currentFile->getFilename(), '/libraries/bootstrap.php')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$error = 'Missing @%s tag in %s comment';
|
||||
$data = array(
|
||||
$tag,
|
||||
$docBlock,
|
||||
);
|
||||
$this->currentFile->addError($error, $commentEnd, 'MissingTag', $data);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the line number for current tag.
|
||||
$tagName = ucfirst($tag);
|
||||
if ($info['allow_multiple'] === true) {
|
||||
$tagName .= 's';
|
||||
}
|
||||
|
||||
$getMethod = 'get'.$tagName;
|
||||
$tagElement = $this->commentParser->$getMethod();
|
||||
if (is_null($tagElement) === true || empty($tagElement) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$errorPos = $commentStart;
|
||||
if (is_array($tagElement) === false) {
|
||||
$errorPos = ($commentStart + $tagElement->getLine());
|
||||
}
|
||||
|
||||
// Get the tag order.
|
||||
$foundIndexes = array_keys($foundTags, $tag);
|
||||
|
||||
if (count($foundIndexes) > 1) {
|
||||
// Multiple occurance not allowed.
|
||||
if ($info['allow_multiple'] === false) {
|
||||
$error = 'Only 1 @%s tag is allowed in a %s comment';
|
||||
$data = array(
|
||||
$tag,
|
||||
$docBlock,
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'DuplicateTag', $data);
|
||||
} else {
|
||||
// Make sure same tags are grouped together.
|
||||
$i = 0;
|
||||
$count = $foundIndexes[0];
|
||||
foreach ($foundIndexes as $index) {
|
||||
if ($index !== $count) {
|
||||
$errorPosIndex
|
||||
= ($errorPos + $tagElement[$i]->getLine());
|
||||
$error = '@%s tags must be grouped together';
|
||||
$data = array($tag);
|
||||
$this->currentFile->addError($error, $errorPosIndex, 'TagsNotGrouped', $data);
|
||||
}
|
||||
|
||||
$i++;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
// Check tag order.
|
||||
if ($foundIndexes[0] > $orderIndex) {
|
||||
$orderIndex = $foundIndexes[0];
|
||||
} else {
|
||||
if (is_array($tagElement) === true && empty($tagElement) === false) {
|
||||
$errorPos += $tagElement[0]->getLine();
|
||||
}
|
||||
|
||||
$error = 'The @%s tag is in the wrong order; the tag %s';
|
||||
$data = array(
|
||||
$tag,
|
||||
$info['order_text'],
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'WrongTagOrder', $data);
|
||||
}
|
||||
|
||||
// Store the indentation for checking.
|
||||
$len = strlen($tag);
|
||||
if ($len > $longestTag) {
|
||||
$longestTag = $len;
|
||||
}
|
||||
|
||||
if (is_array($tagElement) === true) {
|
||||
foreach ($tagElement as $key => $element) {
|
||||
$indentation[] = array(
|
||||
'tag' => $tag,
|
||||
'space' => $this->getIndentation($tag, $element),
|
||||
'line' => $element->getLine(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$indentation[] = array(
|
||||
'tag' => $tag,
|
||||
'space' => $this->getIndentation($tag, $tagElement),
|
||||
);
|
||||
}
|
||||
|
||||
$method = 'process'.$tagName;
|
||||
if (method_exists($this, $method) === true) {
|
||||
// Process each tag if a method is defined.
|
||||
call_user_func(array($this, $method), $errorPos);
|
||||
} else {
|
||||
if (is_array($tagElement) === true) {
|
||||
foreach ($tagElement as $key => $element) {
|
||||
$element->process(
|
||||
$this->currentFile,
|
||||
$commentStart,
|
||||
$docBlock
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$tagElement->process(
|
||||
$this->currentFile,
|
||||
$commentStart,
|
||||
$docBlock
|
||||
);
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
foreach ($indentation as $indentInfo) {
|
||||
if ($indentInfo['space'] !== 0
|
||||
// Joomla change: allow for 2 space gap.
|
||||
&& $indentInfo['space'] !== ($longestTag + 2)
|
||||
) {
|
||||
$expected = (($longestTag - strlen($indentInfo['tag'])) + 2);
|
||||
$space = ($indentInfo['space'] - strlen($indentInfo['tag']));
|
||||
$error = '@%s tag comment indented incorrectly; expected %s spaces but found %s';
|
||||
$data = array(
|
||||
$indentInfo['tag'],
|
||||
$expected,
|
||||
$space,
|
||||
);
|
||||
|
||||
$getTagMethod = 'get'.ucfirst($indentInfo['tag']);
|
||||
|
||||
if ($this->tags[$indentInfo['tag']]['allow_multiple'] === true) {
|
||||
$line = $indentInfo['line'];
|
||||
} else {
|
||||
$tagElem = $this->commentParser->$getTagMethod();
|
||||
$line = $tagElem->getLine();
|
||||
}
|
||||
|
||||
$this->currentFile->addError($error, ($commentStart + $line), 'TagIndent', $data);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processTags()
|
||||
|
||||
|
||||
/**
|
||||
* Get the indentation information of each tag.
|
||||
*
|
||||
* @param string $tagName The name of the
|
||||
* doc comment
|
||||
* element.
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $tagElement The doc comment
|
||||
* element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getIndentation($tagName, $tagElement)
|
||||
{
|
||||
if ($tagElement instanceof PHP_CodeSniffer_CommentParser_SingleElement) {
|
||||
if ($tagElement->getContent() !== '') {
|
||||
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeContent(), ' '));
|
||||
}
|
||||
} else if ($tagElement instanceof PHP_CodeSniffer_CommentParser_PairElement) {
|
||||
if ($tagElement->getValue() !== '') {
|
||||
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeValue(), ' '));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}//end getIndentation()
|
||||
|
||||
|
||||
/**
|
||||
* Process the category tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processCategory($errorPos)
|
||||
{
|
||||
$category = $this->commentParser->getCategory();
|
||||
if ($category !== null) {
|
||||
$content = $category->getContent();
|
||||
if ($content !== '') {
|
||||
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
|
||||
// $newContent = str_replace(' ', '_', $content);
|
||||
// $nameBits = explode('_', $newContent);
|
||||
// $firstBit = array_shift($nameBits);
|
||||
// $newName = ucfirst($firstBit).'_';
|
||||
// foreach ($nameBits as $bit) {
|
||||
// $newName .= ucfirst($bit).'_';
|
||||
// }
|
||||
//
|
||||
// $error = 'Category name "%s" is not valid; consider "%s" instead';
|
||||
// $validName = trim($newName, '_');
|
||||
// $data = array(
|
||||
// $content,
|
||||
// $validName,
|
||||
// );
|
||||
// $this->currentFile->addError($error, $errorPos, 'InvalidCategory', $data);
|
||||
}
|
||||
} else {
|
||||
$error = '@category tag must contain a name';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyCategory');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processCategory()
|
||||
|
||||
|
||||
/**
|
||||
* Process the package tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processPackage($errorPos)
|
||||
{
|
||||
$package = $this->commentParser->getPackage();
|
||||
if ($package !== null) {
|
||||
$content = $package->getContent();
|
||||
if ($content !== '') {
|
||||
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
|
||||
$newContent = str_replace(' ', '_', $content);
|
||||
$nameBits = explode('_', $newContent);
|
||||
$firstBit = array_shift($nameBits);
|
||||
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
|
||||
foreach ($nameBits as $bit) {
|
||||
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
|
||||
}
|
||||
|
||||
$error = 'Package name "%s" is not valid; consider "%s" instead';
|
||||
$validName = trim($newName, '_');
|
||||
$data = array(
|
||||
$content,
|
||||
$validName,
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'InvalidPackage', $data);
|
||||
}
|
||||
} else {
|
||||
$error = '@package tag must contain a name';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyPackage');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processPackage()
|
||||
|
||||
|
||||
/**
|
||||
* Process the subpackage tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processSubpackage($errorPos)
|
||||
{
|
||||
$package = $this->commentParser->getSubpackage();
|
||||
if ($package !== null) {
|
||||
$content = $package->getContent();
|
||||
if ($content !== '') {
|
||||
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
|
||||
// $newContent = str_replace(' ', '_', $content);
|
||||
// $nameBits = explode('_', $newContent);
|
||||
// $firstBit = array_shift($nameBits);
|
||||
// $newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
|
||||
// foreach ($nameBits as $bit) {
|
||||
// $newName .= strtoupper($bit{0}).substr($bit, 1).'_';
|
||||
// }
|
||||
//
|
||||
// $error = 'Subpackage name "%s" is not valid; consider "%s" instead';
|
||||
// $validName = trim($newName, '_');
|
||||
// $data = array(
|
||||
// $content,
|
||||
// $validName,
|
||||
// );
|
||||
// $this->currentFile->addError($error, $errorPos, 'InvalidSubpackage', $data);
|
||||
}
|
||||
} else {
|
||||
$error = '@subpackage tag must contain a name';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptySubpackage');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSubpackage()
|
||||
|
||||
|
||||
/**
|
||||
* Process the author tag(s) that this header comment has.
|
||||
*
|
||||
* This function is different from other _process functions
|
||||
* as $authors is an array of SingleElements, so we work out
|
||||
* the errorPos for each element separately
|
||||
*
|
||||
* @param int $commentStart The position in the stack where
|
||||
* the comment started.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processAuthors($commentStart)
|
||||
{
|
||||
$authors = $this->commentParser->getAuthors();
|
||||
// Report missing return.
|
||||
if (empty($authors) === false) {
|
||||
foreach ($authors as $author) {
|
||||
$errorPos = ($commentStart + $author->getLine());
|
||||
$content = $author->getContent();
|
||||
if ($content !== '') {
|
||||
$local = '\da-zA-Z-_+';
|
||||
// Dot character cannot be the first or last character
|
||||
// in the local-part.
|
||||
$localMiddle = $local.'.\w';
|
||||
if (preg_match('/^([^<]*)\s+<(['.$local.']['.$localMiddle.']*['.$local.']@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
|
||||
$error = 'Content of the @author tag must be in the form "Display Name <username@example.com>"';
|
||||
$this->currentFile->addError($error, $errorPos, 'InvalidAuthors');
|
||||
}
|
||||
} else {
|
||||
$error = 'Content missing for @author tag in %s comment';
|
||||
$docBlock = (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
|
||||
$data = array($docBlock);
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyAuthors', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//end processAuthors()
|
||||
|
||||
|
||||
/**
|
||||
* Process the copyright tags.
|
||||
*
|
||||
* @param int $commentStart The position in the stack where
|
||||
* the comment started.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processCopyrights($commentStart)
|
||||
{
|
||||
$copyrights = $this->commentParser->getCopyrights();
|
||||
foreach ($copyrights as $copyright) {
|
||||
$errorPos = ($commentStart + $copyright->getLine());
|
||||
$content = $copyright->getContent();
|
||||
if ($content !== '') {
|
||||
$matches = array();
|
||||
if (preg_match('/^.*?([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
|
||||
// Check earliest-latest year order.
|
||||
if ($matches[3] !== '') {
|
||||
if ($matches[3] !== '-') {
|
||||
$error = 'A hyphen must be used between the earliest and latest year';
|
||||
$this->currentFile->addError($error, $errorPos, 'CopyrightHyphen');
|
||||
}
|
||||
|
||||
if ($matches[4] !== '' && $matches[4] < $matches[1]) {
|
||||
$error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead";
|
||||
$this->currentFile->addWarning($error, $errorPos, 'InvalidCopyright');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = '@copyright tag must contain a year and the name of the copyright holder';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyCopyright');
|
||||
}
|
||||
} else {
|
||||
$error = '@copyright tag must contain a year and the name of the copyright holder';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyCopyright');
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
}//end processCopyrights()
|
||||
|
||||
|
||||
/**
|
||||
* Process the license tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processLicense($errorPos)
|
||||
{
|
||||
$license = $this->commentParser->getLicense();
|
||||
if ($license !== null) {
|
||||
$value = $license->getValue();
|
||||
$comment = $license->getComment();
|
||||
if ($value === '' || $comment === '') {
|
||||
$error = '@license tag must contain a URL and a license name';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyLicense');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processLicense()
|
||||
|
||||
|
||||
/**
|
||||
* Process the version tag.
|
||||
*
|
||||
* @param int $errorPos The line number where the error occurs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVersion($errorPos)
|
||||
{
|
||||
$version = $this->commentParser->getVersion();
|
||||
if ($version !== null) {
|
||||
$content = $version->getContent();
|
||||
$matches = array();
|
||||
if (empty($content) === true) {
|
||||
$error = 'Content missing for @version tag in file comment';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyVersion');
|
||||
} else if (strstr($content, 'CVS:') === false
|
||||
&& strstr($content, 'SVN:') === false
|
||||
&& strstr($content, 'Id:') === false
|
||||
) {
|
||||
$error = 'Invalid version "%s" in file comment; consider "CVS: <cvs_id>" or "SVN: <svn_id>" instead';
|
||||
$data = array($content);
|
||||
$this->currentFile->addWarning($error, $errorPos, 'InvalidVersion', $data);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processVersion()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,508 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Parses and verifies the doc comments for functions.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: FunctionCommentSniff.php 301632 2010-07-28 01:57:56Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_FunctionCommentParser', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_FunctionCommentParser not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and verifies the doc comments for functions.
|
||||
*
|
||||
* Verifies that :
|
||||
* <ul>
|
||||
* <li>A comment exists</li>
|
||||
* <li>There is a blank newline after the short description.</li>
|
||||
* <li>There is a blank newline between the long and short description.</li>
|
||||
* <li>There is a blank newline between the long description and tags.</li>
|
||||
* <li>Parameter names represent those in the method.</li>
|
||||
* <li>Parameter comments are in the correct order</li>
|
||||
* <li>Parameter comments are complete</li>
|
||||
* <li>A space is present before the first and after the last parameter</li>
|
||||
* <li>A return type exists</li>
|
||||
* <li>There must be one blank line between body and headline comments.</li>
|
||||
* <li>Any throw tag must have an exception class.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the method that we are currently processing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_methodName = '';
|
||||
|
||||
/**
|
||||
* The position in the stack where the fucntion token was found.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_functionToken = null;
|
||||
|
||||
/**
|
||||
* The position in the stack where the class token was found.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_classToken = null;
|
||||
|
||||
/**
|
||||
* The function comment parser for the current method.
|
||||
*
|
||||
* @var PHP_CodeSniffer_Comment_Parser_FunctionCommentParser
|
||||
*/
|
||||
protected $commentParser = null;
|
||||
|
||||
/**
|
||||
* The current PHP_CodeSniffer_File object we are processing.
|
||||
*
|
||||
* @var PHP_CodeSniffer_File
|
||||
*/
|
||||
protected $currentFile = null;
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_FUNCTION);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$find = array(
|
||||
T_COMMENT,
|
||||
T_DOC_COMMENT,
|
||||
T_CLASS,
|
||||
T_FUNCTION,
|
||||
T_OPEN_TAG,
|
||||
);
|
||||
|
||||
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1));
|
||||
|
||||
if ($commentEnd === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->currentFile = $phpcsFile;
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// If the token that we found was a class or a function, then this
|
||||
// function has no doc comment.
|
||||
$code = $tokens[$commentEnd]['code'];
|
||||
|
||||
if ($code === T_COMMENT) {
|
||||
$error = 'You must use "/**" style comments for a function comment';
|
||||
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
|
||||
return;
|
||||
} else if ($code !== T_DOC_COMMENT) {
|
||||
$phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is any code between the function keyword and the doc block
|
||||
// then the doc block is not for us.
|
||||
$ignore = PHP_CodeSniffer_Tokens::$scopeModifiers;
|
||||
$ignore[] = T_STATIC;
|
||||
$ignore[] = T_WHITESPACE;
|
||||
$ignore[] = T_ABSTRACT;
|
||||
$ignore[] = T_FINAL;
|
||||
$prevToken = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
|
||||
if ($prevToken !== $commentEnd) {
|
||||
$phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_functionToken = $stackPtr;
|
||||
|
||||
$this->_classToken = null;
|
||||
foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condition) {
|
||||
if ($condition === T_CLASS || $condition === T_INTERFACE) {
|
||||
$this->_classToken = $condPtr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the first T_OPEN_TAG is right before the comment, it is probably
|
||||
// a file comment.
|
||||
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
|
||||
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
|
||||
if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
|
||||
// Is this the first open tag?
|
||||
if ($stackPtr === 0 || $phpcsFile->findPrevious(T_OPEN_TAG, ($prevToken - 1)) === false) {
|
||||
$phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
|
||||
$this->_methodName = $phpcsFile->getDeclarationName($stackPtr);
|
||||
|
||||
try {
|
||||
$this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
|
||||
$this->commentParser->parse();
|
||||
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
|
||||
$line = ($e->getLineWithinComment() + $commentStart);
|
||||
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
|
||||
return;
|
||||
}
|
||||
|
||||
$comment = $this->commentParser->getComment();
|
||||
if (is_null($comment) === true) {
|
||||
$error = 'Function doc comment is empty';
|
||||
$phpcsFile->addError($error, $commentStart, 'Empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processParams($commentStart);
|
||||
$this->processReturn($commentStart, $commentEnd);
|
||||
$this->processThrows($commentStart);
|
||||
|
||||
// No extra newline before short description.
|
||||
$short = $comment->getShortComment();
|
||||
$newlineCount = 0;
|
||||
$newlineSpan = strspn($short, $phpcsFile->eolChar);
|
||||
if ($short !== '' && $newlineSpan > 0) {
|
||||
$error = 'Extra newline(s) found before function comment short description';
|
||||
$phpcsFile->addError($error, ($commentStart + 1), 'SpacingBeforeShort');
|
||||
}
|
||||
|
||||
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
|
||||
|
||||
// Exactly one blank line between short and long description.
|
||||
$long = $comment->getLongComment();
|
||||
if (empty($long) === false) {
|
||||
$between = $comment->getWhiteSpaceBetween();
|
||||
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
|
||||
if ($newlineBetween !== 2) {
|
||||
$error = 'There must be exactly one blank line between descriptions in function comment';
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1), 'SpacingAfterShort');
|
||||
}
|
||||
|
||||
$newlineCount += $newlineBetween;
|
||||
}
|
||||
|
||||
// Exactly one blank line before tags.
|
||||
$params = $this->commentParser->getTagOrders();
|
||||
if (count($params) > 1) {
|
||||
$newlineSpan = $comment->getNewlineAfter();
|
||||
if ($newlineSpan !== 2) {
|
||||
$error = 'There must be exactly one blank line before the tags in function comment';
|
||||
if ($long !== '') {
|
||||
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
|
||||
}
|
||||
|
||||
$phpcsFile->addError($error, ($commentStart + $newlineCount), 'SpacingBeforeTags');
|
||||
$short = rtrim($short, $phpcsFile->eolChar.' ');
|
||||
}
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Process any throw tags that this function comment has.
|
||||
*
|
||||
* @param int $commentStart The position in the stack where the
|
||||
* comment started.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processThrows($commentStart)
|
||||
{
|
||||
if (count($this->commentParser->getThrows()) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->commentParser->getThrows() as $throw) {
|
||||
|
||||
$exception = $throw->getValue();
|
||||
$errorPos = ($commentStart + $throw->getLine());
|
||||
|
||||
if ($exception === '') {
|
||||
$error = '@throws tag must contain the exception class name';
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyThrows');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processThrows()
|
||||
|
||||
|
||||
/**
|
||||
* Process the return comment of this function comment.
|
||||
*
|
||||
* @param int $commentStart The position in the stack where the comment started.
|
||||
* @param int $commentEnd The position in the stack where the comment ended.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processReturn($commentStart, $commentEnd)
|
||||
{
|
||||
// Skip constructor and destructor.
|
||||
$className = '';
|
||||
if ($this->_classToken !== null) {
|
||||
$className = $this->currentFile->getDeclarationName($this->_classToken);
|
||||
$className = strtolower(ltrim($className, '_'));
|
||||
}
|
||||
|
||||
$methodName = strtolower(ltrim($this->_methodName, '_'));
|
||||
$isSpecialMethod = ($this->_methodName === '__construct' || $this->_methodName === '__destruct');
|
||||
|
||||
if ($isSpecialMethod === false && $methodName !== $className) {
|
||||
// Report missing return tag.
|
||||
if ($this->commentParser->getReturn() === null) {
|
||||
$error = 'Missing @return tag in function comment';
|
||||
$this->currentFile->addError($error, $commentEnd, 'MissingReturn');
|
||||
} else if (trim($this->commentParser->getReturn()->getRawContent()) === '') {
|
||||
$error = '@return tag is empty in function comment';
|
||||
$errorPos = ($commentStart + $this->commentParser->getReturn()->getLine());
|
||||
$this->currentFile->addError($error, $errorPos, 'EmptyReturn');
|
||||
} else {
|
||||
if (substr_count($this->commentParser->getReturn()->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
|
||||
$error = 'Return comment requires a blank newline after it';
|
||||
$errorPos = ($this->commentParser->getReturn()->getLine() + $commentStart);
|
||||
$this->currentFile->addError($error, $errorPos, 'SpacingAfterReturn');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->commentParser->getReturn() != null)
|
||||
{
|
||||
$error = 'Constructor and destructor comments must not have a @return tag';
|
||||
$errorPos = ($this->commentParser->getReturn()->getLine() + $commentStart);
|
||||
$this->currentFile->addError($error, $errorPos, 'UselessReturn');
|
||||
}
|
||||
}
|
||||
}//end processReturn()
|
||||
|
||||
|
||||
/**
|
||||
* Process the function parameter comments.
|
||||
*
|
||||
* @param int $commentStart The position in the stack where
|
||||
* the comment started.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processParams($commentStart)
|
||||
{
|
||||
$realParams = $this->currentFile->getMethodParameters($this->_functionToken);
|
||||
|
||||
$params = $this->commentParser->getParams();
|
||||
$foundParams = array();
|
||||
|
||||
if (empty($params) === false) {
|
||||
|
||||
$lastParm = (count($params) - 1);
|
||||
if (substr_count($params[$lastParm]->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
|
||||
$error = 'Last parameter comment requires a blank newline after it';
|
||||
$errorPos = ($params[$lastParm]->getLine() + $commentStart);
|
||||
$this->currentFile->addError($error, $errorPos, 'SpacingAfterParams');
|
||||
}
|
||||
|
||||
// Parameters must appear immediately after the comment.
|
||||
if ($params[0]->getOrder() !== 2) {
|
||||
$error = 'Parameters must appear immediately after the comment';
|
||||
$errorPos = ($params[0]->getLine() + $commentStart);
|
||||
$this->currentFile->addError($error, $errorPos, 'SpacingBeforeParams');
|
||||
}
|
||||
|
||||
$previousParam = null;
|
||||
$spaceBeforeVar = 10000;
|
||||
$spaceBeforeComment = 10000;
|
||||
$longestType = 0;
|
||||
$longestVar = 0;
|
||||
|
||||
foreach ($params as $param) {
|
||||
|
||||
$paramComment = trim($param->getComment());
|
||||
$errorPos = ($param->getLine() + $commentStart);
|
||||
|
||||
// Make sure that there is only one space before the var type.
|
||||
// Joomla change: 3 spaces to make it line up with the @return tag with a 2 space gap.
|
||||
if ($param->getWhitespaceBeforeType() !== ' ') {
|
||||
$error = 'Expected 3 spaces before variable type';
|
||||
$this->currentFile->addError($error, $errorPos, 'BeforeParamType');
|
||||
}
|
||||
|
||||
$spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
|
||||
if ($spaceCount < $spaceBeforeVar) {
|
||||
$spaceBeforeVar = $spaceCount;
|
||||
$longestType = $errorPos;
|
||||
}
|
||||
|
||||
$spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
|
||||
|
||||
if ($spaceCount < $spaceBeforeComment && $paramComment !== '') {
|
||||
$spaceBeforeComment = $spaceCount;
|
||||
$longestVar = $errorPos;
|
||||
}
|
||||
|
||||
// Make sure they are in the correct order,
|
||||
// and have the correct name.
|
||||
$pos = $param->getPosition();
|
||||
|
||||
$paramName = ($param->getVarName() !== '') ? $param->getVarName() : '[ UNKNOWN ]';
|
||||
|
||||
if ($previousParam !== null) {
|
||||
$previousName = ($previousParam->getVarName() !== '') ? $previousParam->getVarName() : 'UNKNOWN';
|
||||
|
||||
// Check to see if the parameters align properly.
|
||||
if ($param->alignsVariableWith($previousParam) === false) {
|
||||
$error = 'The variable names for parameters %s (%s) and %s (%s) do not align';
|
||||
$data = array(
|
||||
$previousName,
|
||||
($pos - 1),
|
||||
$paramName,
|
||||
$pos,
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'ParameterNamesNotAligned', $data);
|
||||
}
|
||||
|
||||
if ($param->alignsCommentWith($previousParam) === false) {
|
||||
$error = 'The comments for parameters %s (%s) and %s (%s) do not align';
|
||||
$data = array(
|
||||
$previousName,
|
||||
($pos - 1),
|
||||
$paramName,
|
||||
$pos,
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'ParameterCommentsNotAligned', $data);
|
||||
}
|
||||
}//end if
|
||||
|
||||
// Make sure the names of the parameter comment matches the
|
||||
// actual parameter.
|
||||
if (isset($realParams[($pos - 1)]) === true) {
|
||||
$realName = $realParams[($pos - 1)]['name'];
|
||||
$foundParams[] = $realName;
|
||||
|
||||
// Append ampersand to name if passing by reference.
|
||||
if ($realParams[($pos - 1)]['pass_by_reference'] === true) {
|
||||
$realName = '&'.$realName;
|
||||
}
|
||||
|
||||
if ($realName !== $paramName) {
|
||||
$code = 'ParamNameNoMatch';
|
||||
$data = array(
|
||||
$paramName,
|
||||
$realName,
|
||||
$pos,
|
||||
);
|
||||
|
||||
$error = 'Doc comment for var %s does not match ';
|
||||
if (strtolower($paramName) === strtolower($realName)) {
|
||||
$error .= 'case of ';
|
||||
$code = 'ParamNameNoCaseMatch';
|
||||
}
|
||||
|
||||
$error .= 'actual variable name %s at position %s';
|
||||
|
||||
$this->currentFile->addError($error, $errorPos, $code, $data);
|
||||
}
|
||||
} else {
|
||||
// We must have an extra parameter comment.
|
||||
$error = 'Superfluous doc comment at position '.$pos;
|
||||
$this->currentFile->addError($error, $errorPos, 'ExtraParamComment');
|
||||
}
|
||||
|
||||
if ($param->getVarName() === '') {
|
||||
$error = 'Missing parameter name at position '.$pos;
|
||||
$this->currentFile->addError($error, $errorPos, 'MissingParamName');
|
||||
}
|
||||
|
||||
if ($param->getType() === '') {
|
||||
$error = 'Missing type at position '.$pos;
|
||||
$this->currentFile->addError($error, $errorPos, 'MissingParamType');
|
||||
}
|
||||
|
||||
if ($paramComment === '') {
|
||||
$error = 'Missing comment for param "%s" at position %s';
|
||||
$data = array(
|
||||
$paramName,
|
||||
$pos,
|
||||
);
|
||||
$this->currentFile->addError($error, $errorPos, 'MissingParamComment', $data);
|
||||
}
|
||||
|
||||
$previousParam = $param;
|
||||
|
||||
}//end foreach
|
||||
|
||||
// Joomla modification to 2 spaces.
|
||||
if ($spaceBeforeVar !== 2 && $spaceBeforeVar !== 10000 && $spaceBeforeComment !== 10000) {
|
||||
$error = 'Expected 2 spaces after the longest type';
|
||||
$this->currentFile->addError($error, $longestType, 'SpacingAfterLongType');
|
||||
}
|
||||
|
||||
// Joomla modification to 2 spaces.
|
||||
if ($spaceBeforeComment !== 2 && $spaceBeforeComment !== 10000) {
|
||||
$error = 'Expected 2 spaces after the longest variable name';
|
||||
$this->currentFile->addError($error, $longestVar, 'SpacingAfterLongName');
|
||||
}
|
||||
|
||||
}//end if
|
||||
|
||||
$realNames = array();
|
||||
foreach ($realParams as $realParam) {
|
||||
$realNames[] = $realParam['name'];
|
||||
}
|
||||
|
||||
// Report and missing comments.
|
||||
$diff = array_diff($realNames, $foundParams);
|
||||
foreach ($diff as $neededParam) {
|
||||
if (count($params) !== 0) {
|
||||
$errorPos = ($params[(count($params) - 1)]->getLine() + $commentStart);
|
||||
} else {
|
||||
$errorPos = $commentStart;
|
||||
}
|
||||
|
||||
$error = 'Doc comment for "%s" missing';
|
||||
$data = array($neededParam);
|
||||
$this->currentFile->addError($error, $errorPos, 'MissingParamTag', $data);
|
||||
}
|
||||
|
||||
}//end processParams()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,147 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Joomla_Sniffs_Commenting_SingleCommentSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
/**
|
||||
* Returns the token types that this sniff is interested in.
|
||||
*
|
||||
* @return integer[]
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the tokens that this sniff is interested in.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
||||
* @param int $stackPtr The position in the stack where
|
||||
* the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$comment = trim($tokens[$stackPtr]['content']);
|
||||
|
||||
/*
|
||||
* Hash comments are not allowed.
|
||||
*/
|
||||
|
||||
if (0 === strpos($comment, '#'))
|
||||
{
|
||||
$phpcsFile->addError('Hash comments are prohibited; found %s'
|
||||
, $stackPtr, 'HashComment', array($comment));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 !== strpos($comment, '//'))
|
||||
{
|
||||
// Not of our concern
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Always have a space between // and the start of comment text.
|
||||
* The exception to this is if the preceding line consists of a single open bracket.
|
||||
*/
|
||||
|
||||
if (isset($comment{2}) && $comment{2} != ' ')
|
||||
{
|
||||
$phpcsFile->addError('Please put a space between the // and the start of comment text; found "%s"'
|
||||
, $stackPtr, 'NoSpace', array($comment));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* New lines should always start with an upper case letter unless
|
||||
* The line is a continuation of a complete sentence
|
||||
* The term is code and is case sensitive.(@todo)
|
||||
*/
|
||||
|
||||
if (isset($comment{3}) && $comment{3} != strtoupper($comment{3}))
|
||||
{
|
||||
// Comment does not start with an upper case letter
|
||||
|
||||
$previous = $phpcsFile->findPrevious(T_COMMENT, $stackPtr - 1);
|
||||
|
||||
if ($tokens[$previous]['line'] == $tokens[$stackPtr]['line'] - 1)
|
||||
{
|
||||
// There is a comment on the previous line.
|
||||
$test = trim($tokens[$previous]['content']);
|
||||
|
||||
if ('.' != substr($test, strlen($test) - 1))
|
||||
{
|
||||
// If the previous comment does not end with a full stop "." we
|
||||
// assume a sentence spanned over multiple lines.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$phpcsFile->addError('Please start your comment with a capital letter; found "%s"'
|
||||
, $stackPtr, 'LowerCase', array($comment));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Comments should not be on the same line as the code to which they refer
|
||||
* (which puts them after the code they reference).
|
||||
* They should be on their own lines.
|
||||
*/
|
||||
|
||||
$previous = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr);
|
||||
|
||||
if ($tokens[$previous]['line'] == $tokens[$stackPtr]['line'])
|
||||
{
|
||||
$phpcsFile->addError('Please put your comment on a separate line *preceding* your code; found "%s"'
|
||||
, $stackPtr, 'Inline', array($comment));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Always have a single blank line before a comment or block of comments.
|
||||
* -- Don't allow preceding "code" - identified by a semicolon ;)
|
||||
*/
|
||||
if ($tokens[$previous]['line'] == $tokens[$stackPtr]['line'] - 1)
|
||||
{
|
||||
$phpcsFile->addError('Please consider a blank line preceding your comment'
|
||||
, $stackPtr, 'TooClose');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Comment blocks that introduce large sections of code and are more than 3 lines long
|
||||
* should use /* * / and should use * on each line with the same space/tab rules as doc blocks.
|
||||
* If you need a large introduction consider whether this block should be separated into a
|
||||
* method to reduce complexity and therefore providing a full docblock.
|
||||
*/
|
||||
|
||||
$next = $phpcsFile->findNext(T_COMMENT, $stackPtr + 1);
|
||||
|
||||
if ($tokens[$next]['line'] == $tokens[$stackPtr]['line'] + 1)
|
||||
{
|
||||
// The following line contains also a comment
|
||||
$nextNext = $phpcsFile->findNext(T_COMMENT, $next + 1);
|
||||
|
||||
if ($tokens[$nextNext]['line'] == $tokens[$next]['line'] + 1)
|
||||
{
|
||||
// Found 3 lines of // comments - too much.
|
||||
$phpcsFile->addError('Please consider the /* */ style for comments that span over multiple lines.'
|
||||
, $stackPtr, 'MultiLine');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}//function
|
||||
|
||||
}//class
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Verifies that control statements conform to their coding standards.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: ControlSignatureSniff.php 244676 2007-10-23 06:05:14Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that control statements conform to their coding standards.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a Joomla_Sniffs_ControlStructures_ControlSignatureSniff.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(true);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
/**
|
||||
* Returns the patterns that this test wishes to verify.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getPatterns()
|
||||
{
|
||||
return array(
|
||||
'if (...)EOL...{...}EOL...elseEOL',
|
||||
'if (...)EOL...{...}EOL...elseif (...)EOL',
|
||||
'if (...)EOL',
|
||||
|
||||
'tryEOL...{EOL...}EOL',
|
||||
'catch (...)EOL...{EOL',
|
||||
|
||||
'doEOL...{...}EOL',
|
||||
'while (...)EOL...{EOL',
|
||||
|
||||
'for (...)EOL...{EOL',
|
||||
'foreach (...)EOL...{EOL',
|
||||
|
||||
'switch (...)EOL...{EOL',
|
||||
);
|
||||
|
||||
}//end getPatterns()
|
||||
|
||||
/**
|
||||
* Process a pattern.
|
||||
*
|
||||
* Returns if we are inside a "tmpl" folder - workaround for the Joomla! CMS :(
|
||||
*
|
||||
* @param array $patternInfo Information about the pattern used for checking, which includes are
|
||||
* parsed token representation of the pattern.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the token occurred.
|
||||
* @param integer $stackPtr The position in the tokens stack where the listening token type was found.
|
||||
*
|
||||
* @return return_type
|
||||
*/
|
||||
protected function processPattern($patternInfo, PHP_CodeSniffer_File $phpcsFile
|
||||
, $stackPtr)
|
||||
{
|
||||
if (0)
|
||||
{
|
||||
/*
|
||||
* @todo disabled - This is a special sniff for the Joomla! CMS to exclude
|
||||
* the tmpl folder which may contain constructs in colon notation
|
||||
*/
|
||||
|
||||
$parts = explode(DIRECTORY_SEPARATOR, $phpcsFile->getFileName());
|
||||
|
||||
if ('tmpl' == $parts[count($parts) - 2])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::processPattern($patternInfo, $phpcsFile, $stackPtr);
|
||||
}//function
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Joomla_Sniffs_ControlStructures_InlineControlStructureSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: InlineControlStructureSniff.php 258843 2008-05-01 00:49:32Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joomla_Sniffs_ControlStructures_InlineControlStructureSniff.
|
||||
*
|
||||
* Verifies that inline control statements are not present.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_ControlStructures_InlineControlStructureSniff extends Generic_Sniffs_ControlStructures_InlineControlStructureSniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array(
|
||||
'PHP',
|
||||
'JS',
|
||||
);
|
||||
|
||||
/**
|
||||
* If true, an error will be thrown; otherwise a warning.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $error = false;
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_IF,
|
||||
T_ELSE,
|
||||
T_FOREACH,
|
||||
T_WHILE,
|
||||
T_DO,
|
||||
T_SWITCH,
|
||||
T_FOR,
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
|
||||
// Ignore the ELSE in ELSE IF. We'll process the IF part later.
|
||||
if (($tokens[$stackPtr]['code'] === T_ELSE) && ($tokens[($stackPtr + 2)]['code'] === T_IF)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[$stackPtr]['code'] === T_WHILE) {
|
||||
// This could be from a DO WHILE, which doesn't have an opening brace.
|
||||
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
|
||||
if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
|
||||
$brace = $tokens[$lastContent];
|
||||
if (isset($brace['scope_condition']) === true) {
|
||||
$condition = $tokens[$brace['scope_condition']];
|
||||
if ($condition['code'] === T_DO) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is a control structure without an opening brace,
|
||||
// so it is an inline statement.
|
||||
if ($this->error === true) {
|
||||
$phpcsFile->addError('Inline control structures are not allowed', $stackPtr, 'NotAllowed');
|
||||
} else {
|
||||
$phpcsFile->addWarning('Inline control structures are discouraged', $stackPtr, 'Discouraged');
|
||||
}
|
||||
|
||||
return;
|
||||
}//end if
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,133 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Joomla_Sniffs_ControlStructures_MultiLineConditionSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: MultiLineConditionSniff.php 289839 2009-10-21 23:11:33Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joomla_Sniffs_ControlStructures_MultiLineConditionSniff.
|
||||
*
|
||||
* Ensure multi-line IF conditions are defined correctly.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_IF);
|
||||
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// We need to work out how far indented the if statement
|
||||
// itself is, so we can work out how far to indent conditions.
|
||||
$statementIndent = 0;
|
||||
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
|
||||
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i >= 0 && $tokens[$i]['code'] === T_WHITESPACE) {
|
||||
$statementIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
// Each line between the parenthesis should be indented 4 spaces
|
||||
// and start with an operator, unless the line is inside a
|
||||
// function call, in which case it is ignored.
|
||||
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
|
||||
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$openBracket]['line'];
|
||||
|
||||
for ($i = ($openBracket + 1); $i <= $closeBracket; $i++) {
|
||||
if ($tokens[$i]['line'] !== $lastLine) {
|
||||
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
|
||||
if ($next == $closeBracket) {
|
||||
$error = 'Closing parenthesis of a multi-line IF statement must be on the same line';
|
||||
$phpcsFile->addError($error, $i, 'CloseBracketNewLine');
|
||||
$i ++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$expectedIndent = ($statementIndent + 1);
|
||||
|
||||
// We changed lines, so this should be a whitespace indent token.
|
||||
if ($tokens[$i]['code'] !== T_WHITESPACE) {
|
||||
$foundIndent = 0;
|
||||
} else {
|
||||
$foundIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
if ($expectedIndent !== $foundIndent) {
|
||||
$error = 'Multi-line IF statement not indented correctly; expected %s spaces but found %s';
|
||||
$data = array(
|
||||
$expectedIndent,
|
||||
$foundIndent,
|
||||
);
|
||||
$phpcsFile->addError($error, $i, 'Alignment', $data);
|
||||
}
|
||||
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
|
||||
|
||||
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
|
||||
$error = 'Each line in a multi-line IF statement must begin with a boolean operator';
|
||||
$phpcsFile->addError($error, $i, 'StartWithBoolean');
|
||||
}
|
||||
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
}//end if
|
||||
|
||||
if ($tokens[$i]['code'] === T_STRING) {
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
|
||||
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
|
||||
// This is a function call, so skip to the end as they
|
||||
// have their own indentation rules.
|
||||
$i = $tokens[$next]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,257 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Joomla_Sniffs_Functions_FunctionCallSignatureSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: FunctionCallSignatureSniff.php 284575 2009-07-22 02:58:19Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joomla_Sniffs_Functions_FunctionCallSignatureSniff.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Functions_FunctionCallSignatureSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STRING);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Find the next non-empty token.
|
||||
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
|
||||
|
||||
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
|
||||
// Not a function call.
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
|
||||
// Not a function call.
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the previous non-empty token.
|
||||
$search = PHP_CodeSniffer_Tokens::$emptyTokens;
|
||||
$search[] = T_BITWISE_AND;
|
||||
$previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true);
|
||||
if ($tokens[$previous]['code'] === T_FUNCTION) {
|
||||
// It's a function definition, not a function call.
|
||||
return;
|
||||
}
|
||||
|
||||
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
|
||||
|
||||
if (($stackPtr + 1) !== $openBracket) {
|
||||
// Checking this: $value = my_function[*](...).
|
||||
$error = 'Space before opening parenthesis of function call prohibited';
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpaceBeforeOpenBracket');
|
||||
}
|
||||
|
||||
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
|
||||
if ($tokens[$next]['code'] === T_SEMICOLON) {
|
||||
if (in_array($tokens[($closeBracket + 1)]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
|
||||
$error = 'Space after closing parenthesis of function call prohibited';
|
||||
$phpcsFile->addError($error, $closeBracket, 'SpaceAfterCloseBracket');
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this is a single line or multi-line function call.
|
||||
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
|
||||
$this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
|
||||
} else {
|
||||
$this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Processes single-line calls.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param int $openBracket The position of the openning bracket
|
||||
* in the stack passed in $tokens.
|
||||
* @param array $tokens The stack of tokens that make up
|
||||
* the file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
|
||||
{
|
||||
if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
|
||||
// Checking this: $value = my_function([*]...).
|
||||
$error = 'Space after opening parenthesis of function call prohibited';
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpaceAfterOpenBracket');
|
||||
}
|
||||
|
||||
$closer = $tokens[$openBracket]['parenthesis_closer'];
|
||||
|
||||
if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) {
|
||||
// Checking this: $value = my_function(...[*]).
|
||||
$between = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
|
||||
|
||||
// Only throw an error if there is some content between the parenthesis.
|
||||
// i.e., Checking for this: $value = my_function().
|
||||
// If there is no content, then we would have thrown an error in the
|
||||
// previous IF statement because it would look like this:
|
||||
// $value = my_function( ).
|
||||
if ($between !== $closer) {
|
||||
$error = 'Space before closing parenthesis of function call prohibited';
|
||||
$phpcsFile->addError($error, $closer, 'SpaceBeforeCloseBracket');
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSingleLineCall()
|
||||
|
||||
|
||||
/**
|
||||
* Processes multi-line calls.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param int $openBracket The position of the openning bracket
|
||||
* in the stack passed in $tokens.
|
||||
* @param array $tokens The stack of tokens that make up
|
||||
* the file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
|
||||
{
|
||||
// We need to work out how far indented the function
|
||||
// call itself is, so we can work out how far to
|
||||
// indent the arguments.
|
||||
$functionIndent = 0;
|
||||
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
|
||||
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[$i]['code'] === T_WHITESPACE) {
|
||||
$functionIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
// Each line between the parenthesis should be indented 4 spaces.
|
||||
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$openBracket]['line'];
|
||||
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
|
||||
// Skip nested function calls.
|
||||
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
|
||||
$i = $tokens[$i]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($tokens[$i]['line'] !== $lastLine) {
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
|
||||
// We changed lines, so this should be a whitespace indent token.
|
||||
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$heredocTokens) === true) {
|
||||
// Ignore heredoc indentation.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
|
||||
if ($tokens[$i]['code'] === $tokens[($i - 1)]['code']) {
|
||||
// Ignore multi-line string indentation.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
|
||||
// Closing brace needs to be indented to the same level
|
||||
// as the function call.
|
||||
$expectedIndent = $functionIndent;
|
||||
} else {
|
||||
$expectedIndent = ($functionIndent + 4);
|
||||
}
|
||||
|
||||
if ($tokens[$i]['code'] !== T_WHITESPACE) {
|
||||
$foundIndent = 0;
|
||||
} else {
|
||||
$foundIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
if ($expectedIndent !== $foundIndent) {
|
||||
// TODO AJE Allow for tab indents instead of spaces
|
||||
// $error = 'Multi-line function call not indented correctly; expected %s spaces but found %s';
|
||||
// $data = array(
|
||||
// $expectedIndent,
|
||||
// $foundIndent,
|
||||
// );
|
||||
// $phpcsFile->addError($error, $i, 'Indent', $data);
|
||||
}
|
||||
}//end if
|
||||
|
||||
// Skip the rest of a closure.
|
||||
if ($tokens[$i]['code'] === T_CLOSURE) {
|
||||
$i = $tokens[$i]['scope_closer'];
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
continue;
|
||||
}
|
||||
}//end for
|
||||
|
||||
if ($tokens[($openBracket + 1)]['content'] !== $phpcsFile->eolChar
|
||||
&& T_CONSTANT_ENCAPSED_STRING != $tokens[($openBracket + 1)]['code'])// allow a '"'
|
||||
{
|
||||
$error = 'Opening parenthesis of a multi-line function call must be the last content on the line';
|
||||
$phpcsFile->addError($error, $stackPtr, 'ContentAfterOpenBracket');
|
||||
}
|
||||
|
||||
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true);
|
||||
|
||||
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']
|
||||
&& T_CONSTANT_ENCAPSED_STRING != $tokens[$prev]['code'])// allow a '"'
|
||||
{
|
||||
$error = 'Closing parenthesis of a multi-line function call must be on a line by itself';
|
||||
$phpcsFile->addError($error, $closeBracket, 'CloseBracketLine');
|
||||
}
|
||||
|
||||
}//end processMultiLineCall()
|
||||
|
||||
|
||||
}//end class
|
||||
?>
|
|
@ -1,228 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Joomla_Sniffs_Functions_FunctionDeclarationSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: FunctionDeclarationSniff.php 308840 2011-03-02 05:32:18Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joomla_Sniffs_Functions_FunctionDeclarationSniff.
|
||||
*
|
||||
* Ensure single and multi-line function declarations are defined correctly.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_FUNCTION);
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Check if this is a single line or multi-line declaration.
|
||||
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
|
||||
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
|
||||
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
|
||||
$this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
|
||||
} else {
|
||||
$this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
/**
|
||||
* Processes single-line declarations.
|
||||
*
|
||||
* Just uses the Generic BSD-Allman brace sniff.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param array $tokens The stack of tokens that make up
|
||||
* the file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
|
||||
{
|
||||
if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found');
|
||||
}
|
||||
|
||||
$sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff();
|
||||
$sniff->process($phpcsFile, $stackPtr);
|
||||
|
||||
}//end processSingleLineDeclaration()
|
||||
|
||||
|
||||
/**
|
||||
* Processes mutli-line declarations.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param array $tokens The stack of tokens that make up
|
||||
* the file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
|
||||
{
|
||||
// We need to work out how far indented the function
|
||||
// declaration itself is, so we can work out how far to
|
||||
// indent parameters.
|
||||
$functionIndent = 0;
|
||||
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
|
||||
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[$i]['code'] === T_WHITESPACE) {
|
||||
$functionIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
// Each line between the parenthesis should be indented 4 spaces.
|
||||
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
|
||||
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$openBracket]['line'];
|
||||
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
|
||||
if ($tokens[$i]['line'] !== $lastLine)
|
||||
{
|
||||
//-- elkuku: disabled
|
||||
// if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
|
||||
// // Closing brace needs to be indented to the same level
|
||||
// // as the function.
|
||||
// $expectedIndent = $functionIndent;
|
||||
// } else {
|
||||
// $expectedIndent = $functionIndent + 4;
|
||||
// }
|
||||
|
||||
$expectedIndent = $functionIndent + 1;
|
||||
|
||||
// We changed lines, so this should be a whitespace indent token.
|
||||
if ($tokens[$i]['code'] !== T_WHITESPACE) {
|
||||
$foundIndent = 0;
|
||||
} else {
|
||||
$foundIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
if ($expectedIndent !== $foundIndent) {
|
||||
$error = 'Multi-line function declaration not indented correctly; expected %s spaces but found %s';
|
||||
$data = array(
|
||||
$expectedIndent,
|
||||
$foundIndent,
|
||||
);
|
||||
$phpcsFile->addError($error, $i, 'Indent', $data);
|
||||
}
|
||||
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
}//end if
|
||||
|
||||
if ($tokens[$i]['code'] === T_ARRAY) {
|
||||
// Skip arrays as they have their own indentation rules.
|
||||
$i = $tokens[$i]['parenthesis_closer'];
|
||||
$lastLine = $tokens[$i]['line'];
|
||||
continue;
|
||||
}
|
||||
}//end for
|
||||
|
||||
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
|
||||
// The openning brace needs to be one space away
|
||||
// from the closing parenthesis.
|
||||
$next = $tokens[($closeBracket + 1)];
|
||||
if ($next['code'] !== T_WHITESPACE) {
|
||||
$length = 0;
|
||||
} else if ($next['content'] === $phpcsFile->eolChar) {
|
||||
$length = -1;
|
||||
} else {
|
||||
$length = strlen($next['content']);
|
||||
}
|
||||
|
||||
if (false)//$length !== 1) {
|
||||
{
|
||||
$data = array($length);
|
||||
$code = 'SpaceBeforeOpenBrace';
|
||||
|
||||
//-- elkuku: nonsens ?
|
||||
// $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
|
||||
// if ($length === -1) {
|
||||
// $error .= 'newline';
|
||||
// $code = 'NewlineBeforeOpenBrace';
|
||||
// } else {
|
||||
// $error .= '%s spaces';
|
||||
// }
|
||||
|
||||
$phpcsFile->addError($error, ($closeBracket + 1), $code, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
// And just in case they do something funny before the brace...
|
||||
$next = $phpcsFile->findNext(
|
||||
T_WHITESPACE,
|
||||
($closeBracket + 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
//-- elkuku: nonsens ?
|
||||
// if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
|
||||
// $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
|
||||
// $phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
|
||||
// }
|
||||
}//end if
|
||||
|
||||
// The closing parenthesis must be on a new line, even
|
||||
// when checking abstract function definitions.
|
||||
$prev = $phpcsFile->findPrevious(
|
||||
T_WHITESPACE,
|
||||
($closeBracket - 1),
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
if ($tokens[$prev]['line'] != $tokens[$closeBracket]['line']) {
|
||||
$error = 'The closing parenthesis of a multi-line function declaration must be on the same line';
|
||||
$phpcsFile->addError($error, $closeBracket, 'CloseBracketLine');
|
||||
}
|
||||
|
||||
}//end processMultiLineDeclaration()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Squiz_Sniffs_Strings_ConcatenationSpacingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: ConcatenationSpacingSniff.php 151 2010-11-26 01:07:46Z elkuku $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Makes sure there are is a spaces between the concatenation operator <b>.</b> and the strings being concatenated.
|
||||
*
|
||||
* Example:
|
||||
* <b class="bad">$a = $b.$c;</b>
|
||||
* <b class="good">$a = $b . $c;</b>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC1
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_WhiteSpace_ConcatenationSpacingSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_STRING_CONCAT);
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param integer $stackPtr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if ($tokens[($stackPtr + 1)]['code'] != T_WHITESPACE)
|
||||
{
|
||||
// space after
|
||||
$message = 'Concat operator must be followed by one space';
|
||||
$phpcsFile->addError($message, $stackPtr, 'Missing');
|
||||
}
|
||||
else
|
||||
{
|
||||
$found = strlen($tokens[($stackPtr + 1)]['content']);
|
||||
|
||||
if ($found > 1)
|
||||
{
|
||||
$error = sprintf('Expected 1 space after concat operator; %s found', $found);
|
||||
$phpcsFile->addError($error, $stackPtr, 'Too much');
|
||||
}
|
||||
}
|
||||
|
||||
if ($tokens[($stackPtr - 1)]['code'] != T_WHITESPACE)
|
||||
{
|
||||
// space before
|
||||
$message = 'Concat operator must be preceeded by one space';
|
||||
$phpcsFile->addError($message, $stackPtr, 'Missing');
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strpos($tokens[($stackPtr - 2)]['content'], $phpcsFile->eolChar) !== false
|
||||
|| strpos($tokens[($stackPtr - 1)]['content'], $phpcsFile->eolChar) !== false)
|
||||
{
|
||||
// the dot is on a new line
|
||||
return;
|
||||
}
|
||||
|
||||
$found = strlen($tokens[($stackPtr - 1)]['content']);
|
||||
|
||||
if ($found > 1)
|
||||
{
|
||||
$error = sprintf('Expected 1 space before concat operator; %s found', $found);
|
||||
$phpcsFile->addError($error, $stackPtr, 'Too much');
|
||||
}
|
||||
}
|
||||
}//function
|
||||
}//class
|
|
@ -1,151 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Verifies that class members are spaced correctly.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: MemberVarSpacingSniff.php 8 2010-11-06 00:40:23Z elkuku $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if(class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false)
|
||||
{
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that class members are spaced correctly.
|
||||
*
|
||||
* Example:
|
||||
* <b class="bad">Bad:</b>
|
||||
* class Foo
|
||||
* {
|
||||
* <b class="bad">private $foo;</b>
|
||||
* <b class="bad">private $bar;</b>
|
||||
* }
|
||||
*
|
||||
* <b class="good">Good:</b>
|
||||
* class Foo
|
||||
* {
|
||||
* <b class="good">private $foo;</b>
|
||||
* <b class="good"> </b>
|
||||
* <b class="good">private $bar;</b>
|
||||
* }
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC1
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_WhiteSpace_MemberVarSpacingSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
|
||||
{
|
||||
/**
|
||||
* Processes the function tokens within the class.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// There needs to be 1 blank line before the var, not counting comments.
|
||||
$prevLineToken = null;
|
||||
|
||||
for($i = ($stackPtr); $i > 0; $i--)
|
||||
{
|
||||
if(in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true)
|
||||
{
|
||||
// Skip comments.
|
||||
continue;
|
||||
}
|
||||
else if(strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false)
|
||||
{
|
||||
// Not the end of the line.
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If this is a WHITESPACE token, and the token right before
|
||||
// it is a DOC_COMMENT, then it is just the newline after the
|
||||
// member var's comment, and can be skipped.
|
||||
if($tokens[$i]['code'] === T_WHITESPACE
|
||||
&& in_array($tokens[($i - 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$prevLineToken = $i;
|
||||
break;
|
||||
}
|
||||
}//for
|
||||
|
||||
if(is_null($prevLineToken) === true)
|
||||
{
|
||||
// Never found the previous line, which means
|
||||
// there are 0 blank lines before the member var.
|
||||
$foundLines = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$prevContent = $phpcsFile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevLineToken, null, true);
|
||||
|
||||
if($tokens[$prevContent]['code'] == T_OPEN_CURLY_BRACKET)
|
||||
{
|
||||
$foundLines = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$foundLines = ($tokens[$prevLineToken]['line'] - $tokens[$prevContent]['line']);
|
||||
}
|
||||
}//end if
|
||||
|
||||
if($foundLines !== 1)
|
||||
{
|
||||
$error = sprintf('Expected 1 blank line before member var; %s found'
|
||||
, $foundLines);
|
||||
|
||||
$phpcsFile->addError($error, $stackPtr, 'After');
|
||||
}
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes normal variables.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We don't care about normal variables.
|
||||
return;
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes variables in double quoted strings.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param integer $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We don't care about normal variables.
|
||||
return;
|
||||
}//function
|
||||
}//class
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Joomla_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: ObjectOperatorIndentSniff.php 288251 2009-09-10 23:50:52Z squiz $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joomla_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
|
||||
*
|
||||
* Checks that object operators are indented 4 spaces if they are the first
|
||||
* thing on a line.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC2
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_OBJECT_OPERATOR);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Make sure this is the first object operator in a chain of them.
|
||||
$varToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
|
||||
if ($varToken === false || $tokens[$varToken]['code'] !== T_VARIABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure this is a chained call.
|
||||
$next = $phpcsFile->findNext(
|
||||
T_OBJECT_OPERATOR,
|
||||
($stackPtr + 1),
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
if ($next === false) {
|
||||
// Not a chained call.
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine correct indent.
|
||||
for ($i = ($varToken - 1); $i >= 0; $i--) {
|
||||
if ($tokens[$i]['line'] !== $tokens[$varToken]['line']) {
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$requiredIndent = 0;
|
||||
if ($i >= 0 && $tokens[$i]['code'] === T_WHITESPACE) {
|
||||
$requiredIndent = strlen($tokens[$i]['content']);
|
||||
}
|
||||
|
||||
$requiredIndent += 4;
|
||||
|
||||
// Determine the scope of the original object operator.
|
||||
$origBrackets = null;
|
||||
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
|
||||
$origBrackets = $tokens[$stackPtr]['nested_parenthesis'];
|
||||
}
|
||||
|
||||
$origConditions = null;
|
||||
if (isset($tokens[$stackPtr]['conditions']) === true) {
|
||||
$origConditions = $tokens[$stackPtr]['conditions'];
|
||||
}
|
||||
|
||||
// Check indentation of each object operator in the chain.
|
||||
// If the first object operator is on a different line than
|
||||
// the variable, make sure we check its indentation too.
|
||||
if ($tokens[$stackPtr]['line'] > $tokens[$varToken]['line']) {
|
||||
$next = $stackPtr;
|
||||
}
|
||||
|
||||
while ($next !== false) {
|
||||
// Make sure it is in the same scope, otherwise dont check indent.
|
||||
$brackets = null;
|
||||
if (isset($tokens[$next]['nested_parenthesis']) === true) {
|
||||
$brackets = $tokens[$next]['nested_parenthesis'];
|
||||
}
|
||||
|
||||
$conditions = null;
|
||||
if (isset($tokens[$next]['conditions']) === true) {
|
||||
$conditions = $tokens[$next]['conditions'];
|
||||
}
|
||||
|
||||
if ($origBrackets === $brackets && $origConditions === $conditions) {
|
||||
// Make sure it starts a line, otherwise dont check indent.
|
||||
$indent = $tokens[($next - 1)];
|
||||
if ($indent['code'] === T_WHITESPACE) {
|
||||
if ($indent['line'] === $tokens[$next]['line']) {
|
||||
$foundIndent = strlen($indent['content']);
|
||||
} else {
|
||||
$foundIndent = 0;
|
||||
}
|
||||
|
||||
if ($foundIndent !== $requiredIndent) {
|
||||
// TODO AJE Allow for tab indents instead of spaces
|
||||
// $error = 'Object operator not indented correctly; expected %s spaces but found %s';
|
||||
// $data = array(
|
||||
// $requiredIndent,
|
||||
// $foundIndent,
|
||||
// );
|
||||
// $phpcsFile->addError($error, $next, 'Incorrect', $data);
|
||||
}
|
||||
}
|
||||
|
||||
// It can't be the last thing on the line either.
|
||||
$content = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
|
||||
if ($tokens[$content]['line'] !== $tokens[$next]['line']) {
|
||||
$error = 'Object operator must be at the start of the line, not the end';
|
||||
$phpcsFile->addError($error, $next, 'StartOfLine');
|
||||
}
|
||||
}//end if
|
||||
|
||||
$next = $phpcsFile->findNext(
|
||||
T_OBJECT_OPERATOR,
|
||||
($next + 1),
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
}//end while
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Generic_Sniffs_Formatting_NoSpaceAfterCastSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id: NoSpaceAfterCastSniff.php 8 2010-11-06 00:40:23Z elkuku $
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensures there is no space after cast tokens.
|
||||
*
|
||||
* Example:
|
||||
* <b class="bad">(int) $foo;</b>
|
||||
* <b class="good">(int)$foo;</b>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.3.0RC1
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class Joomla_Sniffs_WhiteSpace_SpaceAfterCastSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return PHP_CodeSniffer_Tokens::$castTokens;
|
||||
}//function
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param integer $stackPtr The position of the current token in
|
||||
* the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE)
|
||||
{
|
||||
$content = $tokens[($stackPtr + 1)]['content'];
|
||||
$contentLength = strlen($content);
|
||||
|
||||
if ($contentLength !== 1)
|
||||
{
|
||||
$error = 'Cast statements must be followed by a single space; expected 1 space but found %s';
|
||||
$data = array($contentLength);
|
||||
$phpcsFile->addError($error, $stackPtr, 'IncorrectSingle', $data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = 'Cast statements must be followed by a single space; expected "%s" but found "%s"';
|
||||
$data = array(
|
||||
$tokens[$stackPtr]['content'].' '.$tokens[($stackPtr + 1)]['content'],
|
||||
$tokens[$stackPtr]['content'].$tokens[($stackPtr + 1)]['content'],
|
||||
);
|
||||
$phpcsFile->addError($error, $stackPtr, 'Incorrect', $data);
|
||||
}
|
||||
|
||||
// if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE)
|
||||
// {
|
||||
// $error = 'A cast statement must not be followed by a space';
|
||||
// $phpcsFile->addError($error, $stackPtr, 'SpaceFound');
|
||||
// }
|
||||
}//function
|
||||
}//class
|
|
@ -1,214 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="Joomla">
|
||||
<description>The Joomla coding standard.</description>
|
||||
|
||||
<!-- Exclude folders not containing production code -->
|
||||
<exclude-pattern type="relative">build/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">cache/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">docs/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">logs/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">tmp/*</exclude-pattern>
|
||||
|
||||
<!-- Exclude 3rd party libraries and Framework code. -->
|
||||
<exclude-pattern type="relative">libraries/compat/password/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">libraries/php-encryption/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">libraries/phpass/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">node_modules/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">*/vendor/*</exclude-pattern>
|
||||
<!-- Temporarily exclude the old FOF Library code. TODO: Should be made compliant!! -->
|
||||
<exclude-pattern type="relative">libraries/src/Encrypt/*</exclude-pattern>
|
||||
<!-- Exclude the restore_finalisation until we can deal with nested class definitions -->
|
||||
<exclude-pattern type="relative">administrator/components/com_joomlaupdate/restore_finalisation.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">administrator/components/com_joomlaupdate/restore.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">configuration.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">installation/template/error.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">installation/template/index.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">plugins/captcha/recaptcha/recaptchalib.php</exclude-pattern>
|
||||
<!-- Exclude a temporary helper from PHPUnit whilst we refactor out legacy PHPUnit code -->
|
||||
<exclude-pattern type="relative">tests/unit/core/domhelper.php</exclude-pattern>
|
||||
<!-- Exclude some test related files that don't actually include PHP code -->
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/model/stubs/barbaz.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/fringe/division.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/olivia.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts1/peter.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts2/fauxlivia.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/joomla/view/layouts2/olivia.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/legacy/controller/stubs/component1/controller.json.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/unit/suites/libraries/legacy/controller/stubs/component2/controller.php</exclude-pattern>
|
||||
|
||||
<!-- exclude file because of the use of unsupported class definition -->
|
||||
<exclude-pattern type="relative">*/services/provider.php</exclude-pattern>
|
||||
|
||||
<!-- Exclude the RoboFile.php -->
|
||||
<exclude-pattern type="relative">RoboFile.php</exclude-pattern>
|
||||
|
||||
<!-- Include all sniffs in an external standard directory -->
|
||||
<rule ref="Generic.Files.EndFileNewline">
|
||||
<!-- These exceptions are temporary for now, possibly permanent -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Use Unix newlines -->
|
||||
<rule ref="Generic.Files.LineEndings">
|
||||
<properties>
|
||||
<property name="eolChar" value="\n"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Lines can be 150 chars long, but never show errors -->
|
||||
<rule ref="Generic.Files.LineLength">
|
||||
<properties>
|
||||
<property name="lineLimit" value="150"/>
|
||||
<property name="absoluteLineLimit" value="0"/>
|
||||
</properties>
|
||||
<!-- These exceptions are temporary for now, possibly permanent -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Formatting.DisallowMultipleStatements">
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />
|
||||
|
||||
<!-- This message is not required as spaces are allowed for alignment -->
|
||||
<rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma">
|
||||
<severity>0</severity>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.NamingConventions.UpperCaseConstantName" />
|
||||
<rule ref="Generic.PHP.DisallowShortOpenTag" />
|
||||
<rule ref="Generic.PHP.DeprecatedFunctions" />
|
||||
<rule ref="Generic.PHP.ForbiddenFunctions"/>
|
||||
<rule ref="Generic.PHP.LowerCaseConstant" />
|
||||
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
|
||||
|
||||
<!-- Include some additional sniffs from the PEAR standard -->
|
||||
<rule ref="PEAR.Classes.ClassDeclaration" />
|
||||
<rule ref="PEAR.Commenting.InlineComment" />
|
||||
<rule ref="PEAR.Formatting.MultiLineAssignment" />
|
||||
<rule ref="PEAR.Functions.ValidDefaultValue">
|
||||
<!-- These exceptions are temporary for now -->
|
||||
<exclude-pattern type="relative">administrator/components/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">components/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">modules/mod_articles_category/helper.php</exclude-pattern>
|
||||
<exclude-pattern type="relative">libraries/cms/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PEAR.NamingConventions.ValidClassName">
|
||||
<!-- These exceptions are temporary for now -->
|
||||
<exclude-pattern type="relative">installation/controller/install/database_*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Include some additional sniffs from the Squiz standard -->
|
||||
<rule ref="Squiz.CSS.ColonSpacing" />
|
||||
<rule ref="Squiz.CSS.DuplicateClassDefinition" />
|
||||
<rule ref="Squiz.CSS.EmptyClassDefinition" />
|
||||
<rule ref="Squiz.CSS.EmptyStyleDefinition" />
|
||||
<rule ref="Squiz.CSS.MissingColon" />
|
||||
<rule ref="Squiz.CSS.SemicolonSpacing" />
|
||||
<rule ref="Squiz.Classes.SelfMemberReference" />
|
||||
|
||||
<rule ref="Squiz.Operators.IncrementDecrementUsage">
|
||||
<exclude name="Squiz.Operators.IncrementDecrementUsage.processAssignment" />
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Scope.StaticThisUsage" />
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace">
|
||||
<!-- These exceptions are temporary -->
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
|
||||
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
|
||||
|
||||
<!-- Include some additional sniffs from the PSR2 standard -->
|
||||
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
|
||||
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
|
||||
<type>error</type>
|
||||
</rule>
|
||||
|
||||
<!-- Include some additional sniffs from the Zend standard -->
|
||||
<rule ref="Zend.Files.ClosingTag">
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Remove the following when the folder limitations are dropped -->
|
||||
|
||||
<rule ref="Joomla.Classes.MethodScope">
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.FileComment">
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Functions.FunctionCallSignature">
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.FunctionComment">
|
||||
<!-- We only want this for libraries, language and cli for now -->
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.FunctionComment.MissingParamTag">
|
||||
<exclude-pattern type="relative">administrator/components/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.FunctionComment.ParamNameNoMatch">
|
||||
<exclude-pattern type="relative">administrator/components/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.SingleComment">
|
||||
<!-- We don't want this in mixed html/php views for now -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.Commenting.ClassComment">
|
||||
<exclude-pattern type="relative">tests/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.ControlStructures.ControlSignature">
|
||||
<!-- These exceptions are permanent -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.ControlStructures.InlineControlStructure">
|
||||
<!-- These exceptions are permanent -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.ControlStructures.MultiLineCondition">
|
||||
<!-- These exceptions are permanent -->
|
||||
<exclude-pattern type="relative">*/tmpl/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Joomla.WhiteSpace.ConcatenationSpacing">
|
||||
<!-- We only want this for libraries, language and cli for now -->
|
||||
<exclude-pattern type="relative">templates/*</exclude-pattern>
|
||||
<exclude-pattern type="relative">layouts/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="Joomla.WhiteSpace.MemberVarSpacing" />
|
||||
<rule ref="Joomla.WhiteSpace.ObjectOperatorIndent"/>
|
||||
</ruleset>
|
|
@ -31,4 +31,3 @@ $articleId = $displayData['item']->id;
|
|||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -261,8 +261,8 @@ abstract class JHtmlBehavior
|
|||
}).highlight([\"" . implode('","', $terms) . "\"]);
|
||||
$(start).remove();
|
||||
$(end).remove();
|
||||
});
|
||||
");
|
||||
});"
|
||||
);
|
||||
|
||||
static::$loaded[__METHOD__][$sig] = true;
|
||||
|
||||
|
|
|
@ -263,7 +263,6 @@ abstract class JHtmlBootstrap
|
|||
$opt['constraints'] = isset($params['constraints']) ? $params['constraints'] : ['to' => 'scrollParent', 'attachment' => 'together', 'pin' => true];
|
||||
$opt['offset'] = isset($params['offset']) ? $params['offset'] : '0,0';
|
||||
|
||||
|
||||
$opt = (object) array_filter((array) $opt);
|
||||
|
||||
Factory::getDocument()->addScriptOptions('bootstrap.popover', array($selector => $opt));
|
||||
|
@ -356,7 +355,6 @@ abstract class JHtmlBootstrap
|
|||
$onHide = isset($params['onHide']) ? (string) $params['onHide'] : null;
|
||||
$onHidden = isset($params['onHidden']) ? (string) $params['onHidden'] : null;
|
||||
|
||||
|
||||
$opt = (object) array_filter((array) $opt);
|
||||
|
||||
Factory::getDocument()->addScriptOptions('bootstrap.tooltip', array($selector => $opt));
|
||||
|
|
|
@ -196,6 +196,7 @@ abstract class JHtmlCategory
|
|||
$item->title = str_repeat('- ', $repeat) . $item->title;
|
||||
static::$items[$hash][] = HTMLHelper::_('select.option', $item->id, $item->title);
|
||||
}
|
||||
|
||||
// Special "Add to root" option:
|
||||
static::$items[$hash][] = HTMLHelper::_('select.option', '1', Text::_('JLIB_HTML_ADD_TO_ROOT'));
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ abstract class JHtmlContent
|
|||
{
|
||||
$model = BaseDatabaseModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
|
||||
|
||||
foreach ($state as $key => $value)
|
||||
foreach ($state as $key => $value)
|
||||
{
|
||||
$model->setState($key, $value);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ abstract class JHtmlDraggablelist
|
|||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function draggable(string $tableId = '', string $formId = '', string $sortDir = 'asc', string $saveOrderingUrl = '',
|
||||
$redundant = null, bool $nestedList = false)
|
||||
$redundant = null, bool $nestedList = false
|
||||
)
|
||||
{
|
||||
// Only load once
|
||||
if (isset(static::$loaded[__METHOD__]))
|
||||
|
@ -74,9 +75,9 @@ abstract class JHtmlDraggablelist
|
|||
HTMLHelper::_('behavior.core');
|
||||
|
||||
// Attach draggable to document
|
||||
HTMLHelper::_('script', 'vendor/dragula/dragula.min.js', ['framework'=>false, 'relative'=>true]);
|
||||
HTMLHelper::_('script', 'system/draggable.min.js', ['framework'=>false, 'relative'=>true]);
|
||||
HTMLHelper::_('stylesheet', 'vendor/dragula/dragula.min.css', ['framework'=>false, 'relative'=>true, 'pathOnly'=>false]);
|
||||
HTMLHelper::_('script', 'vendor/dragula/dragula.min.js', ['framework' => false, 'relative' => true]);
|
||||
HTMLHelper::_('script', 'system/draggable.min.js', ['framework' => false, 'relative' => true]);
|
||||
HTMLHelper::_('stylesheet', 'vendor/dragula/dragula.min.css', ['framework' => false, 'relative' => true, 'pathOnly' => false]);
|
||||
|
||||
// Set static array
|
||||
static::$loaded[__METHOD__] = true;
|
||||
|
|
|
@ -348,7 +348,8 @@ abstract class JHtmlDropdown
|
|||
* @since 3.0
|
||||
*/
|
||||
public static function addCustomItem($label, $link = 'javascript:void(0)', $linkAttributes = '', $className = '', $ajaxLoad = false,
|
||||
$jsCallBackFunc = null)
|
||||
$jsCallBackFunc = null
|
||||
)
|
||||
{
|
||||
static::start();
|
||||
|
||||
|
|
|
@ -96,7 +96,6 @@ abstract class JHtmlFormbehavior
|
|||
// Options array to json options string
|
||||
$options_str = json_encode($options, ($debug && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false));
|
||||
|
||||
|
||||
Factory::getDocument()->addScriptDeclaration(
|
||||
"
|
||||
jQuery(document).ready(function (){
|
||||
|
|
|
@ -42,7 +42,8 @@ abstract class JHtmlJGrid
|
|||
* @since 1.6
|
||||
*/
|
||||
public static function action($i, $task, $prefix = '', $active_title = '', $inactive_title = '', $tip = false, $active_class = '',
|
||||
$inactive_class = '', $enabled = true, $translate = true, $checkbox = 'cb', $formId = null)
|
||||
$inactive_class = '', $enabled = true, $translate = true, $checkbox = 'cb', $formId = null
|
||||
)
|
||||
{
|
||||
if (is_array($prefix))
|
||||
{
|
||||
|
@ -171,7 +172,8 @@ abstract class JHtmlJGrid
|
|||
* @since 1.6
|
||||
*/
|
||||
public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null,
|
||||
$formId = null)
|
||||
$formId = null
|
||||
)
|
||||
{
|
||||
if (is_array($prefix))
|
||||
{
|
||||
|
@ -410,7 +412,8 @@ abstract class JHtmlJGrid
|
|||
* @since 1.6
|
||||
*/
|
||||
public static function orderDown($i, $task = 'orderdown', $prefix = '', $text = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb',
|
||||
$formId = null)
|
||||
$formId = null
|
||||
)
|
||||
{
|
||||
if (is_array($prefix))
|
||||
{
|
||||
|
|
|
@ -119,7 +119,7 @@ abstract class JHtmlJquery
|
|||
$doc = Factory::getDocument();
|
||||
|
||||
$doc->addScriptDeclaration(
|
||||
<<<JS
|
||||
<<<JS
|
||||
;(function ($) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
|
|
|
@ -234,7 +234,8 @@ abstract class JHtmlList
|
|||
* @since 1.5
|
||||
*/
|
||||
public static function positions($name, $active = null, $javascript = null, $none = true, $center = true, $left = true, $right = true,
|
||||
$id = false)
|
||||
$id = false
|
||||
)
|
||||
{
|
||||
$pos = array();
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ abstract class JHtmlSearchtools
|
|||
* @return string
|
||||
*/
|
||||
public static function sort($title, $order, $direction = 'asc', $selected = 0, $task = null, $new_direction = 'asc', $tip = '', $icon = null,
|
||||
$formName = 'adminForm')
|
||||
$formName = 'adminForm'
|
||||
)
|
||||
{
|
||||
$direction = strtolower($direction);
|
||||
$orderIcons = array('icon-arrow-up-3', 'icon-arrow-down-3');
|
||||
|
|
|
@ -92,7 +92,8 @@ abstract class JHtmlSelect
|
|||
* @since 1.5
|
||||
*/
|
||||
public static function genericlist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false,
|
||||
$translate = false)
|
||||
$translate = false
|
||||
)
|
||||
{
|
||||
// Set default options
|
||||
$options = array_merge(HTMLHelper::$formatOptions, array('format.depth' => 0, 'id' => false));
|
||||
|
@ -682,7 +683,8 @@ abstract class JHtmlSelect
|
|||
* @since 1.5
|
||||
*/
|
||||
public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false,
|
||||
$translate = false)
|
||||
$translate = false
|
||||
)
|
||||
{
|
||||
|
||||
if (is_array($attribs))
|
||||
|
|
|
@ -53,6 +53,7 @@ abstract class JHtmlUiTab
|
|||
|
||||
// @TODO echo the recall attribute correctly, now it's hardcoded!!!
|
||||
$recall = !isset($params['recall']) ? '' : 'recall';
|
||||
|
||||
return '<joomla-tab id="' . $selector . '" recall>';
|
||||
}
|
||||
|
||||
|
|
|
@ -38,21 +38,21 @@ abstract class JHtmlWorkflowstage
|
|||
|
||||
// Build the query.
|
||||
$query->select(
|
||||
$db->quoteName(
|
||||
[
|
||||
'ws.id',
|
||||
'ws.title',
|
||||
'w.id',
|
||||
'w.title'
|
||||
],
|
||||
[
|
||||
'workflow_stage_id',
|
||||
'workflow_stage_title',
|
||||
'workflow_id',
|
||||
'workflow_title'
|
||||
]
|
||||
)
|
||||
)
|
||||
$db->quoteName(
|
||||
[
|
||||
'ws.id',
|
||||
'ws.title',
|
||||
'w.id',
|
||||
'w.title'
|
||||
],
|
||||
[
|
||||
'workflow_stage_id',
|
||||
'workflow_stage_title',
|
||||
'workflow_id',
|
||||
'workflow_title'
|
||||
]
|
||||
)
|
||||
)
|
||||
->from($db->quoteName('#__workflow_stages', 'ws'))
|
||||
->leftJoin($db->quoteName('#__workflows', 'w') . ' ON w.id = ws.workflow_id')
|
||||
->where('w.published = 1')
|
||||
|
|
|
@ -29,7 +29,7 @@ class JNamespacePsr4Map
|
|||
/**
|
||||
* Check if the file exists
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ class JNamespacePsr4Map
|
|||
/**
|
||||
* Create the namespace file
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
@ -80,7 +80,7 @@ class JNamespacePsr4Map
|
|||
/**
|
||||
* Load the PSR4 file
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
@ -224,8 +224,8 @@ class JNamespacePsr4Map
|
|||
// Add the application specific segment when not a plugin
|
||||
if (strpos($dir, '/plugins/') !== 0)
|
||||
{
|
||||
$baseDir = strpos($namespacePath, 'administrator/') ? 'JPATH_ADMINISTRATOR . \'' : 'JPATH_SITE . \'';
|
||||
$namespace .= strpos($namespacePath, 'administrator/') ? 'Administrator\\\\' : 'Site\\\\';
|
||||
$baseDir = strpos($namespacePath, 'administrator/') ? 'JPATH_ADMINISTRATOR . \'' : 'JPATH_SITE . \'';
|
||||
$namespace .= strpos($namespacePath, 'administrator/') ? 'Administrator\\\\' : 'Site\\\\';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user