Remove unused ConfigException class, make code style adjustments

Deleted ConfigException class as it was not being used anywhere in the project.
Code style adjustments were made to conform with the PSR-12 coding standard. This includes property and variable naming conventions, use of strict equality operators, reformatting of code and removal of unnecessary comments. The .idea/php.xml file was also updated to a newer version of the library.
Log functions are updated to throw exceptions for non-existent message and invalid level. Also, LogLib is now registered/unregistered  as an exception handler.
Other adjustments were made to achieve consistency in the codebase including renaming properties for clarity, moving magic strings into constants, improving code readability and adding descriptive comments.
This commit is contained in:
Netkas 2023-10-10 23:29:26 -04:00
parent 892c4c7ad7
commit 4fa87c349c
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
18 changed files with 666 additions and 494 deletions

View file

@ -7,56 +7,35 @@
class Backtrace
{
/**
* The function name of the backtrace
*
* @var string|null
* @property_name function
*/
private $Function;
private $function;
/**
* The line number of the backtrace
*
* @var int|null
* @property_name line
*/
private $Line;
private $line;
/**
* The file name of the backtrace
*
* @var string|null
* @property_name file
*/
private $File;
private $file;
/**
* The class name, if any, of the backtrace
*
* @var string|null
* @property_name class
*/
private $Class;
private $class;
/**
* The current call type. If a method call, "->" is returned.
* If a static method call, "::" is returned. If a function call,
* nothing is returned.
*
* @see CallType
* @var string|null
* @property_name type
*/
private $Type;
private $type;
/**
* If inside a function, this lists the functions arguments. If inside
* an included file, this lists the included file name(s).
*
* @var array|null
* @property_name args
*/
private $Args;
private $args;
/**
* Public Constructor
@ -66,109 +45,135 @@
public function __construct(?array $backtrace=null)
{
if($backtrace === null)
{
return;
}
$this->Function = $backtrace['function'] ?? null;
$this->Line = $backtrace['line'] ?? null;
$this->File = $backtrace['file'] ?? null;
$this->Class = $backtrace['class'] ?? null;
$this->Type = $backtrace['type'] ?? null;
$this->Args = $backtrace['args'] ?? null;
$this->function = $backtrace['function'] ?? null;
$this->line = $backtrace['line'] ?? null;
$this->file = $backtrace['file'] ?? null;
$this->class = $backtrace['class'] ?? null;
$this->type = $backtrace['type'] ?? null;
$this->args = $backtrace['args'] ?? null;
}
/**
* Optional. Returns the function name of the backtrace
*
* @return string|null
*/
public function getFunction(): ?string
{
return $this->Function;
return $this->function;
}
/**
* @param string|null $Function
* Sets the function name of the backtrace
*
* @param string|null $function
*/
public function setFunction(?string $Function): void
public function setFunction(?string $function): void
{
$this->Function = $Function;
$this->function = $function;
}
/**
* Optional. Returns the line number of the backtrace
*
* @return int|null
*/
public function getLine(): ?int
{
return $this->Line;
return $this->line;
}
/**
* @param int|null $Line
* Sets the line number of the backtrace
*
* @param int|null $line
*/
public function setLine(?int $Line): void
public function setLine(?int $line): void
{
$this->Line = $Line;
$this->line = $line;
}
/**
* Optional. Returns the file name of the backtrace
*
* @return string|null
*/
public function getFile(): ?string
{
return $this->File;
return $this->file;
}
/**
* @param string|null $File
* Sets the file name of the backtrace
*
* @param string|null $file
*/
public function setFile(?string $File): void
public function setFile(?string $file): void
{
$this->File = $File;
$this->file = $file;
}
/**
* Optional. Returns the class name, if any, of the backtrace
*
* @return string|null
*/
public function getClass(): ?string
{
return $this->Class;
return $this->class;
}
/**
* @param string|null $Class
* Sets the class name, if any, of the backtrace
*
* @param string|null $class
*/
public function setClass(?string $Class): void
public function setClass(?string $class): void
{
$this->Class = $Class;
$this->class = $class;
}
/**
* Optional. Returns the current call type. If a method call, "->" is returned.
*
* @return string|null
*/
public function getType(): ?string
{
return $this->Type;
return $this->type;
}
/**
* @param string|null $Type
* Sets the current call type. If a method call, "->" is returned.
*
* @param string|null $type
*/
public function setType(?string $Type): void
public function setType(?string $type): void
{
$this->Type = $Type;
$this->type = $type;
}
/**
* Optional. Return the functions arguments or included file name(s)
*
* @return array|null
*/
public function getArgs(): ?array
{
return $this->Args;
return $this->args;
}
/**
* @param array|null $Args
* Sets the function arguments or included file name(s)
*
* @param array|null $args
*/
public function setArgs(?array $Args): void
public function setArgs(?array $args): void
{
$this->Args = $Args;
$this->args = $args;
}
}

View file

