Skip to content

Commit 1a91eba

Browse files
committed
✨ use grumphp-config for linting
1 parent 88719f3 commit 1a91eba

10 files changed

Lines changed: 132 additions & 74 deletions

File tree

.github/workflows/run-grumphp-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ jobs:
1313
image: kanti/buildy:${{ matrix.php }}
1414
steps:
1515
- uses: actions/checkout@v2
16-
- run: composer install --no-progress --no-scripts -n
16+
- run: COMPOSER_ROOT_VERSION=dev-main composer install --no-progress --no-scripts -n
1717
- run: ./vendor/bin/grumphp run

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
22
composer.lock
3+
var/

bin/fixbom

100644100755
File mode changed.

composer.json

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
{
2-
"name": "pluswerk/grumphp-bom-task",
3-
"description": "Force files to have no BOM",
4-
"type": "library",
5-
"license": "LGPL-3.0-or-later",
6-
"authors": [
7-
{
8-
"name": "Matthias Vogel",
9-
"email": "m.vogel@andersundsehr.com",
10-
"homepage": "https://www.andersundsehr.com"
11-
}
12-
],
13-
"support": {
14-
"issues": "https://github.com/pluswerk/grumphp-bom-task/issues"
15-
},
16-
"bin": ["bin/fixbom"],
17-
"autoload":{
18-
"psr-4":{
19-
"PLUS\\GrumPHPBomTask\\": "src/"
20-
}
21-
},
22-
"require": {
23-
"php": "~8.1.0 || ~8.2.0",
24-
"phpro/grumphp": "^2",
25-
"opis/closure": "^3.6.2"
26-
},
27-
"require-dev": {
28-
"squizlabs/php_codesniffer": ">=3.5.0 <4.0.0"
29-
},
30-
"config": {
31-
"allow-plugins": {
32-
"phpro/grumphp": true
33-
}
2+
"name": "pluswerk/grumphp-bom-task",
3+
"description": "Force files to have no BOM",
4+
"license": "LGPL-3.0-or-later",
5+
"type": "library",
6+
"authors": [
7+
{
8+
"name": "Matthias Vogel",
9+
"email": "m.vogel@andersundsehr.com",
10+
"homepage": "https://www.andersundsehr.com"
3411
}
12+
],
13+
"support": {
14+
"issues": "https://github.com/pluswerk/grumphp-bom-task/issues"
15+
},
16+
"require": {
17+
"php": "~8.1.0 || ~8.2.0",
18+
"phpro/grumphp": "^2.0.0"
19+
},
20+
"require-dev": {
21+
"pluswerk/grumphp-config": "^6.8.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"PLUS\\GrumPHPBomTask\\": "src/"
26+
}
27+
},
28+
"bin": [
29+
"bin/fixbom"
30+
],
31+
"config": {
32+
"allow-plugins": {
33+
"phpro/grumphp": true,
34+
"phpstan/extension-installer": true,
35+
"ergebnis/composer-normalize": true,
36+
"pluswerk/grumphp-config": true
37+
}
38+
},
39+
"extra": {
40+
"branch-alias": {
41+
"dev-main": "8.0.x-dev"
42+
}
43+
}
3544
}

grumphp.yml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
grumphp:
2-
tasks:
3-
composer:
4-
with_dependencies: false
5-
strict: false
6-
git_blacklist:
7-
keywords:
8-
- "die("
9-
- "var_dump("
10-
- "exit;"
11-
triggered_by: [php]
12-
git_commit_message:
13-
max_subject_width: 120
14-
max_body_width: 120
15-
enforce_capitalized_subject: false
16-
jsonlint:
17-
detect_key_conflicts: true
18-
phpcs:
19-
standard: "PSR12"
20-
warning_severity: 0
21-
tab_width: 4
22-
yamllint: ~
23-
plus_bom_fixer:
24-
metadata:
25-
priority: 100
26-
extensions:
27-
- PLUS\GrumPHPBomTask\ExtensionLoader
1+
imports:
2+
- { resource: vendor/pluswerk/grumphp-config/grumphp.yml }
3+
parameters:
4+
convention.process_timeout: 240
5+
convention.security_checker_blocking: true
6+
convention.jsonlint_ignore_pattern: { }
7+
convention.xmllint_ignore_pattern: { }
8+
convention.yamllint_ignore_pattern: { }
9+
convention.phpcslint_ignore_pattern: { }
10+
convention.phpcslint_exclude: { }
11+
convention.xlifflint_ignore_pattern: { }
12+
convention.rector_ignore_pattern: { }
13+
convention.rector_enabled: true
14+
convention.rector_config: rector.php
15+
convention.rector_clear-cache: false
16+
convention.phpstan_level: null

