Skip to content

Commit a40d7cc

Browse files
committed
Add Laravel Pint and apply PSR-12 formatting
Update build script include patterns to match Pint's formatting.
1 parent 9e18cfd commit a40d7cc

16 files changed

Lines changed: 200 additions & 131 deletions

build/build.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161

6262
// Replace the include() calls with the actual file contents
6363
$output = str_replace(
64-
'<?php include(__DIR__ . "/../dist/styles.css"); ?>',
64+
"<?php include __DIR__.'/../dist/styles.css'; ?>",
6565
$css,
6666
$output
6767
);
6868

6969
$output = str_replace(
70-
'<?php include(__DIR__ . "/../dist/app.js"); ?>',
70+
"<?php include __DIR__.'/../dist/app.js'; ?>",
7171
$js,
7272
$output
7373
);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"ext-dom": "*"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^11.0|^12.0"
34+
"phpunit/phpunit": "^11.0|^12.0",
35+
"laravel/pint": "^1.29"
3536
}
3637
}

helpers.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<?php
22

3-
if (!function_exists('items')) {
4-
function items(iterable $items = []): \STS\Phpinfo\Support\Items
3+
use STS\Phpinfo\Info;
4+
use STS\Phpinfo\Support\Items;
5+
6+
if (! function_exists('items')) {
7+
function items(iterable $items = []): Items
58
{
6-
return new \STS\Phpinfo\Support\Items($items);
9+
return new Items($items);
710
}
811
}
912

10-
if (!function_exists('prettyphpinfo')) {
13+
if (! function_exists('prettyphpinfo')) {
1114
/**
1215
* Display a pretty, searchable phpinfo() page.
1316
*
14-
* @param int $what The INFO_* constants bitmask, same as native phpinfo().
17+
* @param int $what The INFO_* constants bitmask, same as native phpinfo().
1518
*/
1619
function prettyphpinfo(int $what = INFO_ALL): void
1720
{
18-
\STS\Phpinfo\Info::capture($what)->render();
21+
Info::capture($what)->render();
1922
}
2023
}

pint.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"exclude": [
3+
"dist"
4+
]
5+
}

resources/template.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta name="viewport" content="width=device-width, initial-scale=1">
1111

1212
<style>
13-
<?php include(__DIR__ . "/../dist/styles.css"); ?>
13+
<?php include __DIR__.'/../dist/styles.css'; ?>
1414
</style>
1515
</head>
1616

@@ -201,7 +201,7 @@ class="px-4 py-1 rounded block"
201201
hash: null,
202202
mobileNav: false,
203203
info: <?php echo json_encode($info) ?>,
204-
sections: <?php echo json_encode($info->modules()->map(fn($m) => $m->key())->values()) ?>,
204+
sections: <?php echo json_encode($info->modules()->map(fn ($m) => $m->key())->values()) ?>,
205205
selected: null,
206206
selectedIndex: null,
207207
initialized: false,
@@ -378,7 +378,7 @@ class="px-4 py-1 rounded block"
378378
});
379379
</script>
380380
<script type="module">
381-
<?php include(__DIR__ . "/../dist/app.js"); ?>
381+
<?php include __DIR__.'/../dist/app.js'; ?>
382382
</script>
383383
</body>
384384
</html>

src/Models/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public static function fromValues(array $values): static
2929
public function key(): string
3030
{
3131
return $this->name === 'Names'
32-
? 'config_names_' . md5((string) $this->localValue())
33-
: 'config_' . Str::slug($this->name);
32+
? 'config_names_'.md5((string) $this->localValue())
33+
: 'config_'.Str::slug($this->name);
3434
}
3535

3636
public function name(): string

src/Models/Group.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function addNote(string $note): self
3838
public function key(): string
3939
{
4040
return $this->name
41-
? 'group_' . Str::slug($this->name)
42-
: 'group_' . md5($this->configs()->map(fn($c) => $c->name())->implode(','));
41+
? 'group_'.Str::slug($this->name)
42+
: 'group_'.md5($this->configs()->map(fn ($c) => $c->name())->implode(','));
4343
}
4444

4545
public function name(): ?string
@@ -83,7 +83,7 @@ public function jsonSerialize(): mixed
8383
'key' => $this->key(),
8484
'name' => $this->name(),
8585
'headings' => $this->headings(),
86-
'shortHeadings' => $this->headings()->map(fn($heading) => $this->shorten($heading)),
86+
'shortHeadings' => $this->headings()->map(fn ($heading) => $this->shorten($heading)),
8787
'configs' => $this->configs()->values(),
8888
'note' => $this->note(),
8989
];

src/Models/Module.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct(
1515

1616
public function key(): string
1717
{
18-
return 'module_' . Str::slug($this->name);
18+
return 'module_'.Str::slug($this->name);
1919
}
2020

2121
public function name(): string
@@ -30,7 +30,7 @@ public function groups(): Items
3030

3131
public function configs(): Items
3232
{
33-
return $this->groups()->flatMap(fn(Group $g) => $g->configs());
33+
return $this->groups()->flatMap(fn (Group $g) => $g->configs());
3434
}
3535

3636
public function hasConfig(string $name): bool
@@ -45,7 +45,7 @@ public function config(string $name, string $which = 'local'): ?string
4545

4646
public function combinedKeyFor(Config $config): string
4747
{
48-
return $this->key() . '_' . $config->key();
48+
return $this->key().'_'.$config->key();
4949
}
5050

5151
public function jsonSerialize(): mixed
@@ -62,6 +62,6 @@ public function findConfig(string $name): ?Config
6262
$slug = Str::slug($name);
6363

6464
return $this->configs()
65-
->first(fn(Config $config) => Str::slug($config->name()) === $slug);
65+
->first(fn (Config $config) => Str::slug($config->name()) === $slug);
6666
}
6767
}

