Skip to content

Commit 1a1551c

Browse files
committed
Modern PHP CS Fixer
1 parent d03d2a6 commit 1a1551c

File tree

10 files changed

+50
-60
lines changed

10 files changed

+50
-60
lines changed

.github/workflows/Tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Setup PHP
4040
uses: shivammathur/setup-php@v2
4141
with:
42-
php-version: 8.0
42+
php-version: 8.1
4343
tools: composer
4444

4545
- name: Install requirements
@@ -56,7 +56,7 @@ jobs:
5656
- name: Setup PHP
5757
uses: shivammathur/setup-php@v2
5858
with:
59-
php-version: 8.0
59+
php-version: 8.1
6060
tools: composer
6161

6262
- name: Install requirements

Classes/Manipulation/RemoveGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public function manipulate(string $html, array $configuration = []): string
1616
{
1717
$regex = '<meta name=["\']?generator["\']? [^>]+>';
1818

19-
return (string) preg_replace('/'.$regex.'/is', '', $html);
19+
return (string) preg_replace('/' . $regex . '/is', '', $html);
2020
}
2121
}

Classes/Middleware/CleanHtmlMiddleware.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
class CleanHtmlMiddleware extends AbstractMiddleware
1313
{
14-
public function __construct(protected CleanHtmlService $cleanHtmlService)
15-
{
16-
}
14+
public function __construct(protected CleanHtmlService $cleanHtmlService) {}
1715

1816
/**
1917
* Clean the HTML output.

Classes/Middleware/RegExRepMiddleware.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
class RegExRepMiddleware extends AbstractMiddleware
1313
{
14-
public function __construct(protected RegExRepService $regExRepService)
15-
{
16-
}
14+
public function __construct(protected RegExRepService $regExRepService) {}
1715

1816
/**
1917
* RegEx search & replace @ HTML output.

Classes/Middleware/SvgStoreMiddleware.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
class SvgStoreMiddleware extends AbstractMiddleware
1313
{
14-
public function __construct(protected SvgStoreService $svgStoreService)
15-
{
16-
}
14+
public function __construct(protected SvgStoreService $svgStoreService) {}
1715

1816
/**
1917
* Search/Extract/Merge SVGs @ HTML output.

Classes/Service/CleanHtmlService.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function clean(string $html, array $config = []): string
101101

102102
foreach ($manipulations as $key => $manipulation) {
103103
/** @var ManipulationInterface $manipulation */
104-
$configuration = isset($config[$key.'.']) && \is_array($config[$key.'.']) ? $config[$key.'.'] : [];
104+
$configuration = isset($config[$key . '.']) && \is_array($config[$key . '.']) ? $config[$key . '.'] : [];
105105
$html = $manipulation->manipulate($html, $configuration);
106106
}
107107

@@ -161,7 +161,7 @@ protected function formatHtml(string $html): string
161161
$functionalBoxElements = 'dd|dt|frameset|li|tbody|td|tfoot|th|thead|tr|colgroup';
162162
$usableBoxElements = 'applet|button|del|iframe|ins|map|object|script';
163163
$imagineBoxElements = 'html|body|head|meta|title|link|script|base|!--';
164-
$allBoxLikeElements = '(?>'.$trueBoxElements.'|'.$functionalBoxElements.'|'.$usableBoxElements.'|'.$imagineBoxElements.')';
164+
$allBoxLikeElements = '(?>' . $trueBoxElements . '|' . $functionalBoxElements . '|' . $usableBoxElements . '|' . $imagineBoxElements . ')';
165165
$esteticBoxLikeElements = '(?>html|head|body|meta name|title|div|table|h1|h2|h3|h4|h5|h6|p|form|pre|center|!--)';
166166
$structureBoxLikeElements = '(?>html|head|body|div|!--)';
167167

