Skip to content

Commit f9efebf

Browse files
authored
Merge pull request #5 from simonschaufi/upgrade
[TASK] Upgrade to friendsofphp/php-cs-fixer 3.0
2 parents 1f4b4b5 + a08de75 commit f9efebf

File tree

8 files changed

+31
-24
lines changed

8 files changed

+31
-24
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
/.idea/
12
/.build/
23
/vendor/
34
/composer.lock
4-
/.php_cs.cache
5+
/.php-cs-fixer.cache

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ or if you want to update the rules, add `-f` option to the end.
4444

4545
Have a look at the newly created files in your root folder:
4646

47-
- .php_cs
47+
- .php-cs-fixer.php
4848
- .editorconfig
4949

5050
For projects, the folder `src/extensions` is configured by default, but you can

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": "^7.2 || ^8.0",
14-
"friendsofphp/php-cs-fixer": "^2.19"
14+
"friendsofphp/php-cs-fixer": "^3.0"
1515
},
1616
"config": {
1717
"sort-packages": true

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33
declare(strict_types = 1);
44

5-
$setup = function($scriptPath, string $type = null, $forceOption = null) {
5+
$setup = static function($scriptPath, string $type = null, $forceOption = null) {
66
$rootPath = getcwd();
77

88
$dir = __DIR__ . '/vendor';

src/CsFixerConfig.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
use PhpCsFixer\Config;
14+
use PhpCsFixer\ConfigInterface;
1415

1516
class CsFixerConfig extends Config
1617
{
@@ -83,25 +84,26 @@ public function __construct($name = 'TYPO3')
8384
parent::__construct($name);
8485
}
8586

86-
public static function create()
87+
public static function create(): ConfigInterface
8788
{
88-
/** @var self $obj */
89-
$obj = parent::create();
90-
$obj->setRiskyAllowed(true);
91-
// Apply our rules
92-
$obj->setRules(static::$typo3Rules);
93-
$obj->getFinder()->exclude(['vendor', 'typo3temp', 'var', '.build']);
94-
return $obj;
89+
$config = (new self())
90+
->setRiskyAllowed(true)
91+
->setRules(static::$typo3Rules);
92+
93+
$config->getFinder()->exclude(['vendor', 'typo3temp', 'var', '.build']);
94+
return $config;
9595
}
9696

97-
public function addRules(array $rules)
97+
public function addRules(array $rules): ConfigInterface
9898
{
9999
$rules = array_replace_recursive($this->getRules(), $rules);
100-
$this->setRules($rules);
100+
return $this->setRules($rules);
101101
}
102102

103-
public function setHeader(string $header = 'This file is part of the TYPO3 CMS project.', $replaceAll = false)
104-
{
103+
public function setHeader(
104+
string $header = 'This file is part of the TYPO3 CMS project.',
105+
bool $replaceAll = false
106+
): ConfigInterface {
105107
if (!$replaceAll) {
106108
$header = str_replace('{header}', $header, static::$defaultHeader);
107109
}
@@ -112,6 +114,6 @@ public function setHeader(string $header = 'This file is part of the TYPO3 CMS p
112114
'location' => 'after_declare_strict',
113115
'separate' => 'both'
114116
];
115-
return parent::setRules($rules);
117+
return $this->setRules($rules);
116118
}
117119
}

src/Setup.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ public function forProject(bool $force): int
3232
{
3333
$errors = $this->copyEditorConfig($force);
3434
// copy php-cs-fixer configuration
35-
if (file_exists($this->rootPath . '/.php_cs') && !$force) {
36-
echo "A .php_cs file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
35+
if (!$force
36+
&& (file_exists($this->rootPath . '/.php_cs') || file_exists($this->rootPath . '/.php-cs-fixer.php'))
37+
) {
38+
echo "A .php-cs-fixer.php or .php_cs file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
3739
$errors = true;
3840
} else {
39-
copy($this->templatesPath . '/project_php_cs.dist', $this->rootPath . '/.php_cs');
41+
copy($this->templatesPath . '/project_php-cs-fixer.dist.php', $this->rootPath . '/.php-cs-fixer.php');
4042
}
4143
return $errors ? 1 : 0;
4244
}
@@ -45,11 +47,13 @@ public function forExtension(bool $force): int
4547
{
4648
$errors = $this->copyEditorConfig($force);
4749
// copy php-cs-fixer configuration
48-
if (file_exists($this->rootPath . '/.php_cs') && !$force) {
49-
echo "A .php_cs file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
50+
if (!$force
51+
&& (file_exists($this->rootPath . '/.php_cs') || file_exists($this->rootPath . '/.php-cs-fixer.php'))
52+
) {
53+
echo "A .php-cs-fixer.php or .php_cs file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
5054
$errors = true;
5155
} else {
52-
copy($this->templatesPath . '/extension_php_cs.dist', $this->rootPath . '/.php_cs');
56+
copy($this->templatesPath . '/extension_php-cs-fixer.dist.php', $this->rootPath . '/.php-cs-fixer.php');
5357
}
5458
return $errors ? 1 : 0;
5559
}
@@ -58,7 +62,7 @@ private function copyEditorConfig(bool $force): bool
5862
{
5963
$errors = false;
6064
// copy editorconfig
61-
if (file_exists($this->rootPath . '/.editorconfig') && !$force) {
65+
if (!$force && file_exists($this->rootPath . '/.editorconfig')) {
6266
echo "A .editorconfig file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
6367
$errors = true;
6468
} else {
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)