Skip to content

Commit

Permalink
Merge pull request #11 from HydraWiki/develop
Browse files Browse the repository at this point in the history
Switch to Squiz standards for comment formatting
  • Loading branch information
valeryan authored Jan 31, 2019
2 parents dd3e10b + ce212aa commit 658bf67
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 71 deletions.
31 changes: 17 additions & 14 deletions HydraWiki/Sniffs/Arrays/NoExtraSpacesSingleLineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace HydraWiki\Sniffs\Arrays;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractArraySniff;

class NoExtraSpacesSingleLineSniff extends AbstractArraySniff {
Expand All @@ -30,11 +31,11 @@ class NoExtraSpacesSingleLineSniff extends AbstractArraySniff {
/**
* Processes a single-line array definition.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param int $arrayStart The token that starts the array definition.
* @param int $arrayEnd The token that ends the array definition.
* @param array $indices An array of token positions for the array keys, double arrows, and values.
* @param File $phpcsFile The current file being checked.
* @param integer $stackPtr The position of the current token in the stack passed in $tokens.
* @param integer $arrayStart The token that starts the array definition.
* @param integer $arrayEnd The token that ends the array definition.
* @param array $indices An array of token positions for the array keys, double arrows, and values.
*
* @return void
*/
Expand All @@ -46,11 +47,11 @@ public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arra
/**
* Processes a multi-line array definition.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param int $arrayStart The token that starts the array definition.
* @param int $arrayEnd The token that ends the array definition.
* @param array $indices An array of token positions for the array keys, double arrows, and values.
* @param File $phpcsFile The current file being checked.
* @param integer $stackPtr The position of the current token in the stack passed in $tokens.
* @param integer $arrayStart The token that starts the array definition.
* @param integer $arrayEnd The token that ends the array definition.
* @param array $indices An array of token positions for the array keys, double arrows, and values.
*
* @return void
*/
Expand All @@ -61,8 +62,9 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
/**
* Process the starting brace of a short array
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $arrayStart
* @param File $phpcsFile
* @param integer $arrayStart
*
* @return void
*/
private function handleArrayStart($phpcsFile, $arrayStart) {
Expand All @@ -84,8 +86,9 @@ private function handleArrayStart($phpcsFile, $arrayStart) {
/**
* Process the closing brace of a short array
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $arrayEnd
* @param File $phpcsFile
* @param integer $arrayEnd
*
* @return void
*/
private function handleArrayEnd($phpcsFile, $arrayEnd) {
Expand Down
80 changes: 55 additions & 25 deletions HydraWiki/Sniffs/Commenting/LicenseCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

/**
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -119,7 +142,7 @@ private function processDocTag($tag) {
}

/**
* get or initialize SpdxLicenses library
* Get or initialize SpdxLicenses library
*
* @return SpdxLicenses
*/
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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/>',
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions HydraWiki/Sniffs/WhiteSpace/NoSpaceAfterNotSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit 658bf67

Please sign in to comment.