Skip to content

Commit c5f3cc0

Browse files
committed
Lint
1 parent fc4009d commit c5f3cc0

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

lib/experimental/html/class-wp-html-tag-processor.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@
181181
*/
182182
class WP_HTML_Tag_Processor {
183183
/**
184+
* The maximum number of bookmarks allowed to exist at
185+
* any given time.
186+
*
184187
* @see set_bookmark();
185188
* @since 6.2.0
186189
* @var int
@@ -1175,8 +1178,8 @@ private function apply_attributes_updates() {
11751178
usort( $this->attribute_updates, array( self::class, 'sort_start_ascending' ) );
11761179

11771180
foreach ( $this->attribute_updates as $diff ) {
1178-
$this->updated_html .= substr( $this->html, $this->updated_bytes, $diff->start - $this->updated_bytes );
1179-
$this->updated_html .= $diff->text;
1181+
$this->updated_html .= substr( $this->html, $this->updated_bytes, $diff->start - $this->updated_bytes );
1182+
$this->updated_html .= $diff->text;
11801183
$this->updated_bytes = $diff->end;
11811184
}
11821185

@@ -1241,7 +1244,7 @@ public function seek( $bookmark_name ) {
12411244
* loop somehow.
12421245
*/
12431246
++$this->seek_counter;
1244-
if($this->seek_counter > $this->max_seek_calls) {
1247+
if ( $this->seek_counter > $this->max_seek_calls ) {
12451248
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
12461249
throw new Exception( "Too many seek() calls ({$this->seek_counter}) – did you run into an infinite loop accidentally? If not, you may adjust this via the `seek_limit( \$new_limit )` method." );
12471250
}
@@ -1250,7 +1253,7 @@ public function seek( $bookmark_name ) {
12501253

12511254
$this->apply_html_updates_and_stay_on_current_tag();
12521255

1253-
// Point this tag processor before the sought tag opener and consume it
1256+
// Point this tag processor before the sought tag opener and consume it.
12541257
$this->parsed_bytes = $this->bookmarks[ $bookmark_name ]->start;
12551258
$this->updated_bytes = $this->parsed_bytes;
12561259
$this->updated_html = substr( $this->html, 0, $this->updated_bytes );
@@ -1266,8 +1269,8 @@ public function seek( $bookmark_name ) {
12661269
* @param int $new_limit Optional. The maximum allowed number of seek() calls.
12671270
* @return number The allowed number of seek() calls.
12681271
*/
1269-
public function seek_limit( $new_limit=null ) {
1270-
if(is_int($new_limit)) {
1272+
public function seek_limit( $new_limit = null ) {
1273+
if ( is_int( $new_limit ) ) {
12711274
$this->max_seek_calls = $new_limit;
12721275
}
12731276
return $this->max_seek_calls;
@@ -1593,30 +1596,30 @@ public function get_updated_html() {
15931596
* @since 6.2.0
15941597
*/
15951598
private function apply_html_updates_and_stay_on_current_tag() {
1596-
// Short-circuit if there are no new updates to apply:
1599+
// Short-circuit if there are no new updates to apply.
15971600
if ( ! count( $this->classname_updates ) && ! count( $this->attribute_updates ) ) {
15981601
return;
15991602
}
16001603

1601-
// Otherwise: apply the updates, rewind before the current tag, and parse it again:
1604+
// Otherwise: apply the updates, rewind before the current tag, and parse it again.
16021605
$delta_between_updated_html_end_and_current_tag_end = substr(
16031606
$this->html,
16041607
$this->updated_bytes,
16051608
$this->tag_name_starts_at + $this->tag_name_length - $this->updated_bytes
16061609
);
1607-
$updated_html_up_to_current_tag_name_end = $this->updated_html . $delta_between_updated_html_end_and_current_tag_end;
1610+
$updated_html_up_to_current_tag_name_end = $this->updated_html . $delta_between_updated_html_end_and_current_tag_end;
16081611

16091612
// 1. Apply the attributes updates to the original HTML
16101613
$this->class_name_updates_to_attributes_updates();
16111614
$this->apply_attributes_updates();
16121615

16131616
// 2. Replace the original HTML with the updated HTML
1614-
$this->html = $this->updated_html . substr( $this->html, $this->updated_bytes );
1615-
$this->updated_html = $updated_html_up_to_current_tag_name_end;
1616-
$this->updated_bytes = strlen($this->updated_html);
1617+
$this->html = $this->updated_html . substr( $this->html, $this->updated_bytes );
1618+
$this->updated_html = $updated_html_up_to_current_tag_name_end;
1619+
$this->updated_bytes = strlen( $this->updated_html );
16171620

16181621
// 3. Point this tag processor at the original tag opener and consume it
1619-
$this->parsed_bytes = strlen($updated_html_up_to_current_tag_name_end) - $this->tag_name_length - 2;
1622+
$this->parsed_bytes = strlen( $updated_html_up_to_current_tag_name_end ) - $this->tag_name_length - 2;
16201623
$this->next_tag();
16211624
}
16221625

phpunit/html/wp-html-tag-processor-bookmark-test.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class WP_HTML_Tag_Processor_Bookmark_Test extends WP_UnitTestCase {
2323
public function test_set_bookmark() {
2424
$p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
2525
$p->next_tag( 'li' );
26-
$this->assertTrue($p->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark.');
26+
$this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark.' );
2727
$p->next_tag( 'li' );
28-
$this->assertTrue($p->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark.');
29-
$this->assertTrue($p->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark.');
28+
$this->assertTrue( $p->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark.' );
29+
$this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark.' );
3030
}
3131

3232
/**
@@ -37,9 +37,9 @@ public function test_set_bookmark() {
3737
public function test_release_bookmark() {
3838
$p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
3939
$p->next_tag( 'li' );
40-
$this->assertFalse($p->release_bookmark( 'first li' ), 'Released a non-existing bookmark.');
40+
$this->assertFalse( $p->release_bookmark( 'first li' ), 'Released a non-existing bookmark.' );
4141
$p->set_bookmark( 'first li' );
42-
$this->assertTrue($p->release_bookmark( 'first li' ), 'Could not release a bookmark.');
42+
$this->assertTrue( $p->release_bookmark( 'first li' ), 'Could not release a bookmark.' );
4343
}
4444

4545
/**
@@ -104,11 +104,11 @@ public function test_seek() {
104104
* @covers set_bookmark
105105
* @covers apply_attributes_updates
106106
*/
107-
public function test_removing_long_attributes_doesnt_break_seek( ) {
107+
public function test_removing_long_attributes_doesnt_break_seek() {
108108
$input = <<<HTML
109109
<button twenty_one_characters 7_chars></button><button></button>
110110
HTML;
111-
$p = new WP_HTML_Tag_Processor( $input );
111+
$p = new WP_HTML_Tag_Processor( $input );
112112
$p->next_tag( 'button' );
113113
$p->set_bookmark( 'first' );
114114
$p->next_tag( 'button' );
@@ -118,8 +118,8 @@ public function test_removing_long_attributes_doesnt_break_seek( ) {
118118
$p->seek( 'first' ),
119119
'Seek() to the first button has failed'
120120
);
121-
$p->remove_attribute('twenty_one_characters');
122-
$p->remove_attribute('7_chars');
121+
$p->remove_attribute( 'twenty_one_characters' );
122+
$p->remove_attribute( '7_chars' );
123123

124124
$this->assertTrue(
125125
$p->seek( 'second' ),
@@ -133,8 +133,8 @@ public function test_removing_long_attributes_doesnt_break_seek( ) {
133133
* @covers seek
134134
* @covers set_bookmark
135135
*/
136-
public function test_bookmarks_complex_use_case( ) {
137-
$input = <<<HTML
136+
public function test_bookmarks_complex_use_case() {
137+
$input = <<<HTML
138138
<div selected class="merge-message" checked>
139139
<div class="select-menu d-inline-block">
140140
<div checked class="BtnGroup MixedCaseHTML position-relative" />
@@ -178,7 +178,7 @@ public function test_bookmarks_complex_use_case( ) {
178178
</div>
179179
</div>
180180
HTML;
181-
$p = new WP_HTML_Tag_Processor( $input );
181+
$p = new WP_HTML_Tag_Processor( $input );
182182
$p->next_tag( 'div' );
183183
$p->next_tag( 'div' );
184184
$p->next_tag( 'div' );
@@ -193,35 +193,35 @@ public function test_bookmarks_complex_use_case( ) {
193193
$p->set_bookmark( 'fourth button' );
194194

195195
$p->seek( 'first button' );
196-
$p->set_attribute('type', 'submit');
196+
$p->set_attribute( 'type', 'submit' );
197197

198198
$this->assertTrue(
199199
$p->seek( 'third button' ),
200200
'Seek() to the third button failed'
201201
);
202-
$p->remove_attribute('class');
203-
$p->remove_attribute('type');
204-
$p->remove_attribute('aria-expanded');
205-
$p->set_attribute('id', 'rebase-and-merge');
206-
$p->remove_attribute('data-details-container');
202+
$p->remove_attribute( 'class' );
203+
$p->remove_attribute( 'type' );
204+
$p->remove_attribute( 'aria-expanded' );
205+
$p->set_attribute( 'id', 'rebase-and-merge' );
206+
$p->remove_attribute( 'data-details-container' );
207207

208208
$this->assertTrue(
209209
$p->seek( 'first div' ),
210210
'Seek() to the first div failed'
211211
);
212-
$p->set_attribute('checked', false);
212+
$p->set_attribute( 'checked', false );
213213

214214
$this->assertTrue(
215215
$p->seek( 'fourth button' ),
216216
'Seek() to the fourth button failed'
217217
);
218-
$p->set_attribute('id', 'last-button');
219-
$p->remove_attribute('class');
220-
$p->remove_attribute('type');
221-
$p->remove_attribute('checked');
222-
$p->remove_attribute('aria-label');
223-
$p->remove_attribute('disabled');
224-
$p->remove_attribute('data-view-component');
218+
$p->set_attribute( 'id', 'last-button' );
219+
$p->remove_attribute( 'class' );
220+
$p->remove_attribute( 'type' );
221+
$p->remove_attribute( 'checked' );
222+
$p->remove_attribute( 'aria-label' );
223+
$p->remove_attribute( 'disabled' );
224+
$p->remove_attribute( 'data-view-component' );
225225

226226
$this->assertTrue(
227227
$p->seek( 'second button' ),
@@ -340,10 +340,10 @@ public function test_updates_bookmark_for_deletions_before_both_sides() {
340340
public function test_limits_the_number_of_bookmarks() {
341341
$p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
342342
$p->next_tag( 'li' );
343-
for($i=0;$i<WP_HTML_Tag_Processor::MAX_BOOKMARKS;$i++) {
343+
for ( $i = 0;$i < WP_HTML_Tag_Processor::MAX_BOOKMARKS;$i++ ) {
344344
$this->assertTrue( $p->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" );
345345
}
346-
$this->assertFalse( $p->set_bookmark( "final bookmark" ), "Allocated $i bookmarks, which is one above the limit." );
346+
$this->assertFalse( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit." );
347347
}
348348

349349
/**
@@ -354,12 +354,12 @@ public function test_limits_the_number_of_bookmarks() {
354354
public function test_limits_the_number_of_seek_calls() {
355355
$p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
356356
$p->next_tag( 'li' );
357-
$p->set_bookmark('bookmark');
357+
$p->set_bookmark( 'bookmark' );
358358

359-
for($i=0;$i<$p->seek_limit();$i++) {
359+
for ( $i = 0;$i < $p->seek_limit();$i++ ) {
360360
$this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
361361
}
362-
$this->assertFalse( $p->seek( "bookmark" ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit." );
362+
$this->assertFalse( $p->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit." );
363363
}
364364
/**
365365
* @ticket 56299
@@ -368,13 +368,13 @@ public function test_limits_the_number_of_seek_calls() {
368368
*/
369369
public function test_adjusing_the_number_of_seek_calls() {
370370
$p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
371-
$p->seek_limit(2);
371+
$p->seek_limit( 2 );
372372

373373
$p->next_tag( 'li' );
374-
$p->set_bookmark('bookmark');
374+
$p->set_bookmark( 'bookmark' );
375375
$this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
376376
$this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
377-
$this->assertFalse( $p->seek( "bookmark" ), "The third seek() to the bookmark succeeded, even though it should exceed the allowed limit." );
377+
$this->assertFalse( $p->seek( 'bookmark' ), 'The third seek() to the bookmark succeeded, even though it should exceed the allowed limit.' );
378378
}
379379

380380
}

0 commit comments

Comments
 (0)