From b7b4bb7b7171879f6b6917a831605ffef494d907 Mon Sep 17 00:00:00 2001 From: "Ian M. Jones" Date: Wed, 17 Jan 2024 14:40:49 +0000 Subject: [PATCH 1/2] Add WP_Background_Processing namespace to classes --- .phpcs.xml | 1 + README.md | 6 +++++- classes/wp-async-request.php | 4 ++++ classes/wp-background-process.php | 5 +++++ tests/Test_WP_Background_Process.php | 9 +++++---- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index 9032383..737399a 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -30,6 +30,7 @@ + diff --git a/README.md b/README.md index df27f02..49d355a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The recommended way to install this library in your project is by loading it thr composer require deliciousbrains/wp-background-processing ``` -It is highly recommended to prefix wrap the library class files using [the Mozart package](https://packagist.org/packages/coenjacobs/mozart), to prevent collisions with other projects using this same library. +It is highly recommended to prefix wrap the library class files using [PHP-Scoper](https://packagist.org/packages/humbug/php-scoper), to prevent collisions with other projects using this same library. ## Usage @@ -25,6 +25,8 @@ Async requests are useful for pushing slow one-off tasks such as sending emails Extend the `WP_Async_Request` class: ```php +use My_Plugin\PHP_Scoped\Namespace\WP_Background_Processing; + class WP_Example_Request extends WP_Async_Request { /** @@ -99,6 +101,8 @@ Queues work on a first in first out basis, which allows additional items to be p Extend the `WP_Background_Process` class: ```php +use My_Plugin\PHP_Scoped\Namespace\WP_Background_Processing; + class WP_Example_Process extends WP_Background_Process { /** diff --git a/classes/wp-async-request.php b/classes/wp-async-request.php index 0503a60..3a6bd39 100644 --- a/classes/wp-async-request.php +++ b/classes/wp-async-request.php @@ -5,6 +5,10 @@ * @package WP-Background-Processing */ +namespace WP_Background_Processing; + +use WP_Error; + /** * Abstract WP_Async_Request class. * diff --git a/classes/wp-background-process.php b/classes/wp-background-process.php index 8a053d8..baa45ce 100644 --- a/classes/wp-background-process.php +++ b/classes/wp-background-process.php @@ -5,6 +5,11 @@ * @package WP-Background-Processing */ +namespace WP_Background_Processing; + +use stdClass; +use WP_Error; + /** * Abstract WP_Background_Process class. * diff --git a/tests/Test_WP_Background_Process.php b/tests/Test_WP_Background_Process.php index 19926e9..c7509b0 100644 --- a/tests/Test_WP_Background_Process.php +++ b/tests/Test_WP_Background_Process.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WP_Background_Processing\WP_Background_Process; /** * Class Test_WP_Background_Process @@ -42,7 +43,7 @@ public function setUp(): void { */ private function getWPBPProperty( string $name ) { try { - $property = new ReflectionProperty( 'WP_Background_Process', $name ); + $property = new ReflectionProperty( 'WP_Background_Processing\WP_Background_Process', $name ); } catch ( Exception $e ) { return new WP_Error( $e->getCode(), $e->getMessage() ); } @@ -61,7 +62,7 @@ private function getWPBPProperty( string $name ) { */ private function executeWPBPMethod( string $name, ...$args ) { try { - $method = new ReflectionMethod( 'WP_Background_Process', $name ); + $method = new ReflectionMethod( 'WP_Background_Processing\WP_Background_Process', $name ); $method->setAccessible( true ); return $method->invoke( $this->wpbp, ...$args ); @@ -76,7 +77,7 @@ private function executeWPBPMethod( string $name, ...$args ) { * @return void */ public function test_push_to_queue() { - $this->assertClassHasAttribute( 'data', 'WP_Background_Process', 'class has data property' ); + $this->assertClassHasAttribute( 'data', 'WP_Background_Processing\WP_Background_Process', 'class has data property' ); $this->assertEmpty( $this->getWPBPProperty( 'data' ) ); $this->wpbp->push_to_queue( 'wibble' ); @@ -93,7 +94,7 @@ public function test_push_to_queue() { * @return void */ public function test_save() { - $this->assertClassHasAttribute( 'data', 'WP_Background_Process', 'class has data property' ); + $this->assertClassHasAttribute( 'data', 'WP_Background_Processing\WP_Background_Process', 'class has data property' ); $this->assertEmpty( $this->getWPBPProperty( 'data' ) ); $this->assertEmpty( $this->wpbp->get_batches(), 'no batches until save' ); From a80b4165127d2b4c42a8c66ae7c1fcd77fa56c50 Mon Sep 17 00:00:00 2001 From: "Ian M. Jones" Date: Wed, 17 Jan 2024 15:13:49 +0000 Subject: [PATCH 2/2] Remove unneeded use statements --- classes/wp-async-request.php | 2 -- classes/wp-background-process.php | 1 - 2 files changed, 3 deletions(-) diff --git a/classes/wp-async-request.php b/classes/wp-async-request.php index 3a6bd39..6e3a24c 100644 --- a/classes/wp-async-request.php +++ b/classes/wp-async-request.php @@ -7,8 +7,6 @@ namespace WP_Background_Processing; -use WP_Error; - /** * Abstract WP_Async_Request class. * diff --git a/classes/wp-background-process.php b/classes/wp-background-process.php index baa45ce..9c000a7 100644 --- a/classes/wp-background-process.php +++ b/classes/wp-background-process.php @@ -8,7 +8,6 @@ namespace WP_Background_Processing; use stdClass; -use WP_Error; /** * Abstract WP_Background_Process class.