Skip to content

Commit

Permalink
Merge pull request #35 from inpsyde/modernization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gmazzap authored Apr 13, 2020
2 parents 379bf0e + 3fb34c9 commit 52edc0b
Show file tree
Hide file tree
Showing 35 changed files with 465 additions and 675 deletions.
89 changes: 0 additions & 89 deletions Inpsyde/PHPCSAliases.php

This file was deleted.

18 changes: 17 additions & 1 deletion Inpsyde/PhpcsHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Inpsyde;

use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Exceptions\RuntimeException as CodeSnifferRuntimeException;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
Expand Down Expand Up @@ -330,7 +331,7 @@ public static function isHookClosure(
}

$lookForComma = $file->findPrevious(
[T_WHITESPACE],
[T_WHITESPACE, T_STATIC],
$closurePosition - 1,
null,
true,
Expand Down Expand Up @@ -614,4 +615,19 @@ public static function findNamespace(File $file, int $position): array

return [$namespacePos, $namespace];
}

/**
* @return string
*/
public static function minPhpTestVersion(): string
{
$testVersion = trim(Config::getConfigData('testVersion') ?: '');
if (!$testVersion) {
return '';
}

preg_match('`^(\d+\.\d+)(?:\s*-\s*(?:\d+\.\d+)?)?$`', $testVersion, $matches);

return $matches[1] ?? '';
}
}
8 changes: 6 additions & 2 deletions Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1); # -*- coding: utf-8 -*-
<?php

/*
* This file is part of the php-coding-standards package.
*
Expand All @@ -13,6 +14,8 @@
* released under MIT license.
*/

declare(strict_types=1);

namespace Inpsyde\Sniffs\CodeQuality;

use Inpsyde\PhpcsHelpers;
Expand Down Expand Up @@ -46,7 +49,8 @@ public function register()
*/
public function process(File $file, $position)
{
if (PhpcsHelpers::functionIsArrayAccess($file, $position)
if (
PhpcsHelpers::functionIsArrayAccess($file, $position)
|| PhpcsHelpers::isHookClosure($file, $position)
|| PhpcsHelpers::isHookFunction($file, $position)
|| (
Expand Down
137 changes: 0 additions & 137 deletions Inpsyde/Sniffs/CodeQuality/AssignmentInsideConditionSniff.php

This file was deleted.

40 changes: 40 additions & 0 deletions Inpsyde/Sniffs/CodeQuality/ConstantVisibilitySniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the php-coding-standards package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\Sniffs\CodeQuality;

use Inpsyde\PhpcsHelpers;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Standards\PSR12\Sniffs\Properties as PSR12;

/**
* @package php-coding-standards
* @license http://opensource.org/licenses/MIT MIT
*/
final class ConstantVisibilitySniff extends PSR12\ConstantVisibilitySniff
{
/**
* @param File $phpcsFile
* @param int $stackPtr
* @return void
*/
public function process(File $phpcsFile, $stackPtr)
{
$min = PhpcsHelpers::minPhpTestVersion();
if ($min && version_compare($min, '7.1', '<')) {
return;
}

parent::process($phpcsFile, $stackPtr);
}
}
7 changes: 5 additions & 2 deletions Inpsyde/Sniffs/CodeQuality/DisallowShortOpenTagSniff.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1); # -*- coding: utf-8 -*-
<?php

/*
* This file is part of the php-coding-standards package.
*
Expand All @@ -8,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\Sniffs\CodeQuality;

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP as Generic;
Expand All @@ -16,7 +19,7 @@
* @package php-coding-standards
* @license http://opensource.org/licenses/MIT MIT
*/
final class DisallowShortOpenTagSniff extends Generic\DisallowShortOpenTagSniff
class DisallowShortOpenTagSniff extends Generic\DisallowShortOpenTagSniff
{
/**
* @return int[]
Expand Down
Loading

0 comments on commit 52edc0b

Please sign in to comment.