@ -7,37 +7,76 @@
use LogLib\Abstracts\LevelType;
use LogLib\Classes\Utilities;
use Throwable;
class Event
{
/**
* The level of the event
*
* @see LevelType
* @var string
* @property_name level
*/
public $Level;
private $level;
/**
* An array of backtraces, if any, that were created when the event was created
*
* @var Backtrace[]|null
*/
private $Backtrace;
private $backtrace;
/**
* The exception that was thrown, if any
*
* @var Throwable|null
*/
public $Exception;
private $exception;
/**
* The message of the event
*
* @var string
*/
public $Message;
private $message;
/**
* Event constructor.
*
* @param string $message
* @param int $level
* @param Throwable|null $exception
* @param array|null $backtrace
*/
public function __construct(string $message, int $level, ?Throwable $exception=null, ?array $backtrace=null)
{
$this->message = $message;
$this->level = $level;
$this->exception = $exception;
$this->backtrace = $backtrace;
}
/**
* Returns the level of the event
*
* @see LevelType
* @return int
*/
public function getLevel(): int
{
return $this->level;
}
/**
* Returns the message of the event
*
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* Optional. Returns the exception to the event
*
* @return Throwable|null
*/
public function getException(): ?Throwable
{
return $this->exception;
}
/**
* Sets an exception to the event
@ -47,23 +86,27 @@
*/
public function setException(Throwable $e): void
{
$this->Exception = Utilities::exceptionToArray($e);
$this->exception = Utilities::exceptionToArray($e);
}
/**
* Returns the backtrace of the event
*
* @return array|null
*/
public function getBacktrace(): ?array
{
return $this->Backtrace;
return $this->backtrace;
}
/**
* @param array|null $Backtrace
* Sets the backtrace of the event
*
* @param array|null $backtrace
*/
public function setBacktrace(?array $Backtrace): void
public function setBacktrace(?array $backtrace): void
{
$this->Backtrace = $Backtrace;
$this->backtrace = $backtrace;
}
}

View file

@ -8,19 +8,16 @@
class Options
{
/**
* The name of the application
*
* @var string
* @property_name application_name
*/
private $ApplicationName;
private $application_name;
/**
* Options constructor.
*/
public function __construct(string $application_name)
{
$this->ApplicationName = $application_name;
$this->application_name = $application_name;
}
/**
@ -30,7 +27,7 @@
*/
public function getApplicationName(): string
{
return $this->ApplicationName;
return $this->application_name;
}
}

View file

@ -4,7 +4,6 @@
namespace LogLib\Objects;
use InvalidArgumentException;
use LogLib\Abstracts\LevelType;
use LogLib\Classes\Utilities;
@ -16,7 +15,7 @@
* @var bool
* @property_name console_output
*/
private $ConsoleOutput;
private $console_output;
/**
* Indicates if ANSI colors should be used in the console output
@ -24,7 +23,7 @@
* @var bool
* @property_name display_ansi
*/
private $DisplayAnsi;
private $display_ansi;
/**
* Indicates if LogLib should handle uncaught exceptions
@ -32,7 +31,7 @@
* @var bool
* @property_name handle_exceptions
*/
private $HandleExceptions;
private $handle_exceptions;
/**
* The current log level
@ -40,17 +39,17 @@
* @var int
* @see LevelType
*/
private $LogLevel;
private $log_level;
/**
* Public Constructor
*/
public function __construct()
{
$this->ConsoleOutput = Utilities::runningInCli();
$this->DisplayAnsi = Utilities::getDisplayAnsi();
$this->HandleExceptions = true;
$this->LogLevel = Utilities::getLogLevel();
$this->console_output = Utilities::runningInCli();
$this->display_ansi = Utilities::getDisplayAnsi();
$this->log_level = Utilities::getLogLevel();
$this->handle_exceptions = true;
}
/**
@ -58,62 +57,62 @@
*/
public function isConsoleOutput(): bool
{
return $this->ConsoleOutput;
return $this->console_output;
}
/**
* @param bool $ConsoleOutput
* @param bool $console_output
*/
public function setConsoleOutput(bool $ConsoleOutput): void
public function setConsoleOutput(bool $console_output): void
{
$this->ConsoleOutput = $ConsoleOutput;
$this->console_output = $console_output;
}
/**
* @return bool
*/
public function isDisplayAnsi(): bool
public function displayAnsi(): bool
{
return $this->DisplayAnsi;
return $this->display_ansi;
}
/**
* @param bool $DisplayAnsi
* @param bool $display_ansi
*/
public function setDisplayAnsi(bool $DisplayAnsi): void
public function setDisplayAnsi(bool $display_ansi): void
{
$this->DisplayAnsi = $DisplayAnsi;
$this->display_ansi = $display_ansi;
}
/**
* @return bool
*/
public function isHandleExceptions(): bool
public function handleExceptions(): bool
{
return $this->HandleExceptions;
return $this->handle_exceptions;
}
/**
* @param bool $HandleExceptions
* @param bool $handle_exceptions
*/
public function setHandleExceptions(bool $HandleExceptions): void
public function setHandleExceptions(bool $handle_exceptions): void
{
$this->HandleExceptions = $HandleExceptions;
$this->handle_exceptions = $handle_exceptions;
}
/**
* @return int
*/
public function getLogLevel(): int
public function getLoglevel(): int
{
return $this->LogLevel;
return $this->log_level;
}
/**
* @param int $LogLevel
* @param int $log_level
*/
public function setLogLevel(int $LogLevel): void
public function setLoglevel(int $log_level): void
{
$this->LogLevel = $LogLevel;
$this->log_level = $log_level;
}
}