phpstan-baseline.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors: []

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- vendor/andersundsehr/phpstan-git-files/extension.php
4+
5+
parameters:
6+
level: 8
7+
reportUnmatchedIgnoredErrors: false

rector.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PLUS\GrumPHPConfig\RectorSettings;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->parallel();
11+
$rectorConfig->importNames();
12+
$rectorConfig->importShortClasses();
13+
$rectorConfig->cacheClass(FileCacheStorage::class);
14+
$rectorConfig->cacheDirectory('./var/cache/rector');
15+
16+
$rectorConfig->paths(
17+
array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php|html|typoscript)$'")))
18+
);
19+
20+
// define sets of rules
21+
$rectorConfig->sets(
22+
[
23+
...RectorSettings::sets(true),
24+
...RectorSettings::setsTypo3(false),
25+
]
26+
);
27+
28+
// remove some rules
29+
// ignore some files
30+
$rectorConfig->skip(
31+
[
32+
...RectorSettings::skip(),
33+
...RectorSettings::skipTypo3(),
34+
35+
/**
36+
* rector should not touch these files
37+
*/
38+
//__DIR__ . '/src/Example',
39+
//__DIR__ . '/src/Example.php',
40+
]
41+
);
42+
};

src/BomFixerTask.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PLUS\GrumPHPBomTask;
46

7+
use Symfony\Component\Finder\SplFileInfo;
58
use GrumPHP\Runner\TaskResult;
69
use GrumPHP\Runner\TaskResultInterface;
710
use GrumPHP\Task\Config\ConfigOptionsResolver;
@@ -15,8 +18,7 @@
1518

1619
final class BomFixerTask implements TaskInterface
1720
{
18-
/** @var TaskConfigInterface */
19-
private $config;
21+
private EmptyTaskConfig|TaskConfigInterface $config;
2022

2123
public function __construct()
2224
{
@@ -63,20 +65,19 @@ public function run(ContextInterface $context): TaskResultInterface
6365

6466
if (is_file('./vendor/bin/fixbom')) {
6567
$fixCommand = './vendor/bin/fixbom';
68+
} elseif (is_file('./bin/fixbom')) {
69+
$fixCommand = './bin/fixbom';
6670
} else {
67-
if (is_file('./bin/fixbom')) {
68-
$fixCommand = './bin/fixbom';
69-
} else {
70-
$fixCommand = 'fixbom';
71-
}
71+
$fixCommand = 'fixbom';
7272
}
73+
7374
$shouldGetFixedLog = [];
74-
/** @var \Symfony\Component\Finder\SplFileInfo $file */
75+
/** @var SplFileInfo $file */
7576
foreach ($files as $file) {
7677
$execFile = $file->getPathname();
7778
if ($this->isFileWithBOM($execFile)) {
7879
$shouldGetFixedLog[] = $execFile . ' has BOM and should be fixed';
79-
$fixCommand .= ' \'' . $execFile . '\'';
80+
$fixCommand .= " '" . $execFile . "'";
8081
}
8182
}
8283

@@ -86,6 +87,7 @@ public function run(ContextInterface $context): TaskResultInterface
8687
. $fixCommand;
8788
return TaskResult::createFailed($this, $context, $errorMessage);
8889
}
90+
8991
return TaskResult::createPassed($this, $context);
9092
}
9193

@@ -98,9 +100,14 @@ private function fileInfoSearch(string $filename, string $search): bool
98100
{
99101
$output = [];
100102
exec('file ' . '"' . $filename . '"', $output, $returnVar);
101-
if ($returnVar === 0 && !empty($output[0]) && strpos($output[0], $search) !== false) {
102-
return true;
103+
if ($returnVar !== 0) {
104+
return false;
103105
}
104-
return false;
106+
107+
if (empty($output[0])) {
108+
return false;
109+
}
110+
111+
return str_contains($output[0], $search);
105112
}
106113
}

src/ExtensionLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
namespace PLUS\GrumPHPBomTask;
66

7+
use Iterator;
78
use GrumPHP\Extension\ExtensionInterface;
89

9-
class ExtensionLoader implements ExtensionInterface
10+
final class ExtensionLoader implements ExtensionInterface
1011
{
11-
public function imports(): iterable
12+
public function imports(): Iterator
1213
{
1314
yield __DIR__ . '/../Services.yaml';
1415
}

0 commit comments

Comments
 (0)