From 5e44f36dbc9c3d3c104620ee351ce7031df6b30b Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 3 Nov 2023 20:03:34 -0400 Subject: [PATCH] - Forced variable typing --- composer.json | 15 +++++++++++++++ meta/negundo.php | 12 ++++++++++++ src/Dump.php | 12 ++++++------ src/Handler.php | 20 ++++++++++---------- src/NegundoMiddleware.php | 2 +- src/SoftwareConfig.php | 4 ++-- src/Task.php | 10 +++++----- src/Transport/Curl.php | 2 +- src/Util/DumpHandler.php | 2 +- src/Util/ExceptionHandler.php | 2 +- src/Util/TaskHandler.php | 4 ++-- 11 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 meta/negundo.php diff --git a/composer.json b/composer.json index b4ddf6d..645b3e3 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "mcnd/negundo-client", "description": "Negundo client which allow sending dump(), error and tasks reports", "keywords": ["negundo","dev","debug","psr15","middleware"], + "type": "library", "license": "MIT", "authors": [ { @@ -13,5 +14,19 @@ "psr-4": { "Negundo\\Client\\": "src/" } + }, + "require": { + "php": "^8.2", + "ext-curl": "*", + "ext-json": "*" + }, + "extra" : { + "lean" : { + "autoload": { + "definitions" : [ + "meta/negundo.php" + ] + } + } } } \ No newline at end of file diff --git a/meta/negundo.php b/meta/negundo.php new file mode 100644 index 0000000..67fb3ee --- /dev/null +++ b/meta/negundo.php @@ -0,0 +1,12 @@ + create(SoftwareConfig::class)->constructor(getenv('NEGUNDO_HASH'), getenv('NEGUNDO_SERVER')), + NegundoMiddleware::class => autowire(NegundoMiddleware::class), + Dump::class => autowire(Dump::class), + Task::class => autowire(Task::class), +]; diff --git a/src/Dump.php b/src/Dump.php index 752239b..f7cd36c 100644 --- a/src/Dump.php +++ b/src/Dump.php @@ -2,17 +2,17 @@ namespace Negundo\Client { class Dump { - public static /* array */ $instances = []; + public static array $instances = []; - # public /*string*/ $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s"; + # public string $serverUrl = "http://dev.cslsj.qc.ca/debug/dump/report/%s"; - protected /* SoftwareConfig */ $config; + protected SoftwareConfig $config; - protected /*array*/ $sent = []; + protected array $sent = []; - protected /* TransportInterface */ $transport; + protected Transport\TransportInterface $transport; - protected /* Util\DumpHandler */ $dumpHandler; + protected Util\DumpHandler $dumpHandler; public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null) { diff --git a/src/Handler.php b/src/Handler.php index 1a488a1..7b9d511 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -5,21 +5,21 @@ namespace Negundo\Client; use Closure; abstract class Handler { - protected /* SoftwareConfig */ $config; + protected SoftwareConfig $config; - public /* bool */ $registerErrorHandler = true; + public bool $registerErrorHandler = true; - public /* bool */ $registerExceptionHandler = true; + public bool $registerExceptionHandler = true; - public /* bool */ $registerFatalErrorHandler = true; + public bool $registerFatalErrorHandler = true; - protected /*Closure*/ $callback; + protected Closure $callback; - protected /*array*/ $sent = []; - - protected /* TransportInterface */ $transport; + protected Transport\TransportInterface $transport; - protected /* Util\ExceptionHandler */ $exceptionHandler; + protected Util\ExceptionHandler $exceptionHandler; + + protected array $sent = []; public abstract function handleException(\Throwable $ex) : array; @@ -33,7 +33,7 @@ abstract class Handler { $this->registerHandlers(); } - public function registerHandlers() + public function registerHandlers() : void { $this->registerExceptionHandler && set_exception_handler(function(\Throwable $ex) { $this->pushData($ex); diff --git a/src/NegundoMiddleware.php b/src/NegundoMiddleware.php index d56a3b7..73f3469 100644 --- a/src/NegundoMiddleware.php +++ b/src/NegundoMiddleware.php @@ -12,7 +12,7 @@ class NegundoMiddleware extends Handler implements MiddlewareInterface { protected ServerRequestInterface $request; - public $registerExceptionHandler = false; + public bool $registerExceptionHandler = false; public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { diff --git a/src/SoftwareConfig.php b/src/SoftwareConfig.php index 6f6d211..80d6cc6 100644 --- a/src/SoftwareConfig.php +++ b/src/SoftwareConfig.php @@ -4,9 +4,9 @@ namespace Negundo\Client; class SoftwareConfig { - public /*string*/ $serverUrl; + public string $serverUrl; - public /* string */ $softwareHash; + public string $softwareHash; public function __construct(string $softwareHash, string $serverUrl) { diff --git a/src/Task.php b/src/Task.php index 9f0a7ef..e59daaa 100644 --- a/src/Task.php +++ b/src/Task.php @@ -4,15 +4,15 @@ namespace Negundo\Client { class Task { - public static /* array */ $instances = []; + public static array $instances = []; - protected /*array*/ $sent = []; + protected array $sent = []; - protected /* TransportInterface */ $transport; + protected Transport\TransportInterface $transport; - protected /* Util\TaskHandler */ $taskHandler; + protected Util\TaskHandler $taskHandler; - protected /* SoftwareConfig */ $config; + protected SoftwareConfig $config; public function __construct(SoftwareConfig $config, ? DataInterface $dataManipulator = null, Transport\TransportInterface $transport = null) { diff --git a/src/Transport/Curl.php b/src/Transport/Curl.php index 934d58e..ce4d0dd 100644 --- a/src/Transport/Curl.php +++ b/src/Transport/Curl.php @@ -159,7 +159,7 @@ class Curl implements TransportInterface { 35 => "A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.", 36 => "The download could not be resumed because the specified offset was out of the file boundary.", 37 => "A file given with FILE:// couldn't be opened. Most likely because the file path doesn't identify an existing file. Did you check file permissions? ", - 35 => "LDAP cannot bind. LDAP bind operation failed.", + 38 => "LDAP cannot bind. LDAP bind operation failed.", 39 => "LDAP search failed.", 41 => "Function not found. A required zlib function was not found.", 42 => "Aborted by callback. A callback returned \"abort\" to libcurl.", diff --git a/src/Util/DumpHandler.php b/src/Util/DumpHandler.php index 8665bfb..f72826f 100644 --- a/src/Util/DumpHandler.php +++ b/src/Util/DumpHandler.php @@ -6,7 +6,7 @@ use Negundo\Client\DataInterface; class DumpHandler { - public /*DataInterface*/ $dataManipulator; + public DataInterface $dataManipulator; public function __construct(DataInterface $dataManipulator = null) { diff --git a/src/Util/ExceptionHandler.php b/src/Util/ExceptionHandler.php index bc3c104..74539a6 100644 --- a/src/Util/ExceptionHandler.php +++ b/src/Util/ExceptionHandler.php @@ -6,7 +6,7 @@ use Negundo\Client\DataInterface; class ExceptionHandler { - public /*DataInterface*/ $dataManipulator; + public ? DataInterface $dataManipulator; public function __construct(DataInterface $dataManipulator = null) { diff --git a/src/Util/TaskHandler.php b/src/Util/TaskHandler.php index 3c8e185..c39d2a4 100644 --- a/src/Util/TaskHandler.php +++ b/src/Util/TaskHandler.php @@ -6,7 +6,7 @@ use Negundo\Client\DataInterface; class TaskHandler { - public /*DataInterface*/ $dataManipulator; + public DataInterface $dataManipulator; public function __construct(DataInterface $dataManipulator = null) { @@ -20,8 +20,8 @@ class TaskHandler { array_shift($backtrace); $trace = $backtrace[0] ?? [ - "line" => -1, "file" => "unknown", + "line" => -1, ]; $post = [