Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ deliberately does not change is the hook boundary — WordPress's own files are
calling our typed methods still coerces weakly, and a callback that receives a loose type from a
filter behaves exactly as it did.

**Every `_doing_it_wrong()` names `Class::method`, never a bare class name.** WordPress prints it as
"Function %s was called incorrectly", so it is the only part of a report that says where in this
library the sentence came from, and a class alone cannot separate two reports made by the same one.
Written `self::class . '::method'` rather than `__METHOD__`, because `__METHOD__` inside a trait
names the trait rather than the class that actually stood down.

**Comments describe behaviour, not the plan.** Never reference a task or plan-step number in a code
comment; the code outlives the plan. Comments earn their place by explaining *why*, especially where
a plausible alternative is wrong.
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static function load( ContainerInterface $container ): void {
*/
private static function report_a_step_that_threw( string $step, string $consequence, Throwable $thrown ): void {
_doing_it_wrong(
self::class,
self::class . '::report_a_step_that_threw',
sprintf( 'The %s threw, so %s: %s', $step, $consequence, $thrown->getMessage() ),
'1.0.0'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Conflict/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function resolve_all(): void {
}
} catch ( Throwable $thrown ) {
_doing_it_wrong(
self::class,
self::class . '::resolve_all',
sprintf(
'The conflict for "%s" threw while being resolved, so it was abandoned: %s',
$sub_plugin->get_slug(),
Expand Down
4 changes: 2 additions & 2 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function load_all(): void {
$this->load( $sub_plugin );
} catch ( Throwable $thrown ) {
_doing_it_wrong(
self::class,
self::class . '::load_all',
sprintf(
'The sub-plugin "%s" threw while loading, so it was abandoned: %s',
$sub_plugin->get_slug(),
Expand Down Expand Up @@ -149,7 +149,7 @@ private function load( Sub_Plugin $sub_plugin ): void {

if ( ! is_file( $file ) || ! is_readable( $file ) ) {
_doing_it_wrong(
self::class,
self::class . '::load',
sprintf(
'The bundled plugin file for "%s" is missing or unreadable: %s',
$sub_plugin->get_slug(),
Expand Down
2 changes: 1 addition & 1 deletion src/Registry/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function flush(): void {
// duplicate" rather than by path alone, because the two registrations may well name
// the same file, and a bare path then reads as if the surviving one went too.
_doing_it_wrong(
self::class,
self::class . '::flush',
sprintf(
'%1$s The original registration was kept; the duplicate %2$s was discarded.',
$exception->getMessage(),
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Guards_Hook_Prefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static function has_hook_prefix(): bool {
try {
Config::get_hook_prefix();
} catch ( Config_Exception $exception ) {
_doing_it_wrong( self::class, $exception->getMessage(), '1.0.0' );
_doing_it_wrong( self::class . '::has_hook_prefix', $exception->getMessage(), '1.0.0' );

return false;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/_support/Traits/WithIncorrectUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ protected function assert_the_library_reported_incorrect_usage(): void {
$report,
'The report has to name this library, or the host goes looking in WordPress.'
);

// The member, not just the class. Which method reported is the only thing separating two
// reports from the same class -- the facade makes two, from separate trampolines -- and
// pinning the shape rather than the name is what keeps this assertion loose enough to
// survive a rename while still refusing a bare class name.
$this->assertStringContainsString(
'::',
$report,
'The report has to name the member it was made from, not just the class.'
);
}
}

Expand Down
Loading