1616
1717class 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