Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmjones authored Feb 2, 2024
2 parents 778d9a2 + e790043 commit ed79a85
Show file tree
Hide file tree
Showing 25 changed files with 159 additions and 114 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
tab_width = 4
indent_style = tab
insert_final_newline = false
trim_trailing_whitespace = true

[*.txt]
trim_trailing_whitespace = false

[*.{md,json,yml}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
6 changes: 0 additions & 6 deletions .scrutinizer.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

23 changes: 18 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "a5hleyrich/wp-queue",
"name": "deliciousbrains/wp-queue",
"description": "WordPress job queues",
"keywords": ["wordpress","queue","job"],
"license": "MIT",
"authors": [
{
"name": "Ashley Rich",
"email": "[email protected]"
},
{
"name": "Delicious Brains",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5.0",
"nesbot/carbon": "^1.22"
"php": ">=7.3.0",
"nesbot/carbon": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -22,7 +26,16 @@
]
},
"require-dev": {
"phpunit/phpunit": "~5.7.0",
"10up/wp_mock": "0.2.0"
"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"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
29 changes: 29 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<ruleset name="Delicious Brains">
<!-- Files or directories to check -->
<file>.</file>

<!-- Path to strip from the front of file paths inside reports (displays shorter paths) -->
<arg name="basepath" value="." />

<!-- Use HM Coding Standards -->
<rule ref="vendor/humanmade/coding-standards">
<!-- Namespace isn't required for all files. -->
<exclude name="HM.Functions.NamespacedFunctions.MissingNamespace" />
<!-- Ignore rule expecting Namespaced directory. -->
<exclude name="HM.Files.NamespaceDirectoryName.NoIncDirectory" />
<!-- File name and class name match is not necessary. -->
<exclude name="HM.Files.ClassFileName.MismatchedName" />
<!-- Ignore class file name rule -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<!-- Ignore rule expecting hyphens in file name. -->
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<!-- Don't require file comment header. -->
<exclude name="Squiz.Commenting.FileComment.Missing" />
</rule>

<!-- Ignore Snake case variables for tests -->
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
</ruleset>
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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
30 changes: 15 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<phpunit colors="true" backupGlobals="false" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="wp-queue">
<directory prefix="Test" suffix=".php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" backupGlobals="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="wp-queue">
<directory prefix="Test" suffix=".php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/WP_Queue/Connections/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ public function jobs();
*/
public function failed_jobs();

}
}
34 changes: 17 additions & 17 deletions src/WP_Queue/Connections/DatabaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function __construct( $wpdb ) {
* @return bool|int
*/
public function push( Job $job, $delay = 0 ) {
$result = $this->database->insert( $this->jobs_table, array(
$result = $this->database->insert( $this->jobs_table, [
'job' => serialize( $job ),
'available_at' => $this->datetime( $delay ),
'created_at' => $this->datetime(),
) );
] );

if ( ! $result ) {
return false;
Expand All @@ -68,7 +68,7 @@ public function pop() {
SELECT * FROM {$this->jobs_table}
WHERE reserved_at IS NULL
AND available_at <= %s
ORDER BY available_at
ORDER BY available_at, id
LIMIT 1
", $this->datetime() );

Expand All @@ -93,9 +93,9 @@ public function pop() {
* @return bool
*/
public function delete( $job ) {
$where = array(
$where = [
'id' => $job->id(),
);
];

if ( $this->database->delete( $this->jobs_table, $where ) ) {
return true;
Expand All @@ -112,14 +112,14 @@ public function delete( $job ) {
* @return bool
*/
public function release( $job ) {
$data = array(
$data = [
'job' => serialize( $job ),
'attempts' => $job->attempts(),
'reserved_at' => null,
);
$where = array(
];
$where = [
'id' => $job->id(),
);
];

if ( $this->database->update( $this->jobs_table, $data, $where ) ) {
return true;
Expand All @@ -137,11 +137,11 @@ public function release( $job ) {
* @return bool
*/
public function failure( $job, Exception $exception ) {
$insert = $this->database->insert( $this->failures_table, array(
$insert = $this->database->insert( $this->failures_table, [
'job' => serialize( $job ),
'error' => $this->format_exception( $exception ),
'failed_at' => $this->datetime(),
) );
] );

if ( $insert ) {
$this->delete( $job );
Expand All @@ -159,7 +159,7 @@ public function failure( $job, Exception $exception ) {
*/
public function jobs() {
$sql = "SELECT COUNT(*) FROM {$this->jobs_table}";

return (int) $this->database->get_var( $sql );
}

Expand All @@ -180,13 +180,13 @@ public function failed_jobs() {
* @param Job $job
*/
protected function reserve( $job ) {
$data = array(
$data = [
'reserved_at' => $this->datetime(),
);
];

$this->database->update( $this->jobs_table, $data, array(
$this->database->update( $this->jobs_table, $data, [
'id' => $job->id(),
) );
] );
}

/**
Expand Down Expand Up @@ -256,4 +256,4 @@ protected function format_exception( Exception $exception ) {
return $string;
}

}
}
9 changes: 1 addition & 8 deletions src/WP_Queue/Connections/RedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class RedisConnection implements ConnectionInterface {
* @return bool|int
*/
public function push( Job $job, $delay = 0 ) {
//
}

/**
Expand All @@ -25,7 +24,6 @@ public function push( Job $job, $delay = 0 ) {
* @return bool|Job
*/
public function pop() {
//
}

/**
Expand All @@ -34,7 +32,6 @@ public function pop() {
* @param Job $job
*/
public function delete( $job ) {
//
}

/**
Expand All @@ -43,7 +40,6 @@ public function delete( $job ) {
* @param Job $job
*/
public function release( $job ) {
//
}

/**
Expand All @@ -55,7 +51,6 @@ public function release( $job ) {
* @return bool
*/
public function failure( $job, Exception $exception ) {
//
}

/**
Expand All @@ -64,7 +59,6 @@ public function failure( $job, Exception $exception ) {
* @return int
*/
public function jobs() {
//
}

/**
Expand All @@ -73,7 +67,6 @@ public function jobs() {
* @return int
*/
public function failed_jobs() {
//
}

}
}
8 changes: 4 additions & 4 deletions src/WP_Queue/Connections/SyncConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SyncConnection implements ConnectionInterface {
*
* @return bool|int
*/
public function push(Job $job, $delay = 0) {
public function push( Job $job, $delay = 0 ) {
$job->handle();

return true;
Expand All @@ -36,7 +36,7 @@ public function pop() {
*
* @return bool
*/
public function delete($job) {
public function delete( $job ) {
return false;
}

Expand All @@ -47,7 +47,7 @@ public function delete($job) {
*
* @return bool
*/
public function release($job) {
public function release( $job ) {
return false;
}

Expand All @@ -59,7 +59,7 @@ public function release($job) {
*
* @return bool
*/
public function failure($job, Exception $exception) {
public function failure( $job, Exception $exception ) {
return false;
}

Expand Down
Loading

0 comments on commit ed79a85

Please sign in to comment.