src/Parsers/HtmlParser.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
class HtmlParser implements Parser
1818
{
19-
protected DOMXpath $xpath;
19+
protected DOMXPath $xpath;
2020

2121
public function __construct(protected string $contents)
2222
{
23-
if (!static::canParse($contents)) {
23+
if (! static::canParse($contents)) {
2424
throw new InvalidArgumentException('Content provided does not appear to be valid phpinfo() HTML output');
2525
}
2626
}
@@ -36,15 +36,15 @@ public function parse(): PhpInfo
3636
$version = str_replace('PHP Version ', '', $this->xpath()->query('//body//h1')[0]->nodeValue);
3737

3838
$modules = items($this->xpath()->query('//body//h2'))
39-
->reject(fn(DOMElement $heading) => $heading->nodeValue === 'PHP License')
40-
->map(fn(DOMElement $heading) => new Module($heading->nodeValue, $this->findGroupedConfigsFor($heading)));
39+
->reject(fn (DOMElement $heading) => $heading->nodeValue === 'PHP License')
40+
->map(fn (DOMElement $heading) => new Module($heading->nodeValue, $this->findGroupedConfigsFor($heading)));
4141

4242
// General info comes from the second table, prepend it
4343
$modules->prepend(
4444
new Module('General', items([
4545
new Group(
4646
items($this->xpath()->query('//body//table[2]/tr'))
47-
->map(fn(DOMElement $row) => new Config(
47+
->map(fn (DOMElement $row) => new Config(
4848
trim($row->firstChild->nodeValue),
4949
trim($row->lastChild->nodeValue),
5050
))
@@ -69,7 +69,7 @@ public function parse(): PhpInfo
6969
$lastH2->nodeValue,
7070
items([
7171
Group::noteOnly(
72-
items($lastTd->childNodes)->map(fn($n) => $n->nodeValue)->implode("\n\n")
72+
items($lastTd->childNodes)->map(fn ($n) => $n->nodeValue)->implode("\n\n")
7373
),
7474
])
7575
)
@@ -94,10 +94,11 @@ protected function findGroupedConfigsFor(DOMElement $heading): Items
9494
// This is a note — attach to the most recent group
9595
$groups->last()?->addNote(
9696
items($current->childNodes[0]->childNodes[0]->childNodes)
97-
->map(fn($n) => $n->nodeValue)
97+
->map(fn ($n) => $n->nodeValue)
9898
->filter()
9999
->implode("\n")
100100
);
101+
101102
continue;
102103
} else {
103104
$title = $current->childNodes[0]->childNodes[0]->nodeValue;
@@ -112,7 +113,7 @@ protected function findGroupedConfigsFor(DOMElement $heading): Items
112113

113114
// Detect header row
114115
$headings = in_array($current->childNodes[$firstRowIndex]?->firstChild->nodeValue, ['Directive', 'Variable', 'Contribution', 'Module'])
115-
? items($current->childNodes[$firstRowIndex]->childNodes)->map(fn($n) => $n->nodeValue)
116+
? items($current->childNodes[$firstRowIndex]->childNodes)->map(fn ($n) => $n->nodeValue)
116117
: items();
117118

118119
// Single-value rows (some credits tables)
@@ -122,15 +123,16 @@ protected function findGroupedConfigsFor(DOMElement $heading): Items
122123
$headings,
123124
$title,
124125
));
126+
125127
continue;
126128
}
127129

128130
$groups->push(new Group(
129131
items($current->childNodes)
130-
->filter(fn($node) => $node instanceof DOMElement && $node->nodeName === 'tr' && $node->childNodes->length > 1)
131-
->reject(fn(DOMElement $node) => in_array($node->firstChild->nodeValue, ['Directive', 'Variable', 'Contribution', 'Module']))
132-
->map(fn(DOMElement $row) => $this->rowToValues($row))
133-
->map(fn(array $values) => Config::fromValues($values)),
132+
->filter(fn ($node) => $node instanceof DOMElement && $node->nodeName === 'tr' && $node->childNodes->length > 1)
133+
->reject(fn (DOMElement $node) => in_array($node->firstChild->nodeValue, ['Directive', 'Variable', 'Contribution', 'Module']))
134+
->map(fn (DOMElement $row) => $this->rowToValues($row))
135+
->map(fn (array $values) => Config::fromValues($values)),
134136
$headings,
135137
$title,
136138
));
@@ -159,18 +161,18 @@ protected function nextTableSibling(DOMNode $current): ?DOMElement
159161
protected function rowToValues(DOMElement $row): array
160162
{
161163
return items($row->childNodes)
162-
->reject(fn($node) => $node instanceof DOMText)
163-
->map(fn(DOMElement $cell) => trim($cell->nodeValue))
164+
->reject(fn ($node) => $node instanceof DOMText)
165+
->map(fn (DOMElement $cell) => trim($cell->nodeValue))
164166
->values()
165167
->all();
166168
}
167169

168170
protected function xpath(): DOMXPath
169171
{
170-
if (!isset($this->xpath)) {
171-
$document = new DOMDocument();
172+
if (! isset($this->xpath)) {
173+
$document = new DOMDocument;
172174
$document->loadHTML(str_replace(["\r\n", "\n"], '', $this->contents), LIBXML_NOERROR);
173-
$this->xpath = new DOMXpath($document);
175+
$this->xpath = new DOMXPath($document);
174176
}
175177

176178
return $this->xpath;

0 commit comments

Comments
 (0)