Skip to content
Browse files

Fixed bug #19612 : Invalid @package suggestion

  • Loading branch information...
1 parent 1a102c1 commit a264699c38d7a42439bbc23f36a9c96ff64f68f3 @gsherwood gsherwood committed Sep 25, 2012
Showing with 30 additions and 23 deletions.
  1. +29 −23 CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
  2. +1 −0 package.xml
View
52 CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
@@ -584,32 +584,38 @@ protected function processCategory($errorPos)
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).'_';
- }
+ if ($package === null) {
+ return;
+ }
- $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');
- }
+ $content = $package->getContent();
+ if ($content === '') {
+ $error = '@package tag must contain a name';
+ $this->currentFile->addError($error, $errorPos, 'EmptyPackage');
+ return;
}
+ if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
+ return;
+ }
+
+ $newContent = str_replace(' ', '_', $content);
+ $newContent = preg_replace('/[^A-Za-z_]/', '', $newContent);
+ $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);
+
}//end processPackage()
View
1 package.xml
@@ -49,6 +49,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Pete Walker for the patch
- Fixed bug #19538 : Function indentation code sniffer checks inside short arrays
- Fixed bug #19565 : Non-Executable Code Sniff Broken for Case Statements with both return and break
+ - Fixed bug #19612 : Invalid @package suggestion
</notes>
<contents>
<dir name="/">

0 comments on commit a264699

Please sign in to comment.
Something went wrong with that request. Please try again.