Skip to content

Commit 14ff869

Browse files
committed
4.0 | Generators: add parameter types
Includes changing the expected parameter type for a couple of methods from `DomNode` to `DomElement`. The previous was incorrect, but changing the method signature by making a type more specific, is a breaking change, so had to wait until now.
1 parent cd53c0f commit 14ff869

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

src/Generators/Generator.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public function __construct(Ruleset $ruleset)
7575

7676

7777
/**
78-
* Retrieves the title of the sniff from the DOMNode supplied.
78+
* Retrieves the title of the sniff from the DOMElement supplied.
7979
*
80-
* @param \DOMNode $doc The DOMNode object for the sniff.
81-
* It represents the "documentation" tag in the XML
82-
* standard file.
80+
* @param \DOMElement $doc The DOMElement object for the sniff.
81+
* It represents the "documentation" tag in the XML
82+
* standard file.
8383
*
8484
* @return string
8585
*/
86-
protected function getTitle(DOMNode $doc)
86+
protected function getTitle(DOMElement $doc)
8787
{
8888
$title = $doc->getAttribute('title');
8989

@@ -141,14 +141,14 @@ public function generate()
141141
*
142142
* Doc generators must implement this function to produce output.
143143
*
144-
* @param \DOMNode $doc The DOMNode object for the sniff.
145-
* It represents the "documentation" tag in the XML
146-
* standard file.
144+
* @param \DOMElement $doc The DOMElement object for the sniff.
145+
* It represents the "documentation" tag in the XML
146+
* standard file.
147147
*
148148
* @return void
149149
* @see generate()
150150
*/
151-
abstract protected function processSniff(DOMNode $doc);
151+
abstract protected function processSniff(DOMElement $doc);
152152

153153

154154
}//end class

src/Generators/HTML.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ protected function getFormattedFooter()
262262
/**
263263
* Process the documentation for a single sniff.
264264
*
265-
* @param \DOMNode $doc The DOMNode object for the sniff.
266-
* It represents the "documentation" tag in the XML
267-
* standard file.
265+
* @param \DOMElement $doc The DOMElement object for the sniff.
266+
* It represents the "documentation" tag in the XML
267+
* standard file.
268268
*
269269
* @return void
270270
*/
271-
public function processSniff(DOMNode $doc)
271+
public function processSniff(DOMElement $doc)
272272
{
273273
$content = '';
274274
foreach ($doc->childNodes as $node) {
@@ -301,7 +301,7 @@ public function processSniff(DOMNode $doc)
301301
*
302302
* @return string
303303
*/
304-
private function titleToAnchor($title)
304+
private function titleToAnchor(string $title)
305305
{
306306
// Slugify the text.
307307
$title = strtolower($title);

src/Generators/Markdown.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ protected function getFormattedFooter()
100100
/**
101101
* Process the documentation for a single sniff.
102102
*
103-
* @param \DOMNode $doc The DOMNode object for the sniff.
104-
* It represents the "documentation" tag in the XML
105-
* standard file.
103+
* @param \DOMElement $doc The DOMElement object for the sniff.
104+
* It represents the "documentation" tag in the XML
105+
* standard file.
106106
*
107107
* @return void
108108
*/
109-
protected function processSniff(DOMNode $doc)
109+
protected function processSniff(DOMElement $doc)
110110
{
111111
$content = '';
112112
foreach ($doc->childNodes as $node) {

src/Generators/Text.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ class Text extends Generator
2323
/**
2424
* Process the documentation for a single sniff.
2525
*
26-
* @param \DOMNode $doc The DOMNode object for the sniff.
27-
* It represents the "documentation" tag in the XML
28-
* standard file.
26+
* @param \DOMElement $doc The DOMElement object for the sniff.
27+
* It represents the "documentation" tag in the XML
28+
* standard file.
2929
*
3030
* @return void
3131
*/
32-
public function processSniff(DOMNode $doc)
32+
public function processSniff(DOMElement $doc)
3333
{
3434
$content = '';
3535
foreach ($doc->childNodes as $node) {
@@ -50,16 +50,16 @@ public function processSniff(DOMNode $doc)
5050
/**
5151
* Format the title area for a single sniff.
5252
*
53-
* @param \DOMNode $doc The DOMNode object for the sniff.
54-
* It represents the "documentation" tag in the XML
55-
* standard file.
53+
* @param \DOMElement $doc The DOMElement object for the sniff.
54+
* It represents the "documentation" tag in the XML
55+
* standard file.
5656
*
5757
* @since 3.12.0 Replaces the Text::printTitle() method,
5858
* which was deprecated in 3.12.0 and removed in 4.0.0.
5959
*
6060
* @return string
6161
*/
62-
protected function getFormattedTitle(DOMNode $doc)
62+
protected function getFormattedTitle(DOMElement $doc)
6363
{
6464
$title = $this->getTitle($doc);
6565
$standard = $this->ruleset->name;

tests/Core/Generators/Fixtures/MockGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace PHP_CodeSniffer\Tests\Core\Generators\Fixtures;
1010

11-
use DOMNode;
11+
use DOMElement;
1212
use PHP_CodeSniffer\Generators\Generator;
1313

1414
class MockGenerator extends Generator
@@ -17,11 +17,11 @@ class MockGenerator extends Generator
1717
/**
1818
* Process the documentation for a single sniff.
1919
*
20-
* @param \DOMNode $doc The DOMNode object for the sniff.
20+
* @param \DOMElement $doc The DOMElement object for the sniff.
2121
*
2222
* @return void
2323
*/
24-
protected function processSniff(DOMNode $doc)
24+
protected function processSniff(DOMElement $doc)
2525
{
2626
echo $this->getTitle($doc), PHP_EOL;
2727
}

0 commit comments

Comments
 (0)