Skip to content

Commit

Permalink
revert: typed properties
Browse files Browse the repository at this point in the history
- Reverted typed properties feature
- Lowered minimum supported PHP version to 7.2
- More verbose MongoDB handler, fixed return types
  • Loading branch information
PAXANDDOS committed Mar 24, 2023
1 parent 4a23ffb commit 383cc7a
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 134 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^7.2|^8.0",
"ext-pcntl": "*",
"predis/predis": "1.1.*",
"predis/predis": "^1.1.0",
"monolog/monolog": "^2.5",
"symfony/console": "^5.4|^6.0"
},
Expand All @@ -36,7 +36,7 @@
"symfony/yaml": "For using the YAML configuration file."
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^8.0|^9.0",
"mongodb/mongodb": "^1.0",
"symfony/process": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
build:
context: .
args:
- PHP_VERSION=7
- PHP_VERSION=7.2
ports:
- 8000:80
volumes:
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class Config
/**
* @var array Configuration settings array.
*/
protected static array $config = [];
protected static $config = [];

/**
* Reads and loads data from a config file
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class Command extends \Symfony\Component\Console\Command\Command
/**
* @var Logger The logger instance
*/
protected Logger $logger;
protected $logger;

/**
* @var array<string, mixed> Config array
*/
protected array $config = [];
protected $config = [];

