Skip to content

Commit 0c0b08c

Browse files
committed
chore(codestyle): Upgrade php-cs-fixer to version 3
1 parent 8a23291 commit 0c0b08c

14 files changed

+99
-105
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
vendor/
33
composer.lock
44
*.phar
5-
.php_cs.cache
5+
.php-cs-fixer.cache
66
coverage/
77
psalm/cache/
88

.php-cs-fixer.dist.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*
3+
* This document has been generated with
4+
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.0.0-rc.1|configurator
5+
* you can change this configuration by importing this file.
6+
*/
7+
return (new PhpCsFixer\Config())
8+
->setRiskyAllowed(true)
9+
->setRules([
10+
'@Symfony' => true,
11+
'@Symfony:risky' => true,
12+
'array_syntax' => ['syntax' => 'short'],
13+
'declare_strict_types' => true,
14+
'global_namespace_import' => [
15+
'import_classes' => true,
16+
'import_constants' => true,
17+
'import_functions' => false,
18+
],
19+
'native_constant_invocation' => true,
20+
'native_function_invocation' => [
21+
'strict' => false,
22+
'include' => ['@compiler_optimized'],
23+
],
24+
'no_superfluous_phpdoc_tags' => true,
25+
'ordered_class_elements' => true,
26+
'ordered_imports' => true,
27+
'php_unit_dedicate_assert' => ['target' => 'newest'],
28+
'php_unit_method_casing' => true,
29+
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
30+
'phpdoc_to_comment' => false,
31+
'void_return' => true,
32+
])
33+
->setFinder(PhpCsFixer\Finder::create()
34+
->exclude('vendor')
35+
->in(__DIR__)
36+
)
37+
;

.php_cs.dist

