/* Decoded by unphp.net */ array("required" => true, "allow_multiple" => false), "@package" => array("required" => true, "allow_multiple" => false), "@subpackage" => array("required" => false, "allow_multiple" => false), "@author" => array("required" => true, "allow_multiple" => true), "@copyright" => array("required" => false, "allow_multiple" => true), "@license" => array("required" => true, "allow_multiple" => false), "@version" => array("required" => false, "allow_multiple" => false), "@link" => array("required" => true, "allow_multiple" => true), "@see" => array("required" => false, "allow_multiple" => true), "@since" => array("required" => false, "allow_multiple" => false), "@deprecated" => array("required" => false, "allow_multiple" => false)); public function register() { return array(T_OPEN_TAG); } public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $commentStart = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); if ($tokens[$commentStart]["code"] === T_DECLARE) { $semicolon = $phpcsFile->findNext(T_SEMICOLON, $commentStart + 1); $commentStart = $phpcsFile->findNext(T_WHITESPACE, $semicolon + 1, null, true); } 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) { return $phpcsFile->numTokens + 1; } else { if ($tokens[$commentStart]["code"] === T_COMMENT) { $error = "You must use "/**" style comments for a file comment"; $phpcsFile->addError($error, $errorToken, "WrongStyle"); $phpcsFile->recordMetric($stackPtr, "File has doc comment", "yes"); return $phpcsFile->numTokens + 1; } else { if ($commentStart === false || $tokens[$commentStart]["code"] !== T_DOC_COMMENT_OPEN_TAG) { $phpcsFile->addError("Missing file doc comment", $errorToken, "Missing"); $phpcsFile->recordMetric($stackPtr, "File has doc comment", "no"); return $phpcsFile->numTokens + 1; } } } $commentEnd = $tokens[$commentStart]["comment_closer"]; for ($nextToken = $commentEnd + 1; $nextToken < $phpcsFile->numTokens; $nextToken++) { if ($tokens[$nextToken]["code"] === T_WHITESPACE) { continue; } if ($tokens[$nextToken]["code"] === T_ATTRIBUTE && isset($tokens[$nextToken]["attribute_closer"]) === true) { $nextToken = $tokens[$nextToken]["attribute_closer"]; continue; } break; } if ($nextToken === $phpcsFile->numTokens) { $nextToken--; } $ignore = array(T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM, T_FUNCTION, T_CLOSURE, T_PUBLIC, T_PRIVATE, T_PROTECTED, T_FINAL, T_STATIC, T_ABSTRACT, T_READONLY, T_CONST, T_PROPERTY); if (in_array($tokens[$nextToken]["code"], $ignore, true) === true) { $phpcsFile->addError("Missing file doc comment", $stackPtr, "Missing"); $phpcsFile->recordMetric($stackPtr, "File has doc comment", "no"); return $phpcsFile->numTokens + 1; } $phpcsFile->recordMetric($stackPtr, "File has doc comment", "yes"); $found = false; for ($i = $commentStart + 1; $i < $commentEnd; $i++) { if ($tokens[$i]["code"] === T_DOC_COMMENT_TAG) { break; } else { if ($tokens[$i]["code"] === T_DOC_COMMENT_STRING && strstr(strtolower($tokens[$i]["content"]), "php version") !== false) { $found = true; break; } } } if ($found === false) { $error = "PHP version not specified"; $phpcsFile->addWarning($error, $commentEnd, "MissingVersion"); } $this->processTags($phpcsFile, $stackPtr, $commentStart); return $phpcsFile->numTokens + 1; } protected function processTags($phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); if (get_class($this) === "PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff") { $docBlock = "file"; } else { $docBlock = "class"; } $commentEnd = $tokens[$commentStart]["comment_closer"]; $foundTags = array(); $tagTokens = array(); foreach ($tokens[$commentStart]["comment_tags"] as $tag) { $name = $tokens[$tag]["content"]; if (isset($this->tags[$name]) === false) { continue; } if ($this->tags[$name]["allow_multiple"] === false && isset($tagTokens[$name]) === true) { $error = "Only one %s tag is allowed in a %s comment"; $data = array($name, $docBlock); $phpcsFile->addError($error, $tag, "Duplicate" . ucfirst(substr($name, 1)) . "Tag", $data); } $foundTags[] = $name; $tagTokens[$name][] = $tag; $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); if ($string === false || $tokens[$string]["line"] !== $tokens[$tag]["line"]) { $error = "Content missing for %s tag in %s comment"; $data = array($name, $docBlock); $phpcsFile->addError($error, $tag, "Empty" . ucfirst(substr($name, 1)) . "Tag", $data); continue; } } $pos = 0; foreach ($this->tags as $tag => $tagData) { if (isset($tagTokens[$tag]) === false) { if ($tagData["required"] === true) { $error = "Missing %s tag in %s comment"; $data = array($tag, $docBlock); $phpcsFile->addError($error, $commentEnd, "Missing" . ucfirst(substr($tag, 1)) . "Tag", $data); } continue; } else { $method = "process" . substr($tag, 1); if (method_exists($this, $method) === true) { call_user_func(array($this, $method), $phpcsFile, $tagTokens[$tag]); } } if (isset($foundTags[$pos]) === false) { break; } if ($foundTags[$pos] !== $tag) { $error = "The tag in position %s should be the %s tag"; $data = array($pos + 1, $tag); $phpcsFile->addError($error, $tokens[$commentStart]["comment_tags"][$pos], ucfirst(substr($tag, 1)) . "TagOrder", $data); } $pos++; while (isset($foundTags[$pos]) === true && $foundTags[$pos] === $tag) { $pos++; } } } protected function processCategory($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; if (Common::isUnderscoreName($content) !== true) { $newContent = str_replace(" ", "_", $content); $nameBits = explode("_", $newContent); $firstBit = array_shift($nameBits); $newName = ucfirst($firstBit) . "_"; foreach ($nameBits as $bit) { if ($bit !== '') { $newName .= ucfirst($bit) . "_"; } } $error = "Category name "%s" is not valid; consider "%s" instead"; $validName = trim($newName, "_"); $data = array($content, $validName); $phpcsFile->addError($error, $tag, "InvalidCategory", $data); } } } protected function processPackage($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; if (Common::isUnderscoreName($content) === true) { continue; } $newContent = str_replace(" ", "_", $content); $newContent = trim($newContent, "_"); $newContent = preg_replace("/[^A-Za-z_]/", '', $newContent); if ($newContent === '') { $error = "Package name "%s" is not valid"; $data = array($content); $phpcsFile->addError($error, $tag, "InvalidPackageValue", $data); } else { $nameBits = explode("_", $newContent); $firstBit = array_shift($nameBits); $newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . "_"; foreach ($nameBits as $bit) { if ($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); $phpcsFile->addError($error, $tag, "InvalidPackage", $data); } } } protected function processSubpackage($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; if (Common::isUnderscoreName($content) === true) { continue; } $newContent = str_replace(" ", "_", $content); $nameBits = explode("_", $newContent); $firstBit = array_shift($nameBits); $newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . "_"; foreach ($nameBits as $bit) { if ($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); $phpcsFile->addError($error, $tag, "InvalidSubpackage", $data); } } protected function processAuthor($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; $local = "\da-zA-Z-_+"; $localMiddle = $local . ".\w"; if (preg_match("/^([^<]*)\s+<([" . $local . "]([" . $localMiddle . "]*[" . $local . "])*@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,})>$/", $content) === 0) { $error = "Content of the @author tag must be in the form "Display Name ""; $phpcsFile->addError($error, $tag, "InvalidAuthors"); } } } protected function processCopyright($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; $matches = array(); if (preg_match("/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/", $content, $matches) !== 0) { if ($matches[3] !== '' && $matches[3] !== null) { if ($matches[3] !== "-") { $error = "A hyphen must be used between the earliest and latest year"; $phpcsFile->addError($error, $tag, "CopyrightHyphen"); } if ($matches[4] !== '' && $matches[4] !== null && $matches[4] < $matches[1]) { $error = "Invalid year span "{$matches["1"]}{$matches["3"]}{$matches["4"]}" found; consider "{$matches["4"]}-{$matches["1"]}" instead"; $phpcsFile->addWarning($error, $tag, "InvalidCopyright"); } } } else { $error = "@copyright tag must contain a year and the name of the copyright holder"; $phpcsFile->addError($error, $tag, "IncompleteCopyright"); } } } protected function processLicense($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; $matches = array(); preg_match("/^([^\s]+)\s+(.*)/", $content, $matches); if (count($matches) !== 3) { $error = "@license tag must contain a URL and a license name"; $phpcsFile->addError($error, $tag, "IncompleteLicense"); } } } protected function processVersion($phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { if ($tokens[$tag + 2]["code"] !== T_DOC_COMMENT_STRING) { continue; } $content = $tokens[$tag + 2]["content"]; if (strstr($content, "CVS:") === false && strstr($content, "SVN:") === false && strstr($content, "GIT:") === false && strstr($content, "HG:") === false) { $error = "Invalid version "%s" in file comment; consider "CVS: " or "SVN: " or "GIT: " or "HG: " instead"; $data = array($content); $phpcsFile->addWarning($error, $tag, "InvalidVersion", $data); } } } } ?>