Skip to content

Commit e29a2d3

Browse files
authored
Migrate to PHP-CS-Fixer 3.x (#58)
- Uses bamarni for installing PHP-CS-Fixer instead of being a dev dependency - Install PHP-CS-Fixer 3.x - Apply the CS Fixer
1 parent 9c5452e commit e29a2d3

17 files changed

+2443
-250
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/.idea
2+
/.php-cs-fixer.cache
23
/.php_cs.cache
34
/.phpunit.result.cache
45
/composer.lock
56
/var/
7+
/vendor-bin/*/vendor/
68
/vendor/

.php-cs-fixer.php

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the Fidry\Console package.
5+
*
6+
* (c) Théo FIDRY <[email protected]>
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+
use PhpCsFixer\Config;
13+
use PhpCsFixer\Finder;
14+
15+
return (new Config())
16+
->setUsingCache(true)
17+
->setRiskyAllowed(true)
18+
->setRules([
19+
'@Symfony' => true,
20+
'@PHPUnit75Migration:risky' => true,
21+
'align_multiline_comment' => true,
22+
'array_indentation' => true,
23+
'array_syntax' => false,
24+
'backtick_to_shell_exec' => true,
25+
'blank_line_between_import_groups' => false,
26+
'combine_consecutive_issets' => true,
27+
'combine_consecutive_unsets' => true,
28+
'combine_nested_dirname' => true,
29+
'compact_nullable_typehint' => true,
30+
'declare_strict_types' => true,
31+
'dir_constant' => true,
32+
'echo_tag_syntax' => [
33+
'format' => 'short',
34+
],
35+
'ereg_to_preg' => true,
36+
'fopen_flag_order' => true,
37+
'fopen_flags' => true,
38+
'fully_qualified_strict_types' => true,
39+
'general_phpdoc_annotation_remove' => true,
40+
'global_namespace_import' => [
41+
'import_classes' => true,
42+
'import_constants' => true,
43+
'import_functions' => true,
44+
],
45+
'header_comment' => [
46+
'header' => <<<EOF
47+
This file is part of the Webmozarts Console Parallelization package.
48+
49+
(c) Webmozarts GmbH <[email protected]>
50+
51+
For the full copyright and license information, please view the LICENSE
52+
file that was distributed with this source code.
53+
EOF,
54+
'location' => 'after_open',
55+
],
56+
'is_null' => true,
57+
'list_syntax' => [
58+
'syntax' => 'short',
59+
],
60+
'logical_operators' => true,
61+
'mb_str_functions' => true,
62+
'no_superfluous_phpdoc_tags' => [
63+
'remove_inheritdoc' => true,
64+
// Required for Psalm
65+
'allow_mixed' => true,
66+
],
67+
'modernize_types_casting' => true,
68+
'multiline_comment_opening_closing' => true,
69+
'no_alternative_syntax' => true,
70+
'no_binary_string' => true,
71+
'no_homoglyph_names' => true,
72+
'no_php4_constructor' => true,
73+
'no_superfluous_elseif' => true,
74+
'no_unset_cast' => true,
75+
'no_unset_on_property' => true,
76+
'no_useless_else' => true,
77+
'no_useless_return' => true,
78+
'nullable_type_declaration_for_default_null_value' => true,
79+
'ordered_class_elements' => true,
80+
'ordered_imports' => true,
81+
'phpdoc_order_by_value' => true,
82+
'phpdoc_separation' => false,
83+
'phpdoc_to_comment' => false,
84+
// Exclude "meta" which renames "Resource" to "resource"
85+
'phpdoc_types' => ['groups' => ['simple', 'alias']],
86+
'php_unit_construct' => true,
87+
'php_unit_method_casing' => [
88+
'case' => 'snake_case',
89+
],
90+
'php_unit_set_up_tear_down_visibility' => true,
91+
'php_unit_test_case_static_method_calls' => [
92+
'call_type' => 'self'
93+
],
94+
'php_unit_test_class_requires_covers' => false,
95+
'phpdoc_order' => true,
96+
'phpdoc_types_order' => false,
97+
'phpdoc_var_annotation_correct_order' => true,
98+
'pow_to_exponentiation' => true,
99+
'protected_to_private' => true,
100+
'self_static_accessor' => true,
101+
'single_line_throw' => false,
102+
'single_trait_insert_per_statement' => false,
103+
// TODO: enable once we are on 8.1 min
104+
// 'trailing_comma_in_multiline' => [
105+
// 'after_heredoc' => true,
106+
// 'elements' => ['arrays', 'arguments', 'parameters'],
107+
// ],
108+
])
109+
->setFinder(
110+
Finder::create()
111+
->in(__DIR__)
112+
->exclude([
113+
'dist',
114+
'var',
115+
]),
116+
);

.php_cs

-39
This file was deleted.

composer.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"ext-json": "*",
27-
"friendsofphp/php-cs-fixer": "^2.15",
27+
"bamarni/composer-bin-plugin": "^1.8",
2828
"phpunit/phpunit": "^8.4",
2929
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0"
3030
},
@@ -41,6 +41,13 @@
4141
},
4242

4343
"config": {
44-
"sort-packages": true
44+
"sort-packages": true,
45+
"allow-plugins": {
46+
"bamarni/composer-bin-plugin": true
47+
},
48+
"bamarni-bin": {
49+
"bin-links": false,
50+
"forward-command": false
51+
}
4552
}
4653
}

src/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace Webmozarts\Console\Parallelization;
1515

16-
use Webmozart\Assert\Assert;
1716
use function ceil;
1817
use function sprintf;
18+
use Webmozart\Assert\Assert;
1919

2020
final class Configuration
2121
{

src/ContainerAwareCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
2525
*/
2626
private $container;
2727

28-
public function setContainer(ContainerInterface $container = null): void
28+
public function setContainer(?ContainerInterface $container = null): void
2929
{
3030
$this->container = $container;
3131
}

src/ItemBatchIterator.php

+49-50
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313

1414
namespace Webmozarts\Console\Parallelization;
1515

16-
use Closure;
17-
use Webmozart\Assert\Assert;
1816
use function array_chunk;
1917
use function array_values;
18+
use Closure;
2019
use function count;
2120
use function get_class;
2221
use function gettype;
2322
use function is_numeric;
2423
use function is_object;
2524
use function sprintf;
25+
use Webmozart\Assert\Assert;
2626

2727
final class ItemBatchIterator
2828
{
@@ -31,56 +31,8 @@ final class ItemBatchIterator
3131
private $batchSize;
3232
private $itemsChunks;
3333

34-
/**
35-
* @param Closure(): list<string> $fetchItems
36-
*/
37-
public static function create(?string $item, Closure $fetchItems, int $batchSize): self
38-
{
39-
if (null !== $item) {
40-
$items = [$item];
41-
} else {
42-
$items = $fetchItems();
43-
44-
Assert::isArray(
45-
$items,
46-
sprintf(
47-
'Expected the fetched items to be a list of strings. Got "%s"',
48-
gettype($items)
49-
)
50-
);
51-
}
52-
53-
return new self($items, $batchSize);
54-
}
55-
56-
/**
57-
* @return list<string>
58-
*/
59-
private static function normalizeItems($items): array
60-
{
61-
foreach ($items as $index => $item) {
62-
if (is_numeric($item)) {
63-
$items[$index] = (string) $item;
64-
65-
continue;
66-
}
67-
68-
Assert::string(
69-
$item,
70-
sprintf(
71-
'The items are potentially passed to the child processes via the STDIN. For this reason they are expected to be string values. Got "%s" for the item "%s"',
72-
is_object($item) ? get_class($item) : gettype($item),
73-
$index
74-
)
75-
);
76-
}
77-
78-
return array_values($items);
79-
}
80-
8134
/**
8235
* @param list<string> $items
83-
* @param int $batchSize
8436
*/
8537
public function __construct(array $items, int $batchSize)
8638
{
@@ -103,6 +55,28 @@ public function __construct(array $items, int $batchSize)
10355
$this->batchSize = $batchSize;
10456
}
10557

58+
/**
59+
* @param Closure(): list<string> $fetchItems
60+
*/
61+
public static function create(?string $item, Closure $fetchItems, int $batchSize): self
62+
{
63+
if (null !== $item) {
64+
$items = [$item];
65+
} else {
66+
$items = $fetchItems();
67+
68+
Assert::isArray(
69+
$items,
70+
sprintf(
71+
'Expected the fetched items to be a list of strings. Got "%s"',
72+
gettype($items)
73+
)
74+
);
75+
}
76+
77+
return new self($items, $batchSize);
78+
}
79+
10680
/**
10781
* @return list<string>
10882
*/
@@ -128,4 +102,29 @@ public function getItemBatches(): array
128102
{
129103
return $this->itemsChunks;
130104
}
105+
106+
/**
107+
* @return list<string>
108+
*/
109+
private static function normalizeItems($items): array
110+
{
111+
foreach ($items as $index => $item) {
112+
if (is_numeric($item)) {
113+
$items[$index] = (string) $item;
114+
115+
continue;
116+
}
117+
118+
Assert::string(
119+
$item,
120+
sprintf(
121+
'The items are potentially passed to the child processes via the STDIN. For this reason they are expected to be string values. Got "%s" for the item "%s"',
122+
is_object($item) ? get_class($item) : gettype($item),
123+
$index
124+
)
125+
);
126+
}
127+
128+
return array_values($items);
129+
}
131130
}

0 commit comments

Comments
 (0)