@@ -204,52 +204,52 @@ protected function formatHtml(string $html): string
204204
} elseif (2 == $this->formatType && ( // minimalistic line break
205205
// this element has a line break before itself
206206
preg_match(
207-
'/<'.$structureBoxLikeElements.'(.*)>/Usi',
207+
'/<' . $structureBoxLikeElements . '(.*)>/Usi',
208208
$htmlArrayCurrent
209209
) || preg_match(
210-
'/<'.$structureBoxLikeElements.'(.*) \/>/Usi',
210+
'/<' . $structureBoxLikeElements . '(.*) \/>/Usi',
211211
$htmlArrayCurrent
212212
) // one element before is a element that has a line break after
213213
|| preg_match(
214-
'/<\/'.$structureBoxLikeElements.'(.*)>/Usi',
214+
'/<\/' . $structureBoxLikeElements . '(.*)>/Usi',
215215
$htmlArrayBefore
216216
) || '<!--' == substr(
217217
$htmlArrayBefore,
218218
0,
219219
4
220-
) || preg_match('/<'.$structureBoxLikeElements.'(.*) \/>/Usi', $htmlArrayBefore))
220+
) || preg_match('/<' . $structureBoxLikeElements . '(.*) \/>/Usi', $htmlArrayBefore))
221221
) {
222222
$newline = true;
223223
} elseif (3 == $this->formatType && ( // aestetic line break
224224
// this element has a line break before itself
225225
preg_match(
226-
'/<'.$esteticBoxLikeElements.'(.*)>/Usi',
226+
'/<' . $esteticBoxLikeElements . '(.*)>/Usi',
227227
$htmlArrayCurrent
228228
) || preg_match(
229-
'/<'.$esteticBoxLikeElements.'(.*) \/>/Usi',
229+
'/<' . $esteticBoxLikeElements . '(.*) \/>/Usi',
230230
$htmlArrayCurrent
231231
) // one element before is a element that has a line break after
232-
|| preg_match('/<\/'.$esteticBoxLikeElements.'(.*)>/Usi', $htmlArrayBefore) || '<!--' == substr(
232+
|| preg_match('/<\/' . $esteticBoxLikeElements . '(.*)>/Usi', $htmlArrayBefore) || '<!--' == substr(
233233
$htmlArrayBefore,
234234
0,
235235
4
236-
) || preg_match('/<'.$esteticBoxLikeElements.'(.*) \/>/Usi', $htmlArrayBefore))
236+
) || preg_match('/<' . $esteticBoxLikeElements . '(.*) \/>/Usi', $htmlArrayBefore))
237237
) {
238238
$newline = true;
239239
} elseif ($this->formatType >= 4 && ( // logical line break
240240
// this element has a line break before itself
241241
preg_match(
242-
'/<'.$allBoxLikeElements.'(.*)>/Usi',
242+
'/<' . $allBoxLikeElements . '(.*)>/Usi',
243243
$htmlArrayCurrent
244244
) || preg_match(
245-
'/<'.$allBoxLikeElements.'(.*) \/>/Usi',
245+
'/<' . $allBoxLikeElements . '(.*) \/>/Usi',
246246
$htmlArrayCurrent
247247
) // one element before is a element that has a line break after
248-
|| preg_match('/<\/'.$allBoxLikeElements.'(.*)>/Usi', $htmlArrayBefore) || '<!--' == substr(
248+
|| preg_match('/<\/' . $allBoxLikeElements . '(.*)>/Usi', $htmlArrayBefore) || '<!--' == substr(
249249
$htmlArrayBefore,
250250
0,
251251
4
252-
) || preg_match('/<'.$allBoxLikeElements.'(.*) \/>/Usi', $htmlArrayBefore))
252+
) || preg_match('/<' . $allBoxLikeElements . '(.*) \/>/Usi', $htmlArrayBefore))
253253
) {
254254
$newline = true;
255255
}
@@ -385,6 +385,6 @@ protected function removeEmptyLines(string &$html): void
385385
*/
386386
public function includeHeaderComment(string &$html): void
387387
{
388-
$html = preg_replace('/^(-->)$/m', "\n\t".$this->headerComment."\n$1", $html);
388+
$html = preg_replace('/^(-->)$/m', "\n\t" . $this->headerComment . "\n$1", $html);
389389
}
390390
}

Classes/Service/RegExRepService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public function process(string $html): string
2222

2323
foreach (['search.', 'replace.'] as $section) {
2424
if (!isset($config[$section]) || !\is_array($config[$section])) {
25-
throw new \Exception('missing entry @ config.replacer.'.$section);
25+
throw new \Exception('missing entry @ config.replacer.' . $section);
2626
}
2727

2828
if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) {
29-
$cObj = $cObj ?? $GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class);
29+
$cObj ??= $GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class);
3030

