Skip to content

Commit 09e513d

Browse files
authored
Fix phpcs formatting (#17)
1 parent 3319ae3 commit 09e513d

18 files changed

Lines changed: 229 additions & 77 deletions

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
build
44
vendor
55
package-lock.json
6+
composer.lock
67

78
# Pinned Gutenberg subtree — formatted by its own tooling at the pin.
89
gutenberg
@@ -14,5 +15,11 @@ src/engines/intent-log
1415
# Vendored third-party code from the Yjs ecosystem.
1516
src/engines/yjs/y-utilities
1617

18+
# Vendored y-php and automerge-php libraries (imported verbatim; they
19+
# carry their own style and configs, and must stay byte-identical to
20+
# their upstream pins).
21+
includes/lib/y-php
22+
includes/lib/automerge-php
23+
1724
# Playwright e2e output.
1825
artifacts

gutenberg-sync-engines.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939

4040
require_once GUTENBERG_SYNC_ENGINES_PATH . 'includes/class-gutenberg-sync-engines-plugin.php';
4141

42-
/**
43-
* Boots the plugin once all plugins are loaded, so the collaborative-editing
44-
* framework (shipped in Gutenberg / WordPress core) is already available to
45-
* feature-detect.
46-
*
47-
* @since 0.1.0
48-
*
49-
* @return void
50-
*/
5142
if ( ! function_exists( 'gutenberg_sync_engines_bootstrap' ) ) {
43+
/**
44+
* Boots the plugin once all plugins are loaded, so the collaborative-editing
45+
* framework (shipped in Gutenberg / WordPress core) is already available to
46+
* feature-detect.
47+
*
48+
* @since 0.1.0
49+
*
50+
* @return void
51+
*/
5252
function gutenberg_sync_engines_bootstrap() {
5353
Gutenberg_Sync_Engines_Plugin::instance()->boot();
5454
}

includes/engines/de-rtc/class-wp-de-rtc-engine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ private function resolve_base_content( array $state, string $base_version ) {
406406
: array();
407407
$snapshot = $snapshots[ $base_version ] ?? null;
408408
if ( is_array( $snapshot ) && is_string( $snapshot['content_base64'] ?? null ) ) {
409+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Decodes a stored version snapshot's content.
409410
$decoded = base64_decode( $snapshot['content_base64'], true );
410411
if ( false !== $decoded ) {
411412
return $decoded;

includes/engines/intent-log/class-wp-intent-log-document.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,17 @@ private static function canonical_block( array $block ): array {
326326
usort(
327327
$formats,
328328
static function ( $a, $b ) {
329-
return ( $a['start'] <=> $b['start'] )
330-
?: ( $a['end'] <=> $b['end'] )
331-
?: strcmp( $a['format'], $b['format'] );
329+
$order = $a['start'] <=> $b['start'];
330+
331+
if ( 0 === $order ) {
332+
$order = $a['end'] <=> $b['end'];
333+
}
334+
335+
if ( 0 === $order ) {
336+
$order = strcmp( $a['format'], $b['format'] );
337+
}
338+
339+
return $order;
332340
}
333341
);
334342
$fields[ $name ] = array(

includes/engines/intent-log/class-wp-intent-log-engine.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class WP_Intent_Log_Engine implements WP_Sync_Engine {
131131
* Storage backend.
132132
*
133133
* @since 7.2.0
134+
* @var WP_Sync_Storage
134135
*/
135136
private WP_Sync_Storage $storage;
136137

@@ -314,6 +315,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
314315
$lock = $this->acquire_room_lock( $room );
315316
$lock_wait_ms = round( ( microtime( true ) - $lock_started ) * 1000, 1 );
316317
if ( is_wp_error( $lock ) ) {
318+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
317319
do_action( 'qm/debug', "wp-sync: ingest lock timeout for {$room} after {$lock_wait_ms}ms" );
318320
return $lock;
319321
}
@@ -377,6 +379,7 @@ private function handle_updates_locked( string $room, int $client_id, array $upd
377379
$intent_id = is_array( $intent ) && is_string( $intent['intentId'] ?? null ) && '' !== $intent['intentId']
378380
? $intent['intentId']
379381
: null;
382+
380383
/*
381384
* Malformed rows settle PER-INTENT as `invalid-payload`
382385
* voids instead of failing the whole request: a request-
@@ -412,6 +415,7 @@ private function handle_updates_locked( string $room, int $client_id, array $upd
412415
$submitted_ids[] = $intent_id;
413416
}
414417
if ( count( $invalid ) > 0 ) {
418+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
415419
do_action( 'qm/debug', 'wp-sync: ' . count( $invalid ) . " invalid intent(s) voided in {$room}" );
416420
}
417421

@@ -622,12 +626,15 @@ function ( $intent ) use ( $state, $base_seq, &$seen_in_batch, &$stale ) {
622626
$plan_counts['stale'] = count( $stale );
623627
$plan_counts['approval'] = array_sum( array_map( 'count', $requires_approval ) );
624628
if ( $plan_counts['escalated'] > 0 ) {
629+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
625630
do_action( 'qm/debug', "wp-sync: {$plan_counts['escalated']} intent(s) escalated for review in {$room}" );
626631
}
627632
if ( $plan_counts['approval'] > 0 ) {
633+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
628634
do_action( 'qm/debug', "wp-sync: {$plan_counts['approval']} intent(s) parked for approval in {$room} (author lacks unfiltered_html)" );
629635
}
630636
if ( $plan_counts['stale'] > 0 ) {
637+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
631638
do_action( 'qm/debug', "wp-sync: {$plan_counts['stale']} stale-base intent(s) voided in {$room} (client below retention horizon)" );
632639
}
633640
if ( ! empty( $context['debug'] ) ) {
@@ -823,6 +830,19 @@ private static function attr_value_requires_unfiltered_html( $value ): bool {
823830
return false;
824831
}
825832

833+
/**
834+
* Whether a block spec carries markup its author may not publish
835+
* without `unfiltered_html`.
836+
*
837+
* Judges the `_wrapper` internal attr, every other attr's string
838+
* leaves, the block-level and per-field format spans, and recurses
839+
* into child block specs.
840+
*
841+
* @since 7.2.0
842+
*
843+
* @param array $block Block spec (make_block() shape).
844+
* @return bool True when the spec requires `unfiltered_html`.
845+
*/
826846
private static function block_spec_requires_unfiltered_html( array $block ): bool {
827847
/*
828848
* Attributes: the _wrapper internal attr re-emits as raw markup
@@ -1032,6 +1052,7 @@ private function maybe_checkpoint( string $room, int $client_id, int $window_int
10321052
if ( $cursor <= 0 ) {
10331053
return true;
10341054
}
1055+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
10351056
do_action( 'qm/debug', "wp-sync: checkpoint at seq {$head_seq} for {$room}" );
10361057
$this->storage->set_room_meta(
10371058
$room,
@@ -1048,6 +1069,7 @@ private function maybe_checkpoint( string $room, int $client_id, int $window_int
10481069
// record the floor for the read path.
10491070
$this->storage->remove_updates_before_cursor( $room, (int) $previous['cursor'] );
10501071
$this->storage->set_room_meta( $room, 'intent_log_floor', (int) $previous['cursor'] );
1072+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
10511073
do_action( 'qm/debug', "wp-sync: trimmed history below cursor {$previous['cursor']} for {$room}" );
10521074
}
10531075
return true;

includes/engines/intent-log/class-wp-intent-log-planner.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* `src/engines/intent-log/rebase.js` (and `sync-id.js` for genesis
1313
* identity).
1414
*
15-
* plan_batch() is THE shared deterministic core: a pure function of
15+
* The plan_batch() method is THE shared deterministic core: a pure function of
1616
* (units, log, doc-at) that decides, for one client's batch, which
1717
* intents apply (with transformed payloads), which escalate to the
1818
* proposal lane, and which void. The server commits a plan at ingest; a
@@ -64,6 +64,7 @@ public static function genesis_sync_id( int $post_id, int $revision_id, array $p
6464
$input = $post_id . ':' . $revision_id . ':' . implode( '.', $path );
6565
$digest = substr( hash( 'sha256', $input, true ), 0, 16 );
6666

67+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Derives the base64url syncId from a binary digest.
6768
return rtrim( strtr( base64_encode( $digest ), '+/', '-_' ), '=' );
6869
}
6970

@@ -240,6 +241,7 @@ public static function is_valid_payload( string $type, array $payload ): bool {
240241
$is_any = static function (): bool {
241242
return true;
242243
};
244+
243245
/*
244246
* Block names materialize into comment delimiters UNESCAPED
245247
* (serialize_block escapes attrs, not the name), so a name
@@ -923,9 +925,10 @@ private static function rebase_intent( array $intent, array $priors, array $doc_
923925
*
924926
* @since 7.2.0
925927
*
926-
* @param array $units Batch grouped into units (group_units).
927-
* @param array $log Accepted log (batch's intents NOT included).
928-
* @param callable $doc_at fn( int $seq ): array document at that log position.
928+
* @param array $units Batch grouped into units (group_units).
929+
* @param array $log Accepted log (batch's intents NOT included).
930+
* @param callable $doc_at fn( int $seq ): array document at that log position.
931+
* @param int $first_seq Sequence number of the first entry in $log (0 for a full log).
929932
* @return array array( 'rows' => row[], 'headDoc' => array ). Each row:
930933
* array( 'intent', 'disposition', 'accepted' => ?array, 'proposal' => ?array ).
931934
*/

includes/engines/intent-log/class-wp-intent-log-rich-text.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ private static function json( array $value ): string {
145145
private static function decode_entities( string $raw ): string {
146146
return preg_replace_callback(
147147
'/&([a-zA-Z]+|#x?[0-9a-fA-F]+);?/',
148-
static function ( $match ) {
149-
if ( ';' !== substr( $match[0], -1 ) ) {
150-
return $match[0];
148+
static function ( $matches ) {
149+
if ( ';' !== substr( $matches[0], -1 ) ) {
150+
return $matches[0];
151151
}
152-
$body = $match[1];
152+
$body = $matches[1];
153153
if ( '#' === $body[0] ) {
154154
$code = ( 'x' === $body[1] || 'X' === $body[1] )
155155
? intval( substr( $body, 2 ), 16 )
@@ -373,9 +373,17 @@ private static function parse_strict( string $html ): array {
373373
usort(
374374
$formats,
375375
static function ( $a, $b ) {
376-
return ( $a['start'] <=> $b['start'] )
377-
?: ( $a['end'] <=> $b['end'] )
378-
?: strcmp( $a['format'], $b['format'] );
376+
$order = $a['start'] <=> $b['start'];
377+
378+
if ( 0 === $order ) {
379+
$order = $a['end'] <=> $b['end'];
380+
}
381+
382+
if ( 0 === $order ) {
383+
$order = strcmp( $a['format'], $b['format'] );
384+
}
385+
386+
return $order;
379387
}
380388
);
381389

@@ -409,9 +417,17 @@ public static function field_to_html( array $field ): string {
409417
usort(
410418
$format_spans,
411419
static function ( $a, $b ) {
412-
return ( $a['start'] <=> $b['start'] )
413-
?: ( $b['end'] <=> $a['end'] )
414-
?: strcmp( $a['format'], $b['format'] );
420+
$order = $a['start'] <=> $b['start'];
421+
422+
if ( 0 === $order ) {
423+
$order = $b['end'] <=> $a['end'];
424+
}
425+
426+
if ( 0 === $order ) {
427+
$order = strcmp( $a['format'], $b['format'] );
428+
}
429+
430+
return $order;
415431
}
416432
);
417433

@@ -457,7 +473,7 @@ static function ( $a, $b ) {
457473
while ( true ) {
458474
// Close spans ending here (with close/reopen stack repair).
459475
$reopen = array();
460-
while ( count( $stack ) > 0 ) {
476+
while ( array() !== $stack ) {
461477
$has_ender = false;
462478
foreach ( $stack as $span ) {
463479
if ( $span['end'] === $position ) {
@@ -508,5 +524,5 @@ static function ( $a, $b ) {
508524
* @since 7.2.0
509525
* @access private
510526
*/
511-
class WP_Intent_Log_Unsupported_Html extends Exception {}
527+
class WP_Intent_Log_Unsupported_Html extends Exception {} // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound -- Internal signal exception, colocated with its only thrower.
512528
}

includes/engines/yjs-server/class-wp-yjs-server-engine.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class WP_Yjs_Server_Engine implements WP_Sync_Engine {
156156
* Storage backend.
157157
*
158158
* @since 0.2.0
159+
* @var WP_Sync_Storage
159160
*/
160161
private WP_Sync_Storage $storage;
161162

@@ -289,6 +290,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
289290
);
290291
}
291292

293+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Decodes the client's binary CRDT update from the wire format.
292294
$binary = base64_decode( (string) $update['data'], true );
293295
if ( false === $binary || '' === $binary ) {
294296
$dispositions[] = array(
@@ -317,6 +319,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
317319
$this->room_docs[ $room ] = null;
318320

319321
if ( ! self::is_decodable( $buffer ) ) {
322+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
320323
do_action( 'qm/debug', "wp-sync: yjs-server rejected a malformed update in {$room}" );
321324
$dispositions[] = array(
322325
'status' => 'voided',
@@ -348,6 +351,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
348351

349352
$diff = self::apply_update_for_row( $doc, $buffer );
350353
if ( null !== $diff ) {
354+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
351355
do_action( 'qm/debug', "wp-sync: yjs-server repaired {$room} from the update log during ingest" );
352356
$diffs[ count( $dispositions ) ] = $diff;
353357
$dispositions[] = array( 'status' => 'applied' );
@@ -362,6 +366,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
362366
*/
363367
$doc = self::rebuild_doc( $before_bytes, $diffs );
364368
$this->room_docs[ $room ] = null;
369+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
365370
do_action( 'qm/debug', "wp-sync: yjs-server update depends on items missing from {$room}; client must resync" );
366371
$dispositions[] = array(
367372
'status' => 'voided',
@@ -375,6 +380,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
375380
// voids and leave the row log untouched. A replay-repaired
376381
// canonical is still worth persisting.
377382
if ( $replayed ) {
383+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Encodes the canonical document's binary bytes for storage.
378384
$this->save_canonical( $room, $doc, $load_cursor, base64_encode( $after_bytes ) );
379385
}
380386
foreach ( $dispositions as $i => $disposition ) {
@@ -411,6 +417,7 @@ public function handle_updates( string $room, int $client_id, int $cursor, array
411417

412418
// $after_bytes IS the canonical encoding at the new head; reuse
413419
// it rather than encoding the document a third time.
420+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Encodes the canonical document's binary bytes for storage.
414421
$this->save_canonical( $room, $doc, $load_cursor, base64_encode( $after_bytes ) );
415422
$this->maybe_checkpoint( $room, $client_id, $doc );
416423

@@ -550,6 +557,7 @@ private function load_room( string $room ) {
550557
// replay below.
551558
$doc = new \Yjs\Utils\Doc();
552559
$meta_cursor = 0;
560+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
553561
do_action( 'qm/debug', "wp-sync: yjs-server canonical snapshot corrupt for {$room}; replaying log" );
554562
}
555563
}
@@ -617,6 +625,7 @@ private static function apply_rows_to_doc( \Yjs\Utils\Doc $doc, array $rows, str
617625
}
618626
} catch ( \Throwable $e ) {
619627
$clean = false;
628+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
620629
do_action( 'qm/debug', "wp-sync: yjs-server skipped a stored row that did not apply in {$room}" );
621630
}
622631
}
@@ -848,12 +857,14 @@ private function maybe_checkpoint( string $room, int $client_id, \Yjs\Utils\Doc
848857
if ( $cursor <= 0 ) {
849858
return true;
850859
}
860+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
851861
do_action( 'qm/debug', "wp-sync: yjs-server checkpoint for {$room}" );
852862
$this->storage->set_room_meta( $room, self::META_CHECKPOINT, array( 'cursor' => $cursor ) );
853863

854864
if ( $prev_cursor > 0 ) {
855865
$this->storage->remove_updates_before_cursor( $room, $prev_cursor );
856866
$this->storage->set_room_meta( $room, self::META_FLOOR, $prev_cursor );
867+
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Query Monitor's debug hook.
857868
do_action( 'qm/debug', "wp-sync: yjs-server trimmed history below cursor {$prev_cursor} for {$room}" );
858869
}
859870

@@ -875,6 +886,7 @@ private function maybe_checkpoint( string $room, int $client_id, \Yjs\Utils\Doc
875886
* @return true|WP_Error True on success.
876887
*/
877888
private function initialize_room( string $room, \Yjs\Utils\Doc $doc ) {
889+
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- clientID is the y-php Doc property, mirroring JS Yjs naming.
878890
$doc->clientID = self::GENESIS_CLIENT_ID;
879891

880892
$post = null;

includes/lib/y-php-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Runtime loader for the vendored y-php library.
44
*
5-
* y-php ships Composer metadata, but the plugin cannot assume a Composer
5+
* The y-php library ships Composer metadata, but the plugin cannot assume a Composer
66
* autoloader at runtime, so this shim provides the equivalent wiring:
77
* a PSR-4 autoloader for the `Yjs\` namespace plus the two eager files
88
* Composer's `files` directive would load (namespace functions and

0 commit comments

Comments
 (0)