Skip to content

Commit 9e8227b

Browse files
committed
We should use own styles
1 parent d71f5ff commit 9e8227b

23 files changed

+220
-77
lines changed

Inpsyde/PhpcsHelpers.php

Lines changed: 16 additions & 0 deletions
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;
@@ -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
|| (
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[]

Inpsyde/Sniffs/CodeQuality/ElementNameMinimalLengthSniff.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
*
@@ -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;
@@ -23,7 +26,7 @@
2326
* @package php-coding-standards
2427
* @license http://opensource.org/licenses/MIT MIT
2528
*/
26-
final class ElementNameMinimalLengthSniff implements Sniff
29+
class ElementNameMinimalLengthSniff implements Sniff
2730
{
2831

2932
/**

Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.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
*
@@ -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;
@@ -24,7 +27,7 @@
2427
* @package php-coding-standards
2528
* @license http://opensource.org/licenses/MIT MIT
2629
*/
27-
final class ForbiddenPublicPropertySniff implements Sniff
30+
class ForbiddenPublicPropertySniff implements Sniff
2831
{
2932
/**
3033
* @return int[]

Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php

Lines changed: 8 additions & 4 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\Files\File;
@@ -43,7 +46,8 @@ public function process(File $phpcsFile, $stackPtr)
4346
}
4447

4548
$bodyStart = $phpcsFile->findNext([T_WHITESPACE], $scopeOpener + 1, null, true);
46-
if (!$bodyStart
49+
if (
50+
!$bodyStart
4751
|| !array_key_exists($bodyStart, $tokens)
4852
|| $bodyStart <= $scopeOpener
4953
|| $bodyStart >= $scopeCloser
@@ -105,7 +109,7 @@ private function checkBodyStart(
105109
return [
106110
$code,
107111
"In functions {$where}, function body should start with a blank line.",
108-
$openerLine + 2
112+
$openerLine + 2,
109113
];
110114
}
111115

@@ -119,7 +123,7 @@ private function checkBodyStart(
119123
return [
120124
'WrongForSingleLineDeclaration',
121125
$message,
122-
$openerLine + 1
126+
$openerLine + 1,
123127
];
124128
}
125129

Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php

Lines changed: 9 additions & 4 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 PHP_CodeSniffer\Files\File;
@@ -22,7 +25,7 @@
2225
* @package php-coding-standards
2326
* @license http://opensource.org/licenses/MIT MIT
2427
*/
25-
final class FunctionLengthSniff implements Sniff
28+
class FunctionLengthSniff implements Sniff
2629
{
2730
/**
2831
* @var int
@@ -96,7 +99,8 @@ public function structureLinesCount(File $file, int $position): int
9699
$tokens = $file->getTokens();
97100
$token = $tokens[$position] ?? [];
98101

99-
if (!array_key_exists('scope_opener', $token)
102+
if (
103+
!array_key_exists('scope_opener', $token)
100104
|| !array_key_exists('scope_closer', $token)
101105
) {
102106
return 0;
@@ -186,7 +190,8 @@ private function docBlocksData(
186190
array $docBlocks
187191
): array {
188192

189-
if (!$this->ignoreDocBlocks
193+
if (
194+
!$this->ignoreDocBlocks
190195
|| $tokens[$position]['code'] !== T_DOC_COMMENT_OPEN_TAG
191196
) {
192197
return $docBlocks;

Inpsyde/Sniffs/CodeQuality/HookClosureReturnSniff.php

Lines changed: 4 additions & 1 deletion
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 Inpsyde\PhpcsHelpers;

Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php

Lines changed: 8 additions & 4 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 BSD license.
1415
*/
1516

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

1821
use PHP_CodeSniffer\Sniffs\Sniff;
@@ -87,7 +90,6 @@ public function process(File $file, $position)
8790
return $file->numTokens + 1;
8891
}
8992

90-
// phpcs:disable VariableAnalysis
9193
foreach ($longLinesData as $lineNum => list($length, $start, $end)) {
9294
if ($this->shouldIgnoreLine($file, $start, $end)) {
9395
continue;
@@ -207,7 +209,8 @@ private function isI18nFunction(File $file, int $start, int $end): bool
207209
$tokens = $file->getTokens();
208210

209211
for ($i = $start; $i <= $end; $i++) {
210-
if ($tokens[$i]['code'] !== T_CONSTANT_ENCAPSED_STRING
212+
if (
213+
$tokens[$i]['code'] !== T_CONSTANT_ENCAPSED_STRING
211214
|| (strlen($tokens[$i]['content']) + 3) < $this->lineLimit
212215
) {
213216
continue;
@@ -223,7 +226,8 @@ private function isI18nFunction(File $file, int $start, int $end): bool
223226
);
224227

225228
$previous = $previousPos ? $tokens[$previousPos] ?? null : null;
226-
if (!$previous
229+
if (
230+
!$previous
227231
|| $previous['code'] !== T_STRING
228232
|| !in_array($previous['content'], self::I18N_FUNCTIONS, true)
229233
) {

0 commit comments

Comments
 (0)