3131
foreach ($matches[1] as $key) {
3232
$config[$section][$key] = $cObj
3333
->stdWrap(
3434
$config[$section][$key],
35-
$config[$section][$key.'.']
35+
$config[$section][$key . '.']
3636
)
3737
;
38-
unset($config[$section][$key.'.']); // keep!
38+
unset($config[$section][$key . '.']); // keep!
3939
}
4040
}
4141

@@ -45,7 +45,7 @@ public function process(string $html): string
4545
if (Environment::getContext()->isDevelopment()) {
4646
foreach ($config['search.'] as $key => $val) {
4747
if (false === @preg_match($val, '')) {
48-
throw new \Exception(preg_last_error_msg().' : please check your regex syntax @ '."{$key} = {$val}");
48+
throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}");
4949
}
5050
}
5151
}

Classes/Service/SvgStoreService.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public function __construct()
6666
$this->svgFileArr = $this->svgCache->get('svgFileArr') ?: [];
6767

6868
if (empty($this->spritePath) && !$this->populateCache()) {
69-
throw new \Exception('could not write file: '.$this->sitePath.$this->spritePath);
69+
throw new \Exception('could not write file: ' . $this->sitePath . $this->spritePath);
7070
}
7171

72-
if (!file_exists($this->sitePath.$this->spritePath)) {
73-
throw new \Exception('file does not exists: '.$this->sitePath.$this->spritePath);
72+
if (!file_exists($this->sitePath . $this->spritePath)) {
73+
throw new \Exception('file does not exists: ' . $this->sitePath . $this->spritePath);
7474
}
7575
}
7676

@@ -91,7 +91,7 @@ public function process(string $html): string
9191
if (!isset($this->svgFileArr[$match['src']])) { // check usage
9292
return $match[0];
9393
}
94-
$attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap|crossorigin|decoding|fetchpriority|referrerpolicy)="[^"]*"/', '', $match['pre'].$match['post']); // cleanup
94+
$attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap|crossorigin|decoding|fetchpriority|referrerpolicy)="[^"]*"/', '', $match['pre'] . $match['post']); // cleanup
9595

9696
return \sprintf('<svg %s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$match['src']]['attr'], trim($attr), $this->spritePath, $this->convertFilePath($match['src']));
9797
}, $dom['body']);
@@ -101,12 +101,12 @@ public function process(string $html): string
101101
if (!isset($this->svgFileArr[$match['data']])) { // check usage
102102
return $match[0];
103103
}
104-
$attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/', '', $match['pre'].$match['post']); // cleanup
104+
$attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/', '', $match['pre'] . $match['post']); // cleanup
105105

106106
return \sprintf('<svg %s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$match['data']]['attr'], trim($attr), $this->spritePath, $this->convertFilePath($match['data']));
107107
}, $dom['body']);
108108

109-
return $dom['head'].$dom['body'];
109+
return $dom['head'] . $dom['body'];
110110
}
111111

112112
private function convertFilePath(string $path): string
@@ -116,11 +116,11 @@ private function convertFilePath(string $path): string
116116

