Skip to content

Commit

Permalink
Use composer/patches
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 19, 2024
1 parent f83d859 commit 21b287e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 929 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.* export-ignore
patches export-ignore
tests export-ignore
infection.json export-ignore
Makefile export-ignore
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ jobs:
tools: composer:v2
ini-file: development

- name: Apply patches
run: composer config extra.patches.symfony/console --json '["patches/Table.patch"]'

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest
composer-options: --prefer-dist --prefer-stable

- name: Test 1
run: rm vendor/symfony/console/Helper/Table.php

- name: Test 2
run: mv tmp/Table.php vendor/symfony/console/Helper/Table.php

- name: Run tests with PHPUnit
run: vendor/bin/phpunit

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"webmozart/assert": "^1.10"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"dereuromark/composer-prefer-lowest": "^0.1.10",
"ergebnis/composer-normalize": "^2.29",
"friendsofphp/php-cs-fixer": "^3.13.0",
Expand Down Expand Up @@ -60,7 +61,8 @@
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"infection/extension-installer": true
"infection/extension-installer": true,
"cweagans/composer-patches": true
},
"sort-packages": true
}
Expand Down
62 changes: 62 additions & 0 deletions patches/Table.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--- vendor/symfony/console/Helper/Table.php 2024-01-23 16:02:46
+++ tmp/Table.php 2024-02-19 19:37:41
@@ -361,21 +361,21 @@
for ($i = 0; $i < $maxRows; ++$i) {
$cell = (string) ($row[$i] ?? '');

- $parts = explode("\n", $cell);
+ $parts = explode(\PHP_EOL, $cell);
foreach ($parts as $idx => $part) {
if ($headers && !$containsColspan) {
if (0 === $idx) {
$rows[] = [sprintf(
- '<comment>%s</>: %s',
- str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
- $part
- )];
+ '<comment>%s</>: %s',
+ str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
+ $part
+ )];
} else {
$rows[] = [sprintf(
- '%s %s',
- str_pad('', $maxHeaderLength, ' ', \STR_PAD_LEFT),
- $part
- )];
+ '%s %s',
+ str_pad('', $maxHeaderLength, ' ', \STR_PAD_LEFT),
+ $part
+ )];
}
} elseif ('' !== $cell) {
$rows[] = [$part];
@@ -629,12 +629,12 @@
if (isset($this->columnMaxWidths[$column]) && Helper::width(Helper::removeDecoration($formatter, $cell)) > $this->columnMaxWidths[$column]) {
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan);
}
- if (!str_contains($cell ?? '', "\n")) {
+ if (!str_contains($cell ?? '', \PHP_EOL)) {
continue;
}
- $escaped = implode("\n", array_map(OutputFormatter::escapeTrailingBackslash(...), explode("\n", $cell)));
+ $escaped = implode(\PHP_EOL, array_map(OutputFormatter::escapeTrailingBackslash(...), explode(\PHP_EOL, $cell)));
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
- $lines = explode("\n", str_replace("\n", "<fg=default;bg=default></>\n", $cell));
+ $lines = explode(\PHP_EOL, str_replace(\PHP_EOL, "<fg=default;bg=default></>".\PHP_EOL, $cell));
foreach ($lines as $lineKey => $line) {
if ($colspan > 1) {
$line = new TableCell($line, ['colspan' => $colspan]);
@@ -695,9 +695,9 @@
if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
$nbLines = $cell->getRowspan() - 1;
$lines = [$cell];
- if (str_contains($cell, "\n")) {
- $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
- $nbLines = \count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
+ if (str_contains($cell, \PHP_EOL)) {
+ $lines = explode(\PHP_EOL, str_replace(\PHP_EOL, "<fg=default;bg=default>".\PHP_EOL."</>", $cell));
+ $nbLines = \count($lines) > $nbLines ? substr_count($cell, \PHP_EOL) : $nbLines;

$rows[$line][$column] = new TableCell($lines[0], ['colspan' => $cell->getColspan(), 'style' => $cell->getStyle()]);
unset($lines[0]);
Loading

0 comments on commit 21b287e

Please sign in to comment.