/**
* @var array Config to options mapping
*/
protected array $configOptionMap = [
protected $configOptionMap = [
'include' => 'include',
'scheme' => 'redis.scheme',
'host' => 'redis.host',
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Command/Socket/Receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
case 'worker:resume':
case 'worker:stop':
case 'worker:cancel':
$valid_id = false;

$id = preg_replace('/[^a-z0-9\*:,\.;-]/i', '', $data['id']);

if (!empty($id)) {
Expand Down Expand Up @@ -235,7 +233,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$server->send($client, $data['json'] ? json_encode($response) : implode(PHP_EOL, array_map(fn ($d) => $d['message'], $response['data'])));
$server->send($client, $data['json'] ? json_encode($response) : implode(PHP_EOL, array_map(function ($d) {
return $d['message'];
}, $response['data'])));

break;
case 'job:queue':
Expand Down
14 changes: 7 additions & 7 deletions src/Console/Command/SpeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public function setProgress(OutputInterface $output, array $stats, float $testTi
$progress_bar .= $progress_complete_length == $progress_length ? '' : ' '.round($progress_percent * 100).'%';

$display = <<<STATS
<comment>%title% php-resque speed test</comment>%clr%
%progress%%clr%
Time: <pop>%in%</pop>%clr%
Processed: <pop>%jobs%</pop>%clr%
Speed: <pop>%speed%</pop>%clr%
Avg job time: <pop>%time%</pop>%clr%
STATS;
<comment>%title% php-resque speed test</comment>%clr%
%progress%%clr%
Time: <pop>%in%</pop>%clr%
Processed: <pop>%jobs%</pop>%clr%
Speed: <pop>%speed%</pop>%clr%
Avg job time: <pop>%time%</pop>%clr%
STATS;

$replace = [
'%title%' => $exec_time == $testTime ? 'Finished' : 'Running',
Expand Down
2 changes: 1 addition & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class Event
/**
* @var array containing all registered callbacks, indexed by event name
*/
protected static array $events = [];
protected static $events = [];

/**
* Listen in on a given event to have a specified callback fired.
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/CatchOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class CatchOutput extends \Symfony\Component\Console\Output\Output
/**
* @var string Stored output string
*/
protected string $written = '';
protected $written = '';

/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/SerializableClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class SerializableClosure
*
* @var \Closure
*/
protected \Closure $closure;
protected $closure;

/**
* The ReflectionFunction instance of the Closure.
*
* @var \ReflectionFunction
*/
protected \ReflectionFunction $reflection;
protected $reflection;

/**
* The code contained by the Closure.
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ final class Table
/**
* @var TableHelper
*/
protected TableHelper $table;
protected $table;

/**
* @var CatchOutput
*/
protected CatchOutput $output;
protected $output;

/**
* Render the table and pass the output back.
Expand Down
6 changes: 3 additions & 3 deletions src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ final class Host
/**
* @var Redis The Redis instance
*/
protected Redis $redis;
protected $redis;

/**
* @var string The hostname
*/
protected string $hostname;
protected $hostname;

/**
* @var int Host key timeout
*/
protected int $timeout = 120;
protected $timeout = 120;

/**
* Get the Redis key
Expand Down
12 changes: 6 additions & 6 deletions src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ final class Job
/**
* @var Redis The Redis instance
*/
protected Redis $redis;
protected $redis;

/**
* @var string The name of the queue that this job belongs to
*/
protected string $queue;
protected $queue;

/**
* @var array|string The payload sent through for this job
Expand All @@ -53,17 +53,17 @@ final class Job
/**
* @var string The ID of this job
*/
protected string $id;
protected $id;

/**
* @var string The classname this job
*/
protected string $class;
protected $class;

/**
* @var string The method name for this job
*/
protected string $method = 'perform';
protected $method = 'perform';

/**
* @var array|null|\Closure The data/arguments for the job
Expand All @@ -83,7 +83,7 @@ final class Job
/**
* @var array of statuses that are considered final/complete
*/
protected static array $completeStatuses = [
protected static $completeStatuses = [
self::STATUS_FAILED,
self::STATUS_COMPLETE,
self::STATUS_CANCELLED,
Expand Down
6 changes: 3 additions & 3 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class Logger
/**
* @var array List of valid log levels
*/
protected array $logTypes = [
protected $logTypes = [
self::DEBUG => 'debug',
self::INFO => 'info',
self::NOTICE => 'notice',
Expand All @@ -76,9 +76,9 @@ final class Logger
];

/**
* @var Monolog The monolog instance
* @var Monolog|null The monolog instance
*/
protected ?Monolog $instance = null;
protected $instance = null;

/**
* Create a Monolog instance and attach a handler
Expand Down
15 changes: 8 additions & 7 deletions src/Logger/Handler/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class Connector
/**
* @var Command command instance
*/
protected Command $command;
protected $command;

/**
* @var InputInterface input instance
*/
protected InputInterface $input;
protected $input;

/**
* @var OutputInterface output instance
*/
protected OutputInterface $output;
protected $output;

/**
* @var array output instance
*/
private array $connectionMap = [
private $connectionMap = [
'Redis' => 'redis://(?P<host>[a-z0-9\._-]+):(?P<port>\d+)/(?P<key>.+)', // redis://127.0.0.1:6379/log:%worker$
'MongoDB' => 'mongodb://(?P<host>[a-z0-9\._-]+):(?P<port>\d+)/(?P<dbname>[a-z0-9_]+)/(?P<collection>.+)', // mongodb://127.0.0.1:27017/dbname/log:%worker%
'CouchDB' => 'couchdb://(?P<host>[a-z0-9\._-]+):(?P<port>\d+)/(?P<dbname>[a-z0-9_]+)', // couchdb://127.0.0.1:27017/dbname
Expand Down Expand Up @@ -72,7 +72,7 @@ public function __construct(Command $command, InputInterface $input, OutputInter
* @param string $logFormat
* @throws InvalidArgumentException
*
* @return Monolog\Handler\HandlerInterface
* @return \Monolog\Handler\HandlerInterface
*/
public function resolve(string $logFormat): \Monolog\Handler\HandlerInterface
{
Expand All @@ -95,8 +95,9 @@ public function resolve(string $logFormat): \Monolog\Handler\HandlerInterface
// Tell them the error of their ways
$format = str_replace(['(?:', ')?', '\)'], '', $this->connectionMap[$handler]);

$cb = fn ($m) => ($m[1] == 'ignore') ? '' : '<'.$m[1].'>';
$format = preg_replace_callback('/\(\?P<([a-z_]+)>(?:.+?)\)/', $cb, $format);
$format = preg_replace_callback('/\(\?P<([a-z_]+)>(?:.+?)\)/', function ($m) {
return ($m[1] == 'ignore') ? '' : '<'.$m[1].'>';
}, $format);

throw new \InvalidArgumentException('Invalid format "'.$logFormat.'" for "'.$handler.'" handler. Should be of format "'.$format.'"');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Logger/Handler/Connector/ConnectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Resque\Logger\Handler\Connector;

use Monolog\Handler\HandlerInterface;
use Monolog\Handler\AbstractProcessingHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -32,9 +32,9 @@ interface ConnectorInterface
* @param OutputInterface $output
* @param array $args
*
* @return HandlerInterface
* @return AbstractProcessingHandler|\Monolog\Handler\NullHandler
*/
public function resolve(Command $command, InputInterface $input, OutputInterface $output, array $args): HandlerInterface;
public function resolve(Command $command, InputInterface $input, OutputInterface $output, array $args);

/**
* Returns the processor for this handler
Expand Down
7 changes: 4 additions & 3 deletions src/Logger/Handler/Connector/MongoDBConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ class MongoDBConnector extends AbstractConnector
{
public function resolve(Command $command, InputInterface $input, OutputInterface $output, array $args): MongoDBHandler
{
$mongodb = null;
$dsn = strtr('mongodb://host:port', $args);
$options = [];

if (class_exists(Client::class)) {
$mongodb = new Client($dsn, $options);
if (!class_exists(Client::class)) {
throw new \RuntimeException('The MongoDB PHP extension is not installed. Please install mongodb/mongodb and ext-mongodb.');
}

$mongodb = new Client($dsn, $options);

return new MongoDBHandler($mongodb, $this->replacePlaceholders($args['dbname']), $this->replacePlaceholders($args['collection']));
}
}
1 change: 0 additions & 1 deletion src/Logger/Handler/Connector/RedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Resque\Logger\Handler\Connector;

use Resque\Resque;
use Monolog\Handler\RedisHandler;
use Resque\Config;
use Resque\Redis;
Expand Down
8 changes: 4 additions & 4 deletions src/Logger/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ConsoleHandler extends AbstractProcessingHandler
/**
* @var OutputInterface The console output interface
*/
protected OutputInterface $output;
protected $output;

/**
* @var array Map log levels to output verbosity
*/
private array $verbosityLevelMap = [
private $verbosityLevelMap = [
Logger::INFO => OutputInterface::VERBOSITY_NORMAL,
Logger::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
Logger::WARNING => OutputInterface::VERBOSITY_VERY_VERBOSE,
Expand All @@ -50,7 +50,7 @@ class ConsoleHandler extends AbstractProcessingHandler
*
* @var array
*/
private array $styleMap = [
private $styleMap = [
'info' => [],
'notice' => [],
'warning' => ['yellow'],
Expand Down Expand Up @@ -132,7 +132,7 @@ protected function write(array $record): void
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter(): Logger\Formatter\ConsoleFormatter
protected function getDefaultFormatter(): \Monolog\Formatter\FormatterInterface
{
$formatter = new Logger\Formatter\ConsoleFormatter();
if (method_exists($formatter, 'allowInlineLineBreaks')) {
Expand Down
6 changes: 3 additions & 3 deletions src/Logger/Processor/ConsoleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class ConsoleProcessor
/**
* @var Command command instance
*/
protected Command $command;
protected $command;

/**
* @var InputInterface input instance
*/
protected InputInterface $input;
protected $input;

/**
* @var OutputInterface output instance
*/
protected OutputInterface $output;
protected $output;

/**
* Create a new instance
Expand Down
Loading

0 comments on commit 383cc7a

Please sign in to comment.