Skip to content

Commit

Permalink
Merge 244ff7e into b447f71
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Dec 6, 2019
2 parents b447f71 + 244ff7e commit e062a62
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 94 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

services:
- mysql
Expand All @@ -25,10 +23,10 @@ matrix:
fast_finish: true

include:
- php: 7.1
- php: 7.2
env: PHPCS=1 DEFAULT=0

- php: 7.1
- php: 7.2
env: COVERALLS=1 DEFAULT=0

before_script:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
[![Documentation Status](https://readthedocs.org/projects/cakephp-queuesadilla/badge/?version=latest&style=flat-square)](https://readthedocs.org/projects/cakephp-queuesadilla/?badge=latest)
[![Gratipay](https://img.shields.io/gratipay/josegonzalez.svg?style=flat-square)](https://gratipay.com/~josegonzalez/)

# CakePHP Queuesadilla Plugin 3.0
# CakePHP Queuesadilla Plugin 4.0

This plugin is a simple wrapper around the Queuesadilla queuing library, providing tighter integration with the CakePHP framework.

## Requirements

* CakePHP 3.x
* PHP 5.6+
* CakePHP 4.x
* PHP 7.2+
* Patience

## Documentation
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}
],
"require": {
"cakephp/cakephp": "^3.6",
"php": ">=5.4",
"cakephp/cakephp": "^4.0",
"php": ">=7.2",
"josegonzalez/queuesadilla": "0.0.*",
"ext-pcntl": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.0",
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "~8.4.0",
"cakephp/cakephp-codesniffer": "dev-next",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
Expand All @@ -34,5 +34,7 @@
"psr-4": {
"Josegonzalez\\CakeQueuesadilla\\Test\\": "tests"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
6 changes: 0 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
Expand All @@ -18,11 +17,6 @@
</testsuites>

<filter>
<blacklist>
<directory suffix=".php">./docs</directory>
<directory suffix=".php">./vendor</directory>
<file>./tests/bootstrap.php</file>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
Expand Down
7 changes: 4 additions & 3 deletions src/Engine/CakeEngine.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla\Engine;

use Cake\Core\Exception\Exception;
use Cake\Database\Connection;
use Cake\Datasource\ConnectionManager;
use Cake\Utility\Hash;
use josegonzalez\Queuesadilla\Engine\PdoEngine;
Expand All @@ -21,7 +22,7 @@ class CakeEngine extends PdoEngine
'attempts' => 0,
'attempts_delay' => 600,
'table' => 'jobs',
'datasource' => 'default'
'datasource' => 'default',
];

/**
Expand All @@ -31,7 +32,7 @@ public function connect()
{
$config = $this->settings;
try {
/** @var Connection $connection */
/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get(Hash::get($config, 'datasource'));
$connection->connect();
$this->connection = $connection->getDriver()->getConnection();
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla;

use Cake\Core\BasePlugin;
Expand Down
25 changes: 13 additions & 12 deletions src/Queue/Queue.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla\Queue;

use Cake\Core\ObjectRegistry;
use Cake\Core\StaticConfigTrait;
use Cake\Utility\Hash;
use InvalidArgumentException;
use Josegonzalez\CakeQueuesadilla\Queue\QueueEngineRegistry;
use josegonzalez\Queuesadilla\Engine\EngineInterface;
use josegonzalez\Queuesadilla\Engine\NullEngine;
use josegonzalez\Queuesadilla\Queue as Queuer;
use RuntimeException;

/**
* Queue provides a consistent interface to Queuing in your application. It allows you
Expand Down Expand Up @@ -55,7 +56,6 @@
*/
class Queue
{

use StaticConfigTrait {
parseDsn as protected _parseDsn;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class Queue
*
* @return void
*/
protected static function _init()
protected static function _init(): void
{
if (empty(static::$_registry)) {
static::$_registry = new QueueEngineRegistry();
Expand All @@ -127,7 +127,7 @@ protected static function _init()
*
* @return void
*/
protected static function _loadConfig()
protected static function _loadConfig(): void
{
foreach (static::$_config as $name => $properties) {
if (isset($properties['engine'])) {
Expand All @@ -149,7 +149,7 @@ protected static function _loadConfig()
* @return array The configuration array to be stored after parsing the DSN
* @throws \InvalidArgumentException If not passed a string
*/
public static function parseDsn($dsn)
public static function parseDsn(string $dsn): array
{
$dsn = static::_parseDsn($dsn);
if (is_array($dsn)) {
Expand All @@ -168,6 +168,7 @@ public static function parseDsn($dsn)

return $dsn;
}

/**
* Reset all the connected loggers. This is useful to do when changing the logging
* configuration or during testing when you want to reset the internal state of the
Expand All @@ -178,7 +179,7 @@ public static function parseDsn($dsn)
*
* @return void
*/
public static function reset()
public static function reset(): void
{
static::$_registry = null;
static::$_config = [];
Expand All @@ -193,7 +194,7 @@ public static function reset()
* @param \Cake\Core\ObjectRegistry|null $registry Injectable registry object.
* @return \Cake\Core\ObjectRegistry
*/
public static function registry(ObjectRegistry $registry = null)
public static function registry(?ObjectRegistry $registry = null): ObjectRegistry
{
if ($registry) {
static::$_registry = $registry;
Expand All @@ -213,7 +214,7 @@ public static function registry(ObjectRegistry $registry = null)
* @return void
* @throws \InvalidArgumentException When a queue engine cannot be created.
*/
protected static function _buildEngine($name)
protected static function _buildEngine(string $name): void
{
$registry = static::registry();

Expand All @@ -236,7 +237,7 @@ protected static function _buildEngine($name)
* @param string $config The configuration name you want an engine for.
* @return \josegonzalez\Queuesadilla\Engine\EngineInterface When caching is disabled a null engine will be returned.
*/
public static function engine($config)
public static function engine(string $config): EngineInterface
{
if (!static::$_enabled) {
return new NullEngine();
Expand All @@ -262,7 +263,7 @@ public static function engine($config)
* @param string $config The configuration name you want an engine for.
* @return \josegonzalez\Queuesadilla\Queue
*/
public static function queue($config)
public static function queue(string $config): Queuer
{
if (isset(static::$_queuers[$config])) {
return static::$_queuers[$config];
Expand All @@ -281,7 +282,7 @@ public static function queue($config)
* @param array $options an array of options for publishing the job
* @return bool the result of the push
*/
public static function push($callable, $args = [], $options = [])
public static function push(callable $callable, array $args = [], array $options = []): bool
{
$config = Hash::get($options, 'config', 'default');
$queue = static::queue($config);
Expand Down
19 changes: 8 additions & 11 deletions src/Queue/QueueEngineRegistry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla\Queue;

use Cake\Core\App;
Expand All @@ -14,21 +16,16 @@
*/
class QueueEngineRegistry extends ObjectRegistry
{

/**
* Resolve a queue engine classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
* @return string Either the correct classname or null.
*/
protected function _resolveClassName($class)
protected function _resolveClassName(string $class): ?string
{
if (is_object($class)) {
return $class;
}

return App::className($class, 'Queue/Engine', 'Engine');
}

Expand All @@ -38,11 +35,11 @@ protected function _resolveClassName($class)
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class The classname that is missing.
* @param string $plugin The plugin the queue engine is missing in.
* @param string|null $plugin The plugin the queue engine is missing in.
* @return void
* @throws \RuntimeException
*/
protected function _throwMissingClassError($class, $plugin)
protected function _throwMissingClassError(string $class, ?string $plugin): void
{
throw new RuntimeException(sprintf('Could not load class %s', $class));
}
Expand All @@ -58,7 +55,7 @@ protected function _throwMissingClassError($class, $plugin)
* @return \josegonzalez\Queuesadilla\Engine\EngineInterface The constructed queue engine class.
* @throws \RuntimeException when an object doesn't implement the correct interface.
*/
protected function _create($class, $alias, $settings)
protected function _create($class, string $alias, array $settings): EngineInterface
{
if (is_callable($class)) {
$class = $class($alias);
Expand Down Expand Up @@ -100,7 +97,7 @@ protected function _create($class, $alias, $settings)
* @param string $name The queue engine name.
* @return void
*/
public function unload($name)
public function unload(string $name): void
{
unset($this->_loaded[$name]);
}
Expand Down
16 changes: 11 additions & 5 deletions src/Shell/QueuesadillaShell.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla\Shell;

use Cake\Console\ConsoleOptionParser;
use Cake\Console\Shell;
use Cake\Log\Log;
use Cake\Utility\Hash;
use Josegonzalez\CakeQueuesadilla\Queue\Queue;
use josegonzalez\Queuesadilla\Engine\Base as BaseEngine;
use josegonzalez\Queuesadilla\Worker\Base as BaseWorker;
use Psr\Log\LoggerInterface;

class QueuesadillaShell extends Shell
{
Expand All @@ -14,7 +20,7 @@ class QueuesadillaShell extends Shell
*
* @return void
*/
public function main()
public function main(): void
{
$logger = Log::engine($this->params['logger']);
$engine = $this->getEngine($logger);
Expand All @@ -28,7 +34,7 @@ public function main()
* @param \Psr\Log\LoggerInterface $logger logger
* @return \josegonzalez\Queuesadilla\Engine\Base
*/
public function getEngine($logger)
public function getEngine(LoggerInterface $logger): BaseEngine
{
$config = Hash::get($this->params, 'config');
$engine = Queue::engine($config);
Expand All @@ -47,15 +53,15 @@ public function getEngine($logger)
* @param \Psr\Log\LoggerInterface $logger logger
* @return \josegonzalez\Queuesadilla\Worker\Base
*/
public function getWorker($engine, $logger)
public function getWorker(BaseEngine $engine, LoggerInterface $logger): BaseWorker
{
$worker = $this->params['worker'];
$WorkerClass = "josegonzalez\\Queuesadilla\\Worker\\" . $worker . "Worker";

return new $WorkerClass($engine, $logger, [
'queue' => $engine->config('queue'),
'maxRuntime' => $engine->config('maxRuntime'),
'maxIterations' => $engine->config('maxIterations')
'maxIterations' => $engine->config('maxIterations'),
]);
}

Expand All @@ -64,7 +70,7 @@ public function getWorker($engine, $logger)
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function getOptionParser()
public function getOptionParser(): ConsoleOptionParser
{
$parser = parent::getOptionParser();
$parser->addOption('config', [
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/QueueTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Josegonzalez\CakeQueuesadilla\Traits;

use Josegonzalez\CakeQueuesadilla\Queue\Queue;
Expand All @@ -13,7 +15,7 @@ trait QueueTrait
* @param array $options an array of options for publishing the job
* @return bool the result of the push
*/
protected function push($callable, $args = [], $options = [])
protected function push(callable $callable, array $args = [], array $options = []): bool
{
return Queue::push($callable, $args, $options);
}
Expand Down

0 comments on commit e062a62

Please sign in to comment.