Skip to content

Commit

Permalink
Merge pull request #4 from traderinteractive/build-updates
Browse files Browse the repository at this point in the history
Build updates
  • Loading branch information
chrisryan authored Jun 15, 2023
2 parents e8c53a9 + f2566f3 commit e6bd031
Show file tree
Hide file tree
Showing 37 changed files with 233 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
12 changes: 8 additions & 4 deletions DWS/Helpers/Array.php → DWS/Helpers/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@
* @subpackage Helpers
*/

namespace DWS\Helpers;

use PHP_CodeSniffer\Files\File;

/**
* A collection of helper methods for arrays.
*
* @package DWS
* @subpackage Helpers
*/
final class DWS_Helpers_Array
final class Arrays
{
/**
* Returns the positions of all of the commas that belong to the array beginning at $arrayStart.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the array is declared.
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the array is declared.
* @param int $arrayStart The position of the opening parenthesis or bracket for the array in the file.
*
* @return array The stack pointers for all of the commas in the array (excluding commas in nested arrays, functions, etc.).
*/
public static function commaPositions(PHP_CodeSniffer_File $phpcsFile, $arrayStart)
public static function commaPositions(File $phpcsFile, $arrayStart)
{
$tokens = $phpcsFile->getTokens();
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $arrayStart);
$arrayEnd = Bracket::bracketEnd($phpcsFile, $arrayStart);

$commas = [];
for ($i = $arrayStart + 1; $i <= $arrayEnd; $i++) {
Expand Down
14 changes: 9 additions & 5 deletions DWS/Helpers/Bracket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@
* @subpackage Helpers
*/

namespace DWS\Helpers;

use PHP_CodeSniffer\Files\File;

/**
* A collection of helper methods for bracketed expressions.
*
* @package DWS
* @subpackage Helpers
*/
final class DWS_Helpers_Bracket
final class Bracket
{
/**
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
*
* @return int The position of the opening bracket, or if not found, the given $stackPtr.
*/
public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public static function bracketStart(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (array_key_exists('parenthesis_opener', $tokens[$stackPtr])) {
Expand All @@ -37,12 +41,12 @@ public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
/**
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the ending bracket.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
*
* @return int The position of the ending bracket, or if not found, the given $stackPtr.
*/
public static function bracketEnd(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public static function bracketEnd(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (array_key_exists('parenthesis_closer', $tokens[$stackPtr])) {
Expand Down
17 changes: 11 additions & 6 deletions DWS/Helpers/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
* @subpackage Helpers
*/

namespace DWS\Helpers;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

/**
* A collection of helper methods for operators.
*
* @package DWS
* @subpackage Helpers
*/
final class DWS_Helpers_Operator
final class Operator
{
/**
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
*
* @return int The position of the opening bracket, or if not found, the given $stackPtr.
*/
public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public static function isUnary(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand All @@ -38,9 +43,9 @@ public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
$unaryHints = array_unique(
array_merge(
PHP_CodeSniffer_Tokens::$comparisonTokens,
PHP_CodeSniffer_Tokens::$operators,
PHP_CodeSniffer_Tokens::$assignmentTokens,
Tokens::$comparisonTokens,
Tokens::$operators,
Tokens::$assignmentTokens,
[
T_RETURN,
T_COMMA,
Expand Down
10 changes: 7 additions & 3 deletions DWS/Helpers/WhiteSpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@
* @subpackage Helpers
*/

namespace DWS\Helpers;

use PHP_CodeSniffer\Files\File;

/**
* A collection of helper methods for whitespace.
*
* @package DWS
* @subpackage Helpers
*/
final class DWS_Helpers_Whitespace
final class Whitespace
{
/**
* Returns the indentation level of the requested line.
*
* @param PHP_CodeSniffer_File $phpcsFile The file in question.
* @param PHP_CodeSniffer\Files\File $phpcsFile The file in question.
* @param int $stackPtr The stack pointer to the element on the line in question.
*
* @return int The normalized column number for the initial non-whitespace token on the line.
*/
public static function indentOfLine(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public static function indentOfLine(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$beginningElement = $stackPtr;
Expand Down
16 changes: 11 additions & 5 deletions DWS/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
* @subpackage Sniffs
*/

namespace DWS\Sniffs\Arrays;

use DWS\Helpers\Bracket;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

/**
* A test to ensure that arrays conform to the array coding standard.
*
* @package DWS
* @subpackage Sniffs
*/
final class DWS_Sniffs_Arrays_ArrayDeclarationSniff implements PHP_CodeSniffer_Sniff
final class ArrayDeclarationSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -27,16 +33,16 @@ public function register()
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
* @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.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
$arrayStart = Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = Bracket::bracketEnd($phpcsFile, $stackPtr);

if (!in_array($arrayStart, [$stackPtr, $stackPtr + 1])) {
$phpcsFile->addError('No whitespace allowed between the array keyword and the opening parenthesis', $stackPtr, 'SpaceAfterKeyword');
Expand Down
11 changes: 8 additions & 3 deletions DWS/Sniffs/Arrays/ArrowSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
* @subpackage Sniffs
*/

namespace DWS\Sniffs\Arrays;

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

/**
* A test to ensure that arrows in arrays are set with proper whitespace.
*
* @package DWS
* @subpackage Sniffs
*/
final class DWS_Sniffs_Arrays_ArrowSpacingSniff implements PHP_CodeSniffer_Sniff
final class ArrowSpacingSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -27,12 +32,12 @@ public function register()
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
* @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.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand Down
18 changes: 12 additions & 6 deletions DWS/Sniffs/Arrays/CommaSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
* @subpackage Sniffs
*/

namespace DWS\Sniffs\Arrays;

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

/**
* A test to ensure that commas in arrays are set with proper whitespace.
*
* @package DWS
* @subpackage Sniffs
*/
final class DWS_Sniffs_Arrays_CommaSpacingSniff implements PHP_CodeSniffer_Sniff
final class CommaSpacingSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -27,20 +33,20 @@ public function register()
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
* @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.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
$arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr);

$isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];

foreach (DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart) as $comma) {
foreach (Helpers\Arrays::commaPositions($phpcsFile, $arrayStart) as $comma) {
if ($tokens[$comma - 1]['code'] === T_WHITESPACE) {
$phpcsFile->addError('No whitespace allowed before commas in an array', $comma, 'SpaceBeforeComma');
}
Expand Down
23 changes: 15 additions & 8 deletions DWS/Sniffs/Arrays/TrailingCommaSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
* @subpackage Sniffs
*/

namespace DWS\Sniffs\Arrays;

use DWS\Helpers;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

/**
* A test to ensure that trailing commas are included for multi-line arrays only.
*
* @package DWS
* @subpackage Sniffs
*/
final class DWS_Sniffs_Arrays_TrailingCommaSniff implements PHP_CodeSniffer_Sniff
final class TrailingCommaSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -27,30 +34,30 @@ public function register()
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
* @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.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
$arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr);
$arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr);

$isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];

$commas = DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart);
$commas = Helpers\Arrays::commaPositions($phpcsFile, $arrayStart);

$lastComma = array_pop($commas);
$trailingComma = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false;
$trailingComma = $phpcsFile->findNext(Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false;

if ($isSingleLine) {
if ($trailingComma) {
$phpcsFile->addError('No trailing comma allowed on single-line arrays', $lastComma, 'SingleLineTrailingComma');
}
} elseif (!$trailingComma) {
$previousItem = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true);
$previousItem = $phpcsFile->findPrevious(Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true);
$phpcsFile->addError('Trailing comma required for multi-line arrays', $previousItem, 'MultiLineTrailingComma');
}
}
Expand Down
6 changes: 5 additions & 1 deletion DWS/Sniffs/ControlStructures/ControlSignatureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
* @subpackage Sniffs
*/

namespace DWS\Sniffs\ControlStructures;

use PHP_CodeSniffer\Sniffs\AbstractPatternSniff;

/**
* Verifies that control statements conform to their coding standards.
*
* @package DWS
* @subpackage Sniffs
*/
final class DWS_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
final class ControlSignatureSniff extends AbstractPatternSniff
{
/**
* Initialze the parent AbstractPatternSniff to ignore comments
Expand Down
Loading

0 comments on commit e6bd031

Please sign in to comment.