Skip to content

Commit 6abdfab

Browse files
authored
Merge pull request #12 from jolicode/maintenance
Maintenance commit
2 parents 4fa0006 + dc46355 commit 6abdfab

23 files changed

+2984
-537
lines changed

.castor/qa.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace qa;
1313

1414
use Castor\Attribute\AsOption;
15+
use Castor\Attribute\AsRawTokens;
1516
use Castor\Attribute\AsTask;
1617
use Symfony\Component\Console\Input\InputOption;
1718

18-
use function Castor\context;
19+
use function Castor\exit_code;
1920
use function Castor\run;
2021

2122
#[AsTask(description: 'Runs all QA tasks')]
@@ -47,6 +48,25 @@ function install(?string $only = null): void
4748
}
4849
}
4950

51+
#[AsTask(description: 'Update tooling')]
52+
function update(?string $only = null): void
53+
{
54+
$map = [
55+
'php-cs-fixer' => fn () => run('composer update --working-dir tools/php-cs-fixer'),
56+
'phpstan' => fn () => run('composer update --working-dir tools/phpstan'),
57+
'phpunit' => fn () => run('composer update --working-dir tools/phpunit'),
58+
'rector' => fn () => run('composer update --working-dir tools/rector'),
59+
];
60+
61+
if ($only) {
62+
$map = array_filter($map, fn ($key) => $key === $only, \ARRAY_FILTER_USE_KEY);
63+
}
64+
65+
foreach ($map as $task) {
66+
$task();
67+
}
68+
}
69+
5070
#[AsTask(description: 'Fix coding standards', aliases: ['cs'])]
5171
function cs(
5272
#[AsOption(name: 'dry-run', description: 'Do not make changes and outputs diff', mode: InputOption::VALUE_NONE)]
@@ -58,31 +78,23 @@ function cs(
5878
$command .= ' --dry-run --diff';
5979
}
6080

61-
$c = context()
62-
->withAllowFailure(true)
63-
;
64-
65-
return run($command, context: $c)->getExitCode();
81+
return exit_code($command);
6682
}
6783

6884
#[AsTask(description: 'Run the phpstan analysis', aliases: ['phpstan'])]
6985
function phpstan(): int
7086
{
71-
return run('tools/phpstan/vendor/bin/phpstan analyse')->getExitCode();
87+
return exit_code('tools/phpstan/vendor/bin/phpstan analyse -v');
7288
}
7389

