diff --git a/.circleci/config.yml b/.circleci/config.yml
index 94554c3..5f0e42a 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -5,6 +5,11 @@ workflows:
- php73-build
- php74-build
- php80-build
+ - php81-build
+ - php82-build
+ - php83-build
+ - php84-build
+ - php85-build
version: 2
@@ -66,9 +71,27 @@ jobs:
docker:
- image: cimg/php:8.1
- image: *mysql_image
-
+
php82-build:
<<: *php_job
docker:
- image: cimg/php:8.2
- - image: *mysql_image
\ No newline at end of file
+ - image: *mysql_image
+
+ php83-build:
+ <<: *php_job
+ docker:
+ - image: cimg/php:8.3
+ - image: *mysql_image
+
+ php84-build:
+ <<: *php_job
+ docker:
+ - image: cimg/php:8.4
+ - image: *mysql_image
+
+ php85-build:
+ <<: *php_job
+ docker:
+ - image: cimg/php:8.5
+ - image: *mysql_image
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..164cbb7
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,84 @@
+
+
+ Generally-applicable sniffs for WordPress plugins.
+
+
+ src/
+ /vendor/
+ /node_modules/
+ /tests/*
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Makefile b/Makefile
index 0ef483b..00da6c8 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ test-style: vendor
vendor/bin/phpcs
vendor: composer.json
- composer install --ignore-platform-reqs
+ composer install
.PHONY: update-deps
update-deps:
@@ -18,5 +18,9 @@ update-deps:
.PHONY: clean
clean:
+ rm -f tests/.phpunit.result.cache .phpunit.result.cache
+
+.PHONY: clean-all
+clean-all: clean
rm -rf vendor
- rm -f tests/.phpunit.result.cache
\ No newline at end of file
+ rm -f composer.lock coverage.clover
diff --git a/composer.json b/composer.json
index 5d6f066..0a2d79d 100644
--- a/composer.json
+++ b/composer.json
@@ -14,8 +14,8 @@
}
],
"require": {
- "php": ">=7.3.0",
- "nesbot/carbon": "^2.0"
+ "php": "^7.3|^8.0",
+ "nesbot/carbon": "^2|^3"
},
"autoload": {
"psr-4": {
@@ -27,11 +27,9 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0.0",
- "10up/wp_mock": "^0.4.2",
- "humanmade/coding-standards": "^1.1",
- "php-stubs/wp-cli-stubs": "^2.6",
- "phpstan/phpstan": "^1.4",
- "szepeviktor/phpstan-wordpress": "^1.0"
+ "10up/wp_mock": "^0.5|^1",
+ "wp-coding-standards/wpcs": "^3",
+ "phpcompatibility/phpcompatibility-wp": "*"
},
"config": {
"allow-plugins": {
diff --git a/phpcs.xml b/phpcs.xml
deleted file mode 100644
index eb38ddb..0000000
--- a/phpcs.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
- .
- /vendor/
- /node_modules/
- /tests/*
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /tests/*
-
-
\ No newline at end of file
diff --git a/phpstan.neon b/phpstan.neon
deleted file mode 100644
index a09044d..0000000
--- a/phpstan.neon
+++ /dev/null
@@ -1,10 +0,0 @@
-includes:
- - vendor/szepeviktor/phpstan-wordpress/extension.neon
-parameters:
- level: 5
- paths:
- - src
- scanFiles:
- - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
- - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
- - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
diff --git a/src/WP_Queue/Connections/ConnectionInterface.php b/src/WP_Queue/Connections/ConnectionInterface.php
index 75a46d6..6d20d75 100644
--- a/src/WP_Queue/Connections/ConnectionInterface.php
+++ b/src/WP_Queue/Connections/ConnectionInterface.php
@@ -61,5 +61,4 @@ public function jobs();
* @return int
*/
public function failed_jobs();
-
}
diff --git a/src/WP_Queue/Connections/DatabaseConnection.php b/src/WP_Queue/Connections/DatabaseConnection.php
index e671700..d819c2e 100644
--- a/src/WP_Queue/Connections/DatabaseConnection.php
+++ b/src/WP_Queue/Connections/DatabaseConnection.php
@@ -55,11 +55,14 @@ public function __construct( $wpdb, array $allowed_job_classes = [] ) {
* @return bool|int
*/
public function push( Job $job, $delay = 0 ) {
- $result = $this->database->insert( $this->jobs_table, [
- 'job' => serialize( $job ),
- 'available_at' => $this->datetime( $delay ),
- 'created_at' => $this->datetime(),
- ] );
+ $result = $this->database->insert(
+ $this->jobs_table,
+ [
+ 'job' => serialize( $job ),
+ 'available_at' => $this->datetime( $delay ),
+ 'created_at' => $this->datetime(),
+ ]
+ );
if ( ! $result ) {
return false;
@@ -76,13 +79,16 @@ public function push( Job $job, $delay = 0 ) {
public function pop() {
$this->release_reserved();
- $sql = $this->database->prepare( "
+ $sql = $this->database->prepare(
+ "
SELECT * FROM {$this->jobs_table}
WHERE reserved_at IS NULL
AND available_at <= %s
ORDER BY available_at, id
LIMIT 1
- ", $this->datetime() );
+ ",
+ $this->datetime()
+ );
$raw_job = $this->database->get_row( $sql );
@@ -160,11 +166,14 @@ public function release( Job $job ) {
* @return bool
*/
public function failure( $job, Exception $exception ) {
- $insert = $this->database->insert( $this->failures_table, [
- 'job' => serialize( $job ),
- 'error' => $this->format_exception( $exception ),
- 'failed_at' => $this->datetime(),
- ] );
+ $insert = $this->database->insert(
+ $this->failures_table,
+ [
+ 'job' => serialize( $job ),
+ 'error' => $this->format_exception( $exception ),
+ 'failed_at' => $this->datetime(),
+ ]
+ );
if ( $insert ) {
$this->delete( $job );
@@ -207,9 +216,13 @@ protected function reserve( Job $job ) {
'reserved_at' => $this->datetime(),
];
- $this->database->update( $this->jobs_table, $data, [
- 'id' => $job->id(),
- ] );
+ $this->database->update(
+ $this->jobs_table,
+ $data,
+ [
+ 'id' => $job->id(),
+ ]
+ );
}
/**
@@ -218,10 +231,14 @@ protected function reserve( Job $job ) {
protected function release_reserved() {
$expired = $this->datetime( -300 );
- $sql = $this->database->prepare( "
- UPDATE {$this->jobs_table}
- SET attempts = attempts + 1, reserved_at = NULL
- WHERE reserved_at <= %s", $expired );
+ $sql = $this->database->prepare(
+ "
+ UPDATE {$this->jobs_table}
+ SET attempts = attempts + 1, reserved_at = NULL
+ WHERE reserved_at <= %s
+ ",
+ $expired
+ );
$this->database->query( $sql );
}
diff --git a/src/WP_Queue/Cron.php b/src/WP_Queue/Cron.php
index 2d31852..d48bf69 100644
--- a/src/WP_Queue/Cron.php
+++ b/src/WP_Queue/Cron.php
@@ -66,7 +66,7 @@ public function init() {
add_action( $this->id, [ $this, 'cron_worker' ] );
if ( ! wp_next_scheduled( $this->id ) ) {
- // Schedule health check
+ // Schedule health check.
wp_schedule_event( time(), $this->id, $this->id );
}
@@ -142,7 +142,8 @@ protected function unlock_worker() {
* @return bool
*/
protected function memory_exceeded() {
- $memory_limit = $this->get_memory_limit() * 0.8; // 80% of max memory
+ // 80% of max memory.
+ $memory_limit = $this->get_memory_limit() * 0.8;
$current_memory = memory_get_usage( true );
$return = false;
@@ -165,8 +166,9 @@ protected function get_memory_limit() {
$memory_limit = '256M';
}
+ // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
if ( ! $memory_limit || -1 == $memory_limit ) {
- // Unlimited, set to 1GB
+ // Unlimited, set to 1GB.
$memory_limit = '1000M';
}
@@ -182,7 +184,8 @@ protected function get_memory_limit() {
* @return bool
*/
protected function time_exceeded() {
- $finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 ); // 20 seconds
+ // Default to 20 seconds.
+ $finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 );
$return = false;
if ( time() >= $finish ) {
diff --git a/src/WP_Queue/Job.php b/src/WP_Queue/Job.php
index b4522f4..8fbc22c 100644
--- a/src/WP_Queue/Job.php
+++ b/src/WP_Queue/Job.php
@@ -140,6 +140,7 @@ public function set_created_at( Carbon $created_at ) {
* Flag job as released.
*/
public function release() {
+ // phpcs:ignore Generic.Formatting.MultipleStatementAlignment.NotSameWarning
$this->released = true;
$this->attempts += 1;
}
@@ -192,5 +193,4 @@ public function __sleep() {
return array_keys( $object_props );
}
-
}
diff --git a/src/WP_Queue/QueueManager.php b/src/WP_Queue/QueueManager.php
index 9a08028..75cba14 100644
--- a/src/WP_Queue/QueueManager.php
+++ b/src/WP_Queue/QueueManager.php
@@ -23,7 +23,7 @@ class QueueManager {
* @param array $allowed_job_classes Job classes that may be handled, default any Job subclass.
*
* @return Queue
- * @throws Exception
+ * @throws ConnectionNotFoundException
*/
public static function resolve( $connection, array $allowed_job_classes = [] ) {
if ( isset( static::$instances[ $connection ] ) ) {
@@ -40,7 +40,7 @@ public static function resolve( $connection, array $allowed_job_classes = [] ) {
* @param array $allowed_job_classes Job classes that may be handled, default any Job subclass.
*
* @return Queue
- * @throws Exception
+ * @throws ConnectionNotFoundException
*/
protected static function build( $connection, array $allowed_job_classes = [] ) {
$connections = static::connections( $allowed_job_classes );
diff --git a/src/WP_Queue/Worker.php b/src/WP_Queue/Worker.php
index cafa0af..05800ee 100644
--- a/src/WP_Queue/Worker.php
+++ b/src/WP_Queue/Worker.php
@@ -67,5 +67,4 @@ public function process() {
return true;
}
-
}
diff --git a/src/functions.php b/src/functions.php
index c1ed2b9..6cd326e 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -29,7 +29,7 @@ function wp_queue( $connection = '', array $allowed_job_classes = [] ) {
function wp_queue_install_tables() {
global $wpdb;
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$wpdb->hide_errors();
$charset_collate = $wpdb->get_charset_collate();
@@ -56,4 +56,4 @@ function wp_queue_install_tables() {
dbDelta( $sql );
}
-}
+}//end if