-43
This file was deleted.

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ext-mbstring": "*"
3131
},
3232
"require-dev": {
33-
"friendsofphp/php-cs-fixer": "^2.16",
33+
"friendsofphp/php-cs-fixer": "~3.0.0",
3434
"maglnet/composer-require-checker": "^2.0|^3.2",
3535
"nikic/php-parser": "^4.3,<4.7|^4.10",
3636
"paragonie/hidden-string": "^1.0",
@@ -44,11 +44,11 @@
4444
},
4545
"scripts": {
4646
"static-analysis": [
47-
"parallel-lint .php_cs.dist src tests examples",
47+
"parallel-lint .php-cs-fixer.dist.php src tests examples",
4848
"phpcpd src tests",
4949
"composer-require-checker check ./composer.json",
5050
"phpmnd ./ --exclude=./.github/ --exclude=./examples/ --exclude=./vendor/ --non-zero-exit-on-violation --hint",
51-
"php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run --diff-format=udiff -v",
51+
"php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run -v",
5252
"psalm --show-info=false"
5353
],
5454
"tests": [

psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
cacheDirectory="./psalm/cache/"
1212
>
1313
<projectFiles>
14-
<file name="./.php_cs.dist"/>
14+
<file name="./.php-cs-fixer.dist.php"/>
1515
<directory name="src"/>
1616
<directory name="tests"/>
1717
<directory name="examples"/>

src/PhpImap/DataPartInfo.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
class DataPartInfo
1818
{
19-
const TEXT_PLAIN = 0;
19+
public const TEXT_PLAIN = 0;
2020

21-
const TEXT_HTML = 1;
21+
public const TEXT_HTML = 1;
2222

2323
/**
2424
* @var int

src/PhpImap/Imap.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
final class Imap
4242
{
4343
/** @psalm-var list<int> */
44-
const SORT_CRITERIA = [
44+
public const SORT_CRITERIA = [
4545
SORTARRIVAL,
4646
SORTCC,
4747
SORTDATE,
@@ -52,15 +52,15 @@ final class Imap
5252
];
5353

5454
/** @psalm-var list<int> */
55-
const TIMEOUT_TYPES = [
55+
public const TIMEOUT_TYPES = [
5656
IMAP_CLOSETIMEOUT,
5757
IMAP_OPENTIMEOUT,
5858
IMAP_READTIMEOUT,
5959
IMAP_WRITETIMEOUT,
6060
];
6161

6262
/** @psalm-var list<int> */
63-
const CLOSE_FLAGS = [
63+
public const CLOSE_FLAGS = [
6464
0,
6565
CL_EXPUNGE,
6666
];

src/PhpImap/IncomingMail.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function embedImageAttachments(): void
221221
foreach ($attachments as $attachment) {
222222
/**
223223
* Inline images can contain a "Content-Disposition: inline", but only a "Content-ID" is also enough.
224-
* See https://github.com/barbushin/php-imap/issues/569
224+
* See https://github.com/barbushin/php-imap/issues/569.
225225
*/
226226
if ($attachment->contentId == $cid || 'inline' == \mb_strtolower((string) $attachment->disposition)) {
227227
$contents = $attachment->getContents();

src/PhpImap/Mailbox.php

+34-34
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@
8282
*/
8383
class Mailbox
8484
{
85-
const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2;
85+
public const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2;
8686

87-
const MAX_LENGTH_FILEPATH = 255;
87+
public const MAX_LENGTH_FILEPATH = 255;
8888

89-
const PART_TYPE_TWO = 2;
89+
public const PART_TYPE_TWO = 2;
9090

91-
const IMAP_OPTIONS_SUPPORTED_VALUES =
91+
public const IMAP_OPTIONS_SUPPORTED_VALUES =
9292
OP_READONLY // 2
9393
| OP_ANONYMOUS // 4
9494
| OP_HALFOPEN // 64
@@ -1329,7 +1329,7 @@ public function downloadAttachment(DataPartInfo $dataInfo, array $params, object
13291329
}
13301330

13311331
/**
1332-
* Converts a string to UTF-8
1332+
* Converts a string to UTF-8.
13331333
*
13341334
* @param string $string MIME string to decode
13351335
* @param string $fromCharset Charset to convert from
@@ -1338,35 +1338,35 @@ public function downloadAttachment(DataPartInfo $dataInfo, array $params, object
13381338
*/
13391339
public function convertToUtf8(string $string, string $fromCharset): string
13401340
{
1341-
$fromCharset = mb_strtolower($fromCharset);
1342-
$newString = '';
1343-
1344-
if ('default' === $fromCharset) {
1345-
$fromCharset = $this->decodeMimeStrDefaultCharset;
1346-
}
1347-
1348-
switch ($fromCharset) {
1349-
case 'default': // Charset default is already ASCII (not encoded)
1350-
case 'utf-8': // Charset UTF-8 is OK
1351-
$newString .= $string;
1352-
break;
1353-
default:
1354-
// If charset exists in mb_list_encodings(), convert using mb_convert function
1355-
if (\in_array($fromCharset, $this->lowercase_mb_list_encodings(), true)) {
1356-
$newString .= \mb_convert_encoding($string, 'UTF-8', $fromCharset);
1357-
} else {
1358-
// Fallback: Try to convert with iconv()
1359-
$iconv_converted_string = @\iconv($fromCharset, 'UTF-8', $string);
1360-
if (!$iconv_converted_string) {
1361-
// If iconv() could also not convert, return string as it is
1362-
// (unknown charset)
1363-
$newString .= $string;
1364-
} else {
1365-
$newString .= $iconv_converted_string;
1366-
}
1367-
}
1368-
break;
1369-
}
1341+
$fromCharset = mb_strtolower($fromCharset);
1342+
$newString = '';
1343+
1344+
if ('default' === $fromCharset) {
1345+
$fromCharset = $this->decodeMimeStrDefaultCharset;
1346+
}
1347+
1348+
switch ($fromCharset) {
1349+
case 'default': // Charset default is already ASCII (not encoded)
1350+
case 'utf-8': // Charset UTF-8 is OK
1351+
$newString .= $string;
1352+
break;
1353+
default:
1354+
// If charset exists in mb_list_encodings(), convert using mb_convert function
1355+
if (\in_array($fromCharset, $this->lowercase_mb_list_encodings(), true)) {
1356+
$newString .= \mb_convert_encoding($string, 'UTF-8', $fromCharset);
1357+
} else {
1358+
// Fallback: Try to convert with iconv()
1359+
$iconv_converted_string = @\iconv($fromCharset, 'UTF-8', $string);
1360+
if (!$iconv_converted_string) {
1361+
// If iconv() could also not convert, return string as it is
1362+
// (unknown charset)
1363+
$newString .= $string;
1364+
} else {
1365+
$newString .= $iconv_converted_string;
1366+
}
1367+
}
1368+
break;
1369+
}
13701370

13711371
return $newString;
13721372
}

tests/unit/Issue509Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class Issue509Test extends TestCase
1616
{
17-
const base64 =
17+
public const base64 =
1818
'vsiz58fPvcq0z7HuLiC05MDlx9jB1rzFvK0gsKi758fVtM+02S4NCsDMt7EgwM/AuiC16b7uILq7
1919
wPvAzCC++L3AtM+02S4NCsDMwM8gvu62u7DUIMfPvcO0wsH2ILHDsd3H1bTPtNkuDQrBprChIMik
2020
vcMgsPi9xMD7wLi3ziCw7b/rtce++r3AtM+x7j8NCg0KU2VudCBmcm9tIE1haWw8aHR0cHM6Ly9n
@@ -41,7 +41,7 @@ class Issue509Test extends TestCase
4141
YW5ub24gRHJpdmUNCkUxNCA0QVMgTG9uZG9uDQp3d3cuY2xvdWR3b3JrZXJzLmNvbXBhbnkNCg0K
4242
DQo=';
4343

44-
const sha256 =
44+
public const sha256 =
4545
'5656f5f8a872b8989ba3aaecdfbdc6311bf4c5e0219c27b3b004ce83d8ffd6f3';
4646

4747
public function testDecode(): void

tests/unit/Issue519Test.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class Issue519Test extends TestCase
1919
{
20-
const HEADER_VALUES = [
20+
public const HEADER_VALUES = [
2121
'inline',
2222
'Inline',
2323
'iNline',
@@ -84,23 +84,23 @@ class Issue519Test extends TestCase
8484
'INLINE',
8585
];
8686

87-
const CID = 'cid:foo.jpg';
87+
public const CID = 'cid:foo.jpg';
8888

89-
const ID = 'foo.jpg';
89+
public const ID = 'foo.jpg';
9090

91-
const SUBTYPE = 'jpeg';
91+
public const SUBTYPE = 'jpeg';
9292

93-
const SIZE_IN_BYTES = 0;
93+
public const SIZE_IN_BYTES = 0;
9494

95-
const HTML = 'foo.html';
95+
public const HTML = 'foo.html';
9696

97-
const HTML_EMBED = '<img src="data:image/jpeg;base64, ">';
97+
public const HTML_EMBED = '<img src="data:image/jpeg;base64, ">';
9898

99-
const MIME = 'image/jpeg';
99+
public const MIME = 'image/jpeg';
100100

101-
const EXPECTED_ATTACHMENT_COUNT = 1;
101+
public const EXPECTED_ATTACHMENT_COUNT = 1;
102102

103-
const EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED = 0;
103+
public const EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED = 0;
104104

105105
/**
106106
* @psalm-return array<string, array{0:string}>

tests/unit/LiveMailboxTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
*/
4545
class LiveMailboxTest extends AbstractLiveMailboxTest
4646
{
47-
const RANDOM_MAILBOX_SAMPLE_SIZE = 3;
47+
public const RANDOM_MAILBOX_SAMPLE_SIZE = 3;
4848

49-
const ISSUE_EXPECTED_ATTACHMENT_COUNT = [
49+
public const ISSUE_EXPECTED_ATTACHMENT_COUNT = [
5050
448 => 1,
5151
391 => 2,
5252
];

tests/unit/LiveMailboxWithManualSetupTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class LiveMailboxWithManualSetupTest extends AbstractLiveMailboxTest
2626
{
2727
/**
28-
* @return Generator<int, array{0:string}, void, void>
28+
* @return Generator<int, array{0:string}|void, void>
2929
*/
3030
public function RelativeToRootPathProvider(): Generator
3131
{
@@ -35,7 +35,7 @@ public function RelativeToRootPathProvider(): Generator
3535
}
3636

3737
/**
38-
* @return Generator<int, array{0:MAILBOX_ARGS}, void, void>
38+
* @return Generator<int, array{0:MAILBOX_ARGS}|void, void>
3939
*/
4040
public function statusProviderAbsolutePath(): Generator
4141
{

tests/unit/MailboxTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
final class MailboxTest extends TestCase
3232
{
33-
const ANYTHING = 0;
33+
public const ANYTHING = 0;
3434

3535
/**
3636
* Holds the imap path.

0 commit comments

Comments
 (0)