Fix _ protected names #502

Merged
merged 1 commit into from Nov 10, 2011
@@ -75,7 +75,6 @@ public function __construct()
}//end __construct()
-
/**
* Processes the tokens within the scope.
*
@@ -124,6 +123,36 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
$scope = $methodProps['scope'];
$scopeSpecified = $methodProps['scope_specified'];
+ // Detect if it is marked deprecated
+ $find = array(
+ T_COMMENT,
+ T_DOC_COMMENT,
+ T_CLASS,
+ T_FUNCTION,
+ T_OPEN_TAG,
+ );
+ $tokens = $phpcsFile->getTokens();
+ $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1));
+ if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_DOC_COMMENT) {
+ $commentStart = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1;
+ $comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
+
+ 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;
+ }
+
+ $deprecated = $this->commentParser->getDeprecated();
+ return !is_null($deprecated);
+ }
+ else {
+ return false;
+ }
+
// If it's a private method, it must have an underscore on the front.
if ($isPublic === false && $methodName{0} !== '_') {
$error = 'Private method name "%s" must be prefixed with an underscore';
@@ -132,7 +161,7 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
}
// If it's not a private method, it must not have an underscore on the front.
- if ($isPublic === true && $scopeSpecified === true && $methodName{0} === '_') {
+ if ($isDeprecated === false && $isPublic === true && $scopeSpecified === true && $methodName{0} === '_') {
$error = '%s method name "%s" must not be prefixed with an underscore';
$data = array(
ucfirst($scope),
@@ -153,7 +182,7 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
$testMethodName = substr($methodName, 1);
}
- if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
+ if ($isDeprecated === false && PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
if ($scopeSpecified === true) {
$error = '%s method name "%s" is not in camel caps format';
$data = array(
@@ -58,6 +58,36 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
+ // Detect if it is marked deprecated
+ $find = array(
+ T_COMMENT,
+ T_DOC_COMMENT,
+ T_CLASS,
+ T_FUNCTION,
+ T_OPEN_TAG,
+ );
+ $tokens = $phpcsFile->getTokens();
+ $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1));
+ if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_DOC_COMMENT) {
+ $commentStart = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1;
+ $comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
+
+ 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;
+ }
+
+ $deprecated = $this->commentParser->getDeprecated();
+ $isDeprecated = !is_null($deprecated);
+ }
+ else {
+ $isDeprecated = false;
+ }
+
// If it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName{0} !== '_') {
$error = 'Private member variable "%s" must be prefixed with an underscore';
@@ -67,7 +97,7 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
// If it's not a private member, it must not have an underscore on the front.
- if ($isPublic === true && $scopeSpecified === true && $memberName{0} === '_') {
+ if ($isDeprecated === false && $isPublic === true && $scopeSpecified === true && $memberName{0} === '_') {
$error = '%s member variable "%s" must not be prefixed with an underscore';
$data = array(
ucfirst($scope),
@@ -129,7 +129,7 @@ public static function getConfig($file = null, $type = 'PHP')
$file = JPATH_PLATFORM . '/config.php';
}
- self::$config = self::_createConfig($file, $type);
+ self::$config = self::createConfig($file, $type);
}
return self::$config;
@@ -151,7 +151,7 @@ public static function getSession($options = array())
{
if (!self::$session)
{
- self::$session = self::_createSession($options);
+ self::$session = self::createSession($options);
}
return self::$session;
@@ -171,7 +171,7 @@ public static function getLanguage()
{
if (!self::$language)
{
- self::$language = self::_createLanguage();
+ self::$language = self::createLanguage();
}
return self::$language;
@@ -191,7 +191,7 @@ public static function getDocument()
{
if (!self::$document)
{
- self::$document = self::_createDocument();
+ self::$document = self::createDocument();
}
return self::$document;
@@ -314,7 +314,7 @@ public static function getDbo()
$conf = self::getConfig();
$debug = $conf->get('debug');
- self::$database = self::_createDbo();
+ self::$database = self::createDbo();
self::$database->debug($debug);
}
@@ -335,7 +335,7 @@ public static function getMailer()
{
if (!self::$mailer)
{
- self::$mailer = self::_createMailer();
+ self::$mailer = self::createMailer();
}
$copy = clone self::$mailer;
@@ -582,9 +582,29 @@ public static function getDate($time = 'now', $tzOffset = null)
*
* @see JRegistry
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createConfig($file, $type = 'PHP', $namespace = '')
{
+ JLog::add(__METHOD__ . '() is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createConfig($file, $type, $namespace);
+ }
+
+ /**
+ * Create a configuration object
+ *
+ * @param string $file The path to the configuration file.
+ * @param string $type The type of the configuration file.
+ * @param string $namespace The namespace of the configuration file.
+ *
+ * @return JRegistry
+ *
+ * @see JRegistry
+ * @since 11.1
+ */
+ protected static function createConfig($file, $type = 'PHP', $namespace = '')
+ {
jimport('joomla.registry.registry');
if (is_file($file))
@@ -622,9 +642,26 @@ protected static function _createConfig($file, $type = 'PHP', $namespace = '')
* @return JSession object
*
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createSession($options = array())
{
+ JLog::add(__METHOD__ . '() is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createSession($options);
+ }
+
+ /**
+ * Create a session object
+ *
+ * @param array $options An array containing session options
+ *
+ * @return JSession object
+ *
+ * @since 11.1
+ */
+ protected static function createSession($options = array())
+ {
jimport('joomla.session.session');
// Get the editor configuration setting
@@ -650,9 +687,25 @@ protected static function _createSession($options = array())
*
* @see JDatabase
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createDbo()
{
+ JLog::add(__METHOD__ . '() is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createDbo();
+ }
+
+ /**
+ * Create an database object
+ *
+ * @return JDatabase object
+ *
+ * @see JDatabase
+ * @since 11.1
+ */
+ protected static function createDbo()
+ {
jimport('joomla.database.database');
jimport('joomla.database.table');
@@ -696,9 +749,25 @@ protected static function _createDbo()
*
* @see JMail
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createMailer()
{
+ JLog::add(__METHOD__ . '() is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createMailer();
+ }
+
+ /**
+ * Create a mailer object
+ *
+ * @return JMail object
+ *
+ * @see JMail
+ * @since 11.1
+ */
+ protected static function createMailer()
+ {
jimport('joomla.mail.mail');
$conf = self::getConfig();
@@ -746,9 +815,25 @@ protected static function _createMailer()
*
* @see JLanguage
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createLanguage()
{
+ JLog::add(__METHOD__ . ' is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createLanguage();
+ }
+
+ /**
+ * Create a language object
+ *
+ * @return JLanguage object
+ *
+ * @see JLanguage
+ * @since 11.1
+ */
+ protected static function createLanguage()
+ {
jimport('joomla.language.language');
$conf = self::getConfig();
@@ -766,9 +851,25 @@ protected static function _createLanguage()
*
* @see JDocument
* @since 11.1
+ * @deprecated 12.3
*/
protected static function _createDocument()
{
+ JLog::add(__METHOD__ . ' is deprecated.', JLog::WARNING, 'deprecated');
+
+ return self::createDocument();
+ }
+
+ /**
+ * Create a document object
+ *
+ * @return JDocument object
+ *
+ * @see JDocument
+ * @since 11.1
+ */
+ protected static function createDocument()
+ {
jimport('joomla.document.document');
$lang = self::getLanguage();