-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from HydraWiki/develop
Switch to Squiz standards for comment formatting
- Loading branch information
Showing
11 changed files
with
179 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
* File: MediaWiki/Sniffs/Commenting/LicenseCommentSniff.php | ||
* From repository: https://github.com/wikimedia/mediawiki-tools-codesniffer | ||
* | ||
* @package HydraWiki | ||
* @author Dieser Benutzer | ||
* @author Samuel Hilson <[email protected]> | ||
* @package HydraWiki | ||
* @author Dieser Benutzer | ||
* @author Samuel Hilson <[email protected]> | ||
* @copyright https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/COPYRIGHT | ||
* @license https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/LICENSE GPL-2.0-or-later | ||
* @license https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/LICENSE GPL-2.0-or-later | ||
*/ | ||
namespace HydraWiki\Sniffs\Commenting; | ||
|
||
|
@@ -20,12 +20,32 @@ | |
use PHP_CodeSniffer\Sniffs\Sniff; | ||
|
||
class LicenseCommentSniff implements Sniff { | ||
|
||
/** | ||
* Container for File class | ||
* | ||
* @var File | ||
*/ | ||
private $file; | ||
|
||
/** | ||
* Container for tokens array | ||
* | ||
* @var array | ||
*/ | ||
private $tokens; | ||
|
||
/** | ||
* End pointer | ||
* | ||
* @var integer | ||
*/ | ||
private $end; | ||
|
||
/** @var SpdxLicenses */ | ||
/** | ||
* Container for SpdxLicense class | ||
* | ||
* @var SpdxLicenses | ||
*/ | ||
private $spdx = null; | ||
|
||
/** | ||
|
@@ -51,9 +71,10 @@ public function register() { | |
/** | ||
* Initialize | ||
* | ||
* @param File $phpcsFile | ||
* @param int $stackPtr | ||
* @param File $phpcsFile | ||
* @param integer $stackPtr | ||
* @param SpdxLicenses|null $spdx | ||
* | ||
* @return void | ||
*/ | ||
public function initialize(File $phpcsFile, $stackPtr, SpdxLicenses $spdx = null) { | ||
|
@@ -68,8 +89,9 @@ public function initialize(File $phpcsFile, $stackPtr, SpdxLicenses $spdx = null | |
/** | ||
* Processes this test, when one of its tokens is encountered. | ||
* | ||
* @param File $phpcsFile The file being scanned. | ||
* @param int $stackPtr The position of the current token in the stack passed in $tokens. | ||
* @param 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(File $phpcsFile, $stackPtr) { | ||
|
@@ -81,10 +103,11 @@ public function process(File $phpcsFile, $stackPtr) { | |
} | ||
|
||
/** | ||
* handle a single doc line | ||
* Handle a single doc line | ||
* | ||
* @param string $tag | ||
* @return mixed | ||
* | ||
* @return void | ||
*/ | ||
private function processDocTag($tag) { | ||
if ($this->isCorrectTag($tag)) { | ||
|
@@ -119,7 +142,7 @@ private function processDocTag($tag) { | |
} | ||
|
||
/** | ||
* get or initialize SpdxLicenses library | ||
* Get or initialize SpdxLicenses library | ||
* | ||
* @return SpdxLicenses | ||
*/ | ||
|
@@ -131,25 +154,27 @@ private function getLicenseValidator() { | |
} | ||
|
||
/** | ||
* normalize license text | ||
* Normalize license text | ||
* | ||
* @param string $next | ||
* | ||
* @return string | ||
*/ | ||
private function getLicenseFromTag($next) { | ||
$license = $this->tokens[$next]['content']; | ||
|
||
// license can contain a url, use the text behind it | ||
// License can contain a url, use the text behind it | ||
if (preg_match('/^https?:\/\/[^\s]+\s+(.*)/', $license, $match)) { | ||
$license = $match[1]; | ||
} | ||
return $license; | ||
} | ||
|
||
/** | ||
* check if we are on the correct license tag | ||
* Check if we are on the correct license tag | ||
* | ||
* @param string $tag | ||
* | ||
* @return boolean | ||
*/ | ||
private function isCorrectTag($tag) { | ||
|
@@ -174,10 +199,11 @@ private function isCorrectTag($tag) { | |
} | ||
|
||
/** | ||
* check the tag location is in file level doc comment | ||
* Check the tag location is in file level doc comment | ||
* | ||
* @param string $tag | ||
* @return boolean | ||
* | ||
* @return void | ||
*/ | ||
private function isValidTagLocation($tag) { | ||
if ($this->tokens[$tag]['level'] !== 0) { | ||
|
@@ -190,10 +216,11 @@ private function isValidTagLocation($tag) { | |
} | ||
|
||
/** | ||
* check that tag has some text after @license | ||
* Check that tag has some text after @license | ||
* | ||
* @param string $tag | ||
* @param string $next | ||
* | ||
* @return boolean | ||
*/ | ||
private function hasTextAfterTag($tag, $next) { | ||
|
@@ -208,9 +235,10 @@ private function hasTextAfterTag($tag, $next) { | |
} | ||
|
||
/** | ||
* check for a private license | ||
* Check for a private license | ||
* | ||
* @param string $license | ||
* | ||
* @return boolean | ||
*/ | ||
private function isValidProprietaryLicense($license) { | ||
|
@@ -220,10 +248,11 @@ private function isValidProprietaryLicense($license) { | |
} | ||
|
||
/** | ||
* check if the license is marked as deprecated | ||
* Check if the license is marked as deprecated | ||
* | ||
* @param string $tag | ||
* @param string $license | ||
* | ||
* @return boolean | ||
*/ | ||
private function isLicenseDeprecated($tag, $license) { | ||
|
@@ -244,12 +273,13 @@ private function isLicenseDeprecated($tag, $license) { | |
} | ||
|
||
/** | ||
* checks that the license is a valid license from spdx | ||
* Checks that the license is a valid license from spdx | ||
* | ||
* @param string $tag | ||
* @param string $next | ||
* @param string $license | ||
* @return boolean | ||
* | ||
* @return void | ||
*/ | ||
private function handleInvalidLicense($tag, $next, $license) { | ||
// Initialize the spdx license validator | ||
|
@@ -273,7 +303,7 @@ private function handleInvalidLicense($tag, $next, $license) { | |
} | ||
} | ||
|
||
// handle fixable license problem | ||
// Handle fixable license problem | ||
if ($fixable !== null) { | ||
$fix = $this->file->addFixableWarning( | ||
'Invalid SPDX license identifier "%s", see <https://spdx.org/licenses/>', | ||
|
@@ -287,7 +317,7 @@ private function handleInvalidLicense($tag, $next, $license) { | |
return; | ||
} | ||
|
||
// report un-fixable problems | ||
// Report un-fixable problems | ||
$this->file->addWarning( | ||
'Invalid SPDX license identifier "%s", see <https://spdx.org/licenses/>', | ||
$tag, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
* | ||
* Ensures there is no space after a NOT operator. | ||
* | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @author Samuel Hilson <[email protected]> | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @author Samuel Hilson <[email protected]> | ||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD-3-Clause | ||
*/ | ||
|
@@ -45,9 +45,9 @@ public function register() { | |
/** | ||
* Processes this test, when one of its tokens is encountered. | ||
* | ||
* @param File $phpcsFile The file being scanned. | ||
* @param int $stackPtr The position of the current token in | ||
* the stack passed in $tokens. | ||
* @param File $phpcsFile The file being scanned. | ||
* @param integer $stackPtr The position of the current token in | ||
* the stack passed in $tokens. | ||
* | ||
* @return void | ||
*/ | ||
|
Oops, something went wrong.