74-
#[AsTask(description: 'Run the phpunit tests', aliases: ['phpunit'])]
75-
function phpunit(): int
90+
#[AsTask(description: 'Run the phpunit tests', ignoreValidationErrors: true, aliases: ['phpunit'])]
91+
function phpunit(#[AsRawTokens] array $rawTokens): int
7692
{
77-
$c = context()
78-
->withAllowFailure(true)
79-
;
80-
81-
return run('tools/phpunit/vendor/bin/simple-phpunit', context: $c)->getExitCode();
93+
return exit_code(['tools/phpunit/vendor/bin/phpunit', ...$rawTokens]);
8294
}
8395

8496
#[AsTask(description: 'Run the rector upgrade', aliases: ['rector'])]
8597
function rector(): int
8698
{
87-
return run('tools/rector/vendor/bin/rector process')->getExitCode();
99+
return exit_code('tools/rector/vendor/bin/rector process');
88100
}

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ jobs:
1515
strategy:
1616
matrix:
1717
php-versions:
18-
- "8.1"
19-
- "8.2"
2018
- "8.3"
19+
- "8.4"
20+
- "8.5"
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v5
2424

2525
- name: Setup PHP
2626
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: "${{ matrix.php-versions }}"
29-
tools: jolicode/castor
29+
tools: castor
3030

3131
- name: Validate composer.json and composer.lock
3232
run: composer validate --strict
@@ -49,13 +49,13 @@ jobs:
4949

5050
steps:
5151
- name: Checkout
52-
uses: actions/checkout@v4
52+
uses: actions/checkout@v5
5353

5454
- name: Setup PHP
5555
uses: shivammathur/setup-php@v2
5656
with:
5757
php-version: 8.3
58-
tools: jolicode/castor
58+
tools: castor
5959

6060
- name: Install dependencies
6161
run: castor install

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
return (new PhpCsFixer\Config())
3131
->setRiskyAllowed(true)
3232
->setRules([
33-
'@PHP81Migration' => true,
33+
'@PHP83Migration' => true,
3434
'@Symfony' => true,
3535
'@Symfony:risky' => true,
3636
'concat_space' => ['spacing' => 'one'],

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"require": {
19-
"php": ">=8.1",
19+
"php": ">=8.3",
2020
"ext-mbstring": "*",
2121
"lib-libxml": "*",
2222
"league/commonmark": "^2.4",

phpunit.xml.dist

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false"
4-
colors="true" bootstrap="vendor/autoload.php">
5-
<php>
6-
<ini name="error_reporting" value="-1" />
7-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0" />
8-
</php>
9-
<testsuites>
10-
<testsuite name="JoliMarkdown Test Suite">
11-
<directory>./tests/</directory>
12-
</testsuite>
13-
</testsuites>
14-
<coverage>
15-
<include>
16-
<directory>./</directory>
17-
</include>
18-
<exclude>
19-
<directory>./vendor</directory>
20-
</exclude>
21-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
3+
<php>
4+
<ini name="error_reporting" value="-1"/>
5+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0"/>
6+
</php>
7+
<testsuites>
8+
<testsuite name="JoliMarkdown Test Suite">
9+
<directory>./tests/</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory>./</directory>
15+
</include>
16+
<exclude>
17+
<directory>./vendor</directory>
18+
</exclude>
19+
</source>
2220
</phpunit>

src/Bridge/Symfony/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
class Configuration implements ConfigurationInterface
1818
{
19+
/**
20+
* @return TreeBuilder<'array'>
21+
*/
1922
public function getConfigTreeBuilder(): TreeBuilder
2023
{
2124
$treeBuilder = new TreeBuilder('joli_markdown');
2225

26+
/* @phpstan-ignore class.notFound */
2327
$treeBuilder->getRootNode()
2428
->children()
2529
->booleanNode('prefer_asterisk_over_underscore')

src/Fixer/HtmlBlockFixer.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ protected function buildNodeFromDomElement(\DOMNode $element, bool $allowLtrim =
207207

208208
if (\count($attributes) > 0) {
209209
// the span has attributes, so enclose its childNodes in CommonmarkContainers
210-
$openingNode = new InlineCommonmarkContainer(sprintf(
210+
$openingNode = new InlineCommonmarkContainer(\sprintf(
211211
'<span%s>',
212212
$this->outputAttributes($attributes),
213213
));
@@ -292,15 +292,15 @@ protected function buildNodeFromDomElement(\DOMNode $element, bool $allowLtrim =
292292
// try to let self-closed html tags as-is
293293
preg_match('/^<\s*([a-z0-9-]+)(\s[^>]*)?\/>$/', $elementXml, $matches);
294294

295-
if (isset($matches[1]) && preg_match(sprintf('/^<%s(\s[^>]*)?\>.*<\/%s>$/', $matches[1], $matches[1]), $converted, $subMatches)) {
295+
if (isset($matches[1]) && preg_match(\sprintf('/^<%s(\s[^>]*)?\>.*<\/%s>$/', $matches[1], $matches[1]), $converted, $subMatches)) {
296296
if (\in_array($matches[1], ['br', 'hr', 'source'])) {
297297
$converted = $elementXml;
298298
} else {
299299
$converted = $elementHtml;
300300
}
301301
}
302302

303-
if (isset($tagNameMatches[1]) || isset($matches[1]) && preg_match(sprintf('/^<%s(\s.*)?>$/', $matches[1]), $converted, $subMatches)) {
303+
if (isset($tagNameMatches[1]) || isset($matches[1]) && preg_match(\sprintf('/^<%s(\s.*)?>$/', $matches[1]), $converted, $subMatches)) {
304304
$attributes = [];
305305
}
306306
} else {
@@ -445,10 +445,10 @@ protected function fixAndReplace(string|array $literal, Node|array $nodes, strin
445445
$attributes = '';
446446

447447
foreach ($nodes[0]->data->get('attributes') as $key => $value) {
448-
$attributes .= sprintf(' %s="%s"', $key, Xml::escape($value));
448+
$attributes .= \sprintf(' %s="%s"', $key, Xml::escape($value));
449449
}
450450

451-
$literal = sprintf('<div%s>%s</div>', $attributes, $literal);
451+
$literal = \sprintf('<div%s>%s</div>', $attributes, $literal);
452452
}
453453

454454
$dom = new \DOMDocument();
@@ -498,6 +498,7 @@ protected function removeNode(Node $node): void
498498

499499
foreach ($newChildren as $key => $child) {
500500
if ($child === $node) {
501+
// @phpstan-ignore offsetAccess.nonOffsetAccessible
501502
unset($newChildren[$key]);
502503
}
503504
}
@@ -602,7 +603,7 @@ private function fixHtmlBlock(HtmlBlock $node): ?iterable
602603
}
603604

604605
if (!$isClosed) {
605-
$this->logger->info(sprintf('<%s> tag is NOT closed', $matches[1]));
606+
$this->logger->info(\sprintf('<%s> tag is NOT closed', $matches[1]));
606607
}
607608

608609
$fixedNodes = $this->fixAndReplace($literal, $closingNodes);

src/Fixer/HtmlInlineFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function fixHtmlInline(HtmlInline $node): ?iterable
103103
}
104104

105105
if (!$isClosed) {
106-
$this->logger->info(sprintf('<%s> tag is NOT closed', $matches[1]));
106+
$this->logger->info(\sprintf('<%s> tag is NOT closed', $matches[1]));
107107
}
108108

109109
$fixedNodes = $this->fixAndReplace(

src/Fixer/ImageFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function fix(Node $node): ?iterable
4747

4848
if (str_starts_with($node->getUrl(), 'http')) {
4949
$this->logger->notice(
50-
sprintf(
50+
\sprintf(
5151
'Image with absolute path found: %s',
5252
$node->getUrl(),
5353
)

src/MarkdownFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
$internalDomains = $environment->getConfiguration()->get('joli_markdown/internal_domains');
4747

4848
if (\is_array($internalDomains) && 0 !== \count($internalDomains)) {
49-
$internalDomainsPattern = sprintf(
49+
$internalDomainsPattern = \sprintf(
5050
'#^(https?)?://(%s)/?#',
5151
implode('|', $internalDomains),
5252
);

0 commit comments

Comments
 (0)