117117
private function addFileToSpriteArr(string $hash, string $path, array $attr = []): ?array
118118
{
119-
if (!file_exists($this->sitePath.$path)) {
119+
if (!file_exists($this->sitePath . $path)) {
120120
return null;
121121
}
122122

123-
$svg = file_get_contents($this->sitePath.$path);
123+
$svg = file_get_contents($this->sitePath . $path);
124124

125125
if (preg_match('/(?:;base64|i:a?i?pgf)/', $svg)) { // noop!
126126
return null;
@@ -197,7 +197,7 @@ private function populateCache(): bool
197197

198198
$fileArr = GeneralUtility::makeInstance(SvgFileRepository::class)->findAllByStorageUids(array_keys($storageArr));
199199
foreach ($fileArr as $file) {
200-
$file['path'] = '/'.$storageArr[$file['storage']].$file['identifier']; // ^[/]
200+
$file['path'] = '/' . $storageArr[$file['storage']] . $file['identifier']; // ^[/]
201201
$file['defs'] = $this->addFileToSpriteArr($file['sha1'], $file['path']);
202202

203203
if (null !== $file['defs']) {
@@ -216,13 +216,13 @@ function (array $match): string {
216216
return $match[0];
217217
}
218218

219-
return \sprintf('<use%s href="#%s"/>', $match['pre'].$match['post'], $this->convertFilePath($match['href']));
219+
return \sprintf('<use%s href="#%s"/>', $match['pre'] . $match['post'], $this->convertFilePath($match['href']));
220220
},
221221
'<svg xmlns="http://www.w3.org/2000/svg">'
222222
// ."\n<style>\n".implode("\n", $this->styl)."\n</style>"
223223
// ."\n<defs>\n".implode("\n", $this->defs)."\n</defs>"
224-
."\n<symbol ".implode("</symbol>\n<symbol ", $this->svgs)."</symbol>\n"
225-
.'</svg>'
224+
. "\n<symbol " . implode("</symbol>\n<symbol ", $this->svgs) . "</symbol>\n"
225+
. '</svg>'
226226
);
227227

228228
if ($GLOBALS['TSFE']->config['config']['sourceopt.']['formatHtml'] ?? false) {
@@ -234,12 +234,12 @@ function (array $match): string {
234234
$svg = preg_replace('/<([a-z\-]+)\s*(\/|>\s*<\/\1)>\s*|\s+(?=\/>)/i', '', $svg); // remove emtpy TAGs & shorten endings
235235
$svg = preg_replace('/<((circle|ellipse|line|path|polygon|polyline|rect|stop|use)\s[^>]+?)\s*>\s*<\/\2>/', '<$1/>', $svg); // shorten/minify TAG syntax
236236

237-
if (!is_dir($this->sitePath.$this->outputDir)) {
238-
GeneralUtility::mkdir_deep($this->sitePath.$this->outputDir);
237+
if (!is_dir($this->sitePath . $this->outputDir)) {
238+
GeneralUtility::mkdir_deep($this->sitePath . $this->outputDir);
239239
}
240240

241-
$this->spritePath = $this->outputDir.hash('sha1', serialize($this->svgFileArr)).'.svg';
242-
if (false === file_put_contents($this->sitePath.$this->spritePath, $svg)) {
241+
$this->spritePath = $this->outputDir . hash('sha1', serialize($this->svgFileArr)) . '.svg';
242+
if (false === file_put_contents($this->sitePath . $this->spritePath, $svg)) {
243243
return false;
244244
}
245245

Resources/Private/Build/PhpCsFixer.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33
declare(strict_types=1);
44

55
$baseDir = dirname(__DIR__, 3);
6-
require $baseDir.'/.Build/vendor/autoload.php';
6+
require $baseDir . '/.Build/vendor/autoload.php';
77

88
$finder = PhpCsFixer\Finder::create()
9-
->in($baseDir.'/Classes')
10-
->in($baseDir.'/Tests')
11-
->in($baseDir.'/Resources/Private/Build')
9+
->in($baseDir . '/Classes')
10+
->in($baseDir . '/Tests')
11+
->in($baseDir . '/Resources/Private/Build')
1212
;
1313

1414
return (new PhpCsFixer\Config())
1515
->setRiskyAllowed(true)
1616
->setRules([
17-
'@PhpCsFixer' => true,
18-
'@Symfony' => true,
19-
'@Symfony:risky' => true,
17+
'@PER-CS2.0' => true,
18+
'@PER-CS2.0:risky' => true,
2019
'@DoctrineAnnotation' => true,
2120
'@PSR2' => true,
22-
'@PHP71Migration' => true,
23-
'@PHP71Migration:risky' => true,
21+
'@PHP81Migration' => true,
2422
'array_syntax' => ['syntax' => 'short'],
2523
])
2624
->setFinder($finder)

Tests/Unit/AbstractUnitTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace HTML\Sourceopt\Tests\Unit;
66

7-
abstract class AbstractUnitTest extends \PHPUnit\Framework\TestCase
8-
{
9-
}
7+
abstract class AbstractUnitTest extends \PHPUnit\Framework\TestCase {}

0 commit comments

Comments
 (0)