Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates Sniffs to be compatible with PHP_CodeSniffer 3.0 and higher. #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015-2017, Barracuda Networks, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
<?php
/**
* This sniff prohibits the use of single line multi line comments
* This sniff prohibits the use of single line block comments
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ryan Matthews <[email protected]>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version 1.0.00
* @link http://pear.php.net/package/PHP_CodeSniffer
* @license BSD License 2.0, see LICENSE file.
* @version 2.0.00
* @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/
*/

namespace Barracuda\Sniffs\Commenting;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

/**
* This sniff prohibits the use of Perl style hash comments.
*
* An example of a hash comment is:
*
* <code>
* /* This is a single line multi line comment, which is prohibited. */
/* $hello = 'hello';
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ryan Matthews <[email protected]>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.0.00
* @link http://pear.php.net/package/PHP_CodeSniffer
* Prohibits single line block comments.
*/
class Barracuda_Sniffs_Commenting_DisallowSingleLineMultiCommentsSniff implements PHP_CodeSniffer_Sniff
class DisallowSingleLineMultiCommentsSniff implements Sniff
{


Expand All @@ -48,13 +39,12 @@ public function register()
/**
* Processes the tokens that this sniff is interested in.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
* @param int $stackPtr The position in the stack where
* the token was found.
* @param File $phpcsFile The file where the token was found.
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (preg_match('/\/\*[^\n]*\*\//', $tokens[$stackPtr]['content']))
Expand All @@ -67,4 +57,3 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}// end process()
}
// end class

77 changes: 48 additions & 29 deletions PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
<?php

class Barracuda_Sniffs_Commenting_DocCommentSniff implements PHP_CodeSniffer_Sniff
/**
* This sniff controls requirements for PHP doc blocks.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Daniel Bergey <[email protected]>
* @license BSD License 2.0, see LICENSE file.
* @version 2.0.00
* @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/
*/

namespace Barracuda\Sniffs\Commenting;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Common;

/**
* Controls requirements for PHP doc blocks.
*/
class DocCommentSniff implements Sniff
{

/**
Expand Down Expand Up @@ -71,13 +92,12 @@ public function register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_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 int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return int
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand Down Expand Up @@ -156,14 +176,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
/**
* Processes each required or optional tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $commentStart Position in the stack where the comment started.
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param int $commentStart Position in the stack where the comment started.
*
* @return void
*/
protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
protected function processTags(File $phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();

Expand Down Expand Up @@ -255,12 +274,12 @@ protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $comm
/**
* Process the category tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
* @param File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags)
protected function processCategory(File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
Expand All @@ -270,7 +289,7 @@ protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags)
}

$content = $tokens[($tag + 2)]['content'];
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
if (Common::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
Expand All @@ -297,12 +316,12 @@ protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags)
/**
* Process the package tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
* @param File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
protected function processPackage(File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
Expand All @@ -312,7 +331,7 @@ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
}

$content = $tokens[($tag + 2)]['content'];
if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
if (Common::isUnderscoreName($content) === true) {
continue;
}

Expand Down Expand Up @@ -343,12 +362,12 @@ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
/**
* Process the subpackage tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
* @param File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
protected function processSubpackage(File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
Expand All @@ -358,7 +377,7 @@ protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tag
}

$content = $tokens[($tag + 2)]['content'];
if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
if (Common::isUnderscoreName($content) === true) {
continue;
}

Expand Down Expand Up @@ -432,12 +451,12 @@ protected function processCopyrights($errorPos)
/**
* Process the license tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
* @param File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processLicense(PHP_CodeSniffer_File $phpcsFile, array $tags)
protected function processLicense(File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
Expand All @@ -461,12 +480,12 @@ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, array $tags)
/**
* Process the version tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
* @param File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processVersion(PHP_CodeSniffer_File $phpcsFile, array $tags)
protected function processVersion(File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
Expand Down
Loading