Skip to content

Commit 52edc0b

Browse files
authored
Merge pull request #35 from inpsyde/modernization
This merge will: Modernize the codebase: - Move from PSR-2 or PSR-12 - Use latest PHPCS - Use latest WPCS - Use latest VIP CS now in separate repo from WPCS Cleanup: - Remove custom and 3rd party sniffs that are duplicated - Remove PHPCSAliases.php that's no more necessary - Remove arg and config from ruleset.xml Improve: - Make customization of ElementNameMinimalLength sniff - Improve detection of hook callback Overall, merging this PR will fix: - #21 - #25 - #26 (some outdated packages will be there because of PHPUnit 6 that we can't upgrade due to PHP 7.0 support) - #29 - #33
2 parents 379bf0e + 3fb34c9 commit 52edc0b

35 files changed

+465
-675
lines changed

Inpsyde/PHPCSAliases.php

Lines changed: 0 additions & 89 deletions
This file was deleted.

Inpsyde/PhpcsHelpers.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace Inpsyde;
1717

18+
use PHP_CodeSniffer\Config;
1819
use PHP_CodeSniffer\Exceptions\RuntimeException as CodeSnifferRuntimeException;
1920
use PHP_CodeSniffer\Files\File;
2021
use PHP_CodeSniffer\Util\Tokens;
@@ -330,7 +331,7 @@ public static function isHookClosure(
330331
}
331332

332333
$lookForComma = $file->findPrevious(
333-
[T_WHITESPACE],
334+
[T_WHITESPACE, T_STATIC],
334335
$closurePosition - 1,
335336
null,
336337
true,
@@ -614,4 +615,19 @@ public static function findNamespace(File $file, int $position): array
614615

615616
return [$namespacePos, $namespace];
616617
}
618+
619+
/**
620+
* @return string
621+
*/
622+
public static function minPhpTestVersion(): string
623+
{
624+
$testVersion = trim(Config::getConfigData('testVersion') ?: '');
625+
if (!$testVersion) {
626+
return '';
627+
}
628+
629+
preg_match('`^(\d+\.\d+)(?:\s*-\s*(?:\d+\.\d+)?)?$`', $testVersion, $matches);
630+
631+
return $matches[1] ?? '';
632+
}
617633
}

Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php declare(strict_types=1); # -*- coding: utf-8 -*-
1+
<?php
2+
23
/*
34
* This file is part of the php-coding-standards package.
45
*
@@ -13,6 +14,8 @@
1314
* released under MIT license.
1415
*/
1516

17+
declare(strict_types=1);
18+
1619
namespace Inpsyde\Sniffs\CodeQuality;
1720

1821
use Inpsyde\PhpcsHelpers;
@@ -46,7 +49,8 @@ public function register()
4649
*/
4750
public function process(File $file, $position)
4851
{
49-
if (PhpcsHelpers::functionIsArrayAccess($file, $position)
52+
if (
53+
PhpcsHelpers::functionIsArrayAccess($file, $position)
5054
|| PhpcsHelpers::isHookClosure($file, $position)
5155
|| PhpcsHelpers::isHookFunction($file, $position)
5256
|| (

Inpsyde/Sniffs/CodeQuality/AssignmentInsideConditionSniff.php

Lines changed: 0 additions & 137 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the php-coding-standards package.
5+
*
6+
* (c) Inpsyde GmbH
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Inpsyde\Sniffs\CodeQuality;
15+
16+
use Inpsyde\PhpcsHelpers;
17+
use PHP_CodeSniffer\Files\File;
18+
use PHP_CodeSniffer\Standards\PSR12\Sniffs\Properties as PSR12;
19+
20+
/**
21+
* @package php-coding-standards
22+
* @license http://opensource.org/licenses/MIT MIT
23+
*/
24+
final class ConstantVisibilitySniff extends PSR12\ConstantVisibilitySniff
25+
{
26+
/**
27+
* @param File $phpcsFile
28+
* @param int $stackPtr
29+
* @return void
30+
*/
31+
public function process(File $phpcsFile, $stackPtr)
32+
{
33+
$min = PhpcsHelpers::minPhpTestVersion();
34+
if ($min && version_compare($min, '7.1', '<')) {
35+
return;
36+
}
37+
38+
parent::process($phpcsFile, $stackPtr);
39+
}
40+
}

Inpsyde/Sniffs/CodeQuality/DisallowShortOpenTagSniff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php declare(strict_types=1); # -*- coding: utf-8 -*-
1+
<?php
2+
23
/*
34
* This file is part of the php-coding-standards package.
45
*
@@ -8,6 +9,8 @@
89
* file that was distributed with this source code.
910
*/
1011

12+
declare(strict_types=1);
13+
1114
namespace Inpsyde\Sniffs\CodeQuality;
1215

1316
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP as Generic;
@@ -16,7 +19,7 @@
1619
* @package php-coding-standards
1720
* @license http://opensource.org/licenses/MIT MIT
1821
*/
19-
final class DisallowShortOpenTagSniff extends Generic\DisallowShortOpenTagSniff
22+
class DisallowShortOpenTagSniff extends Generic\DisallowShortOpenTagSniff
2023
{
2124
/**
2225
* @return int[]

0 commit comments

Comments
 (0)