Updated repository to standards of PHP 8.1.

- Dropped support for PHP 7.4 and 8.0.
- Updated shutdown to no longer halt execution on an error if logger error handlers are disabled.
- Logger::enable() and ::disable() now control the screen log, as it used to in the old days.
This commit is contained in:
Abel Hoogeveen 2022-12-10 12:37:49 +01:00
parent ccb0564a14
commit 0b0f4998b4
Signed by: abelhooge
GPG Key ID: D4F7FB321E3868B7
23 changed files with 172 additions and 264 deletions

View File

@ -8,18 +8,6 @@ steps:
commands: commands:
- composer install - composer install
- name: php74test
image: registry.i15.nl/i15/fuzephp:7.4-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: php80test
image: registry.i15.nl/i15/fuzephp:8.0-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: php81test - name: php81test
image: registry.i15.nl/i15/fuzephp:8.1-alpine image: registry.i15.nl/i15/fuzephp:8.1-alpine
commands: commands:
@ -27,7 +15,7 @@ steps:
- vendor/bin/phpunit -c test/phpunit.xml - vendor/bin/phpunit -c test/phpunit.xml
- name: coverage - name: coverage
image: registry.i15.nl/i15/fuzephp:8.0-alpine image: registry.i15.nl/i15/fuzephp:8.1-alpine
commands: commands:
- docker-php-ext-enable xdebug - docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text - vendor/bin/phpunit -c test/phpunit.xml --coverage-text

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ build/
doc doc
nbproject nbproject
._* ._*
*.cache

View File

@ -10,7 +10,7 @@
} }
], ],
"require": { "require": {
"php": ">=7.4.0" "php": ">=8.1.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9", "phpunit/phpunit": "^9",

View File

@ -52,7 +52,7 @@ trait ComponentPathsTrait
* *
* @param array $componentPaths * @param array $componentPaths
*/ */
public function setDirectories(array $componentPaths) public function setDirectories(array $componentPaths): void
{ {
$this->componentPaths = $componentPaths; $this->componentPaths = $componentPaths;
} }
@ -63,7 +63,7 @@ trait ComponentPathsTrait
* @param string $componentPath * @param string $componentPath
* @param int $priority * @param int $priority
*/ */
public function addComponentPath(string $componentPath, int $priority = Priority::NORMAL) public function addComponentPath(string $componentPath, int $priority = Priority::NORMAL): void
{ {
if (!isset($this->componentPaths[$priority])) if (!isset($this->componentPaths[$priority]))
$this->componentPaths[$priority] = []; $this->componentPaths[$priority] = [];
@ -78,7 +78,7 @@ trait ComponentPathsTrait
* @param string $componentPath * @param string $componentPath
* @param int $priority * @param int $priority
*/ */
public function removeComponentPath(string $componentPath, int $priority = Priority::NORMAL) public function removeComponentPath(string $componentPath, int $priority = Priority::NORMAL): void
{ {
if (!isset($this->componentPaths[$priority])) if (!isset($this->componentPaths[$priority]))
return; return;

View File

@ -124,7 +124,7 @@ class Config
/** /**
* Clears all the config files and discards all changes not committed * Clears all the config files and discards all changes not committed
*/ */
public function discardConfigFiles() public function discardConfigFiles(): void
{ {
$this->cfg = []; $this->cfg = [];
} }
@ -195,7 +195,7 @@ class Config
* @param string $configKey * @param string $configKey
* @param $configValue * @param $configValue
*/ */
public static function overrideConfig(string $configName, string $configKey, $configValue) public static function overrideConfig(string $configName, string $configKey, $configValue): void
{ {
// Convert configName // Convert configName
$configName = strtolower($configName); $configName = strtolower($configName);

View File

@ -122,7 +122,7 @@ abstract class ConfigORMAbstract implements Iterator
* @return mixed Value of the requested entry * @return mixed Value of the requested entry
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function get(string $name) public function get(string $name): mixed
{ {
return $this->cfg[$name]; return $this->cfg[$name];
} }
@ -134,7 +134,7 @@ abstract class ConfigORMAbstract implements Iterator
* @param mixed $value Value of the entry * @param mixed $value Value of the entry
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __set(string $name, $value) public function __set(string $name, mixed $value)
{ {
$this->cfg[$name] = $value; $this->cfg[$name] = $value;
} }
@ -146,7 +146,7 @@ abstract class ConfigORMAbstract implements Iterator
* @param mixed $value Value of the entry * @param mixed $value Value of the entry
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function set(string $name, $value) public function set(string $name, mixed $value)
{ {
$this->cfg[$name] = $value; $this->cfg[$name] = $value;
} }
@ -154,10 +154,10 @@ abstract class ConfigORMAbstract implements Iterator
/** /**
* Unset a value in a config file. * Unset a value in a config file.
* *
* @param string Key of the entry * @param string $name Key of the entry
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __unset($name) public function __unset(string $name)
{ {
unset($this->cfg[$name]); unset($this->cfg[$name]);
} }
@ -166,16 +166,16 @@ abstract class ConfigORMAbstract implements Iterator
* Iterator method. * Iterator method.
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function rewind() public function rewind(): void
{ {
return reset($this->cfg); reset($this->cfg);
} }
/** /**
* Iterator method. * Iterator method.
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function current() public function current(): mixed
{ {
return current($this->cfg); return current($this->cfg);
} }
@ -184,7 +184,7 @@ abstract class ConfigORMAbstract implements Iterator
* Iterator method. * Iterator method.
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function key() public function key(): string|int|null
{ {
return key($this->cfg); return key($this->cfg);
} }
@ -193,9 +193,9 @@ abstract class ConfigORMAbstract implements Iterator
* Iterator method. * Iterator method.
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function next() public function next(): void
{ {
return next($this->cfg); next($this->cfg);
} }
/** /**

View File

@ -224,9 +224,9 @@ class Configurator
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* *
* @var string Name of the template file * @var string $templateName of the template file
*/ */
public static function setLoggerTemplate($templateName) public static function setLoggerTemplate(string $templateName): void
{ {
Logger::setLoggerTemplate($templateName); Logger::setLoggerTemplate($templateName);
} }
@ -283,7 +283,7 @@ class Configurator
* @return Configurator * @return Configurator
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function setDebugAddress($address = 'NONE'): Configurator public function setDebugAddress(string|array $address = 'NONE'): Configurator
{ {
// First we fetch the list // First we fetch the list
if (!is_string($address) && !is_array($address)) if (!is_string($address) && !is_array($address))
@ -348,7 +348,7 @@ class Configurator
// Then load the framework // Then load the framework
$container = Core::init(); $container = Core::init();
Logger::newLevel("Creating container..."); Logger::newLevel("Creating container...");
if ($debug == true) if ($debug)
{ {
define('ENVIRONMENT', 'DEVELOPMENT'); define('ENVIRONMENT', 'DEVELOPMENT');
Logger::enable(); Logger::enable();
@ -358,7 +358,7 @@ class Configurator
// Load components // Load components
foreach ($this->components as $componentSuperClass => $component) foreach ($this->components as $component)
{ {
Logger::logInfo("Adding Component: '" . $component->getName() . "'"); Logger::logInfo("Adding Component: '" . $component->getName() . "'");
foreach ($component->getClasses() as $componentName => $componentClass) foreach ($component->getClasses() as $componentName => $componentClass)

View File

@ -118,7 +118,7 @@ class Core
register_shutdown_function(array('\FuzeWorks\Core', 'shutdown')); register_shutdown_function(array('\FuzeWorks\Core', 'shutdown'));
set_error_handler(array('\FuzeWorks\Core', 'errorHandler'), E_ALL); set_error_handler(array('\FuzeWorks\Core', 'errorHandler'), E_ALL);
set_exception_handler(array('\FuzeWorks\Core', 'exceptionHandler')); set_exception_handler(array('\FuzeWorks\Core', 'exceptionHandler'));
spl_autoload_register(['\FuzeWorks\Core', 'autoloader'], true,false); spl_autoload_register(['\FuzeWorks\Core', 'autoloader']);
// Return the Factory // Return the Factory
return new Factory(); return new Factory();
@ -130,7 +130,7 @@ class Core
* Afterwards run the Logger shutdown function in order to possibly display the log * Afterwards run the Logger shutdown function in order to possibly display the log
* @throws EventException * @throws EventException
*/ */
public static function shutdown() public static function shutdown(): void
{ {
// Fix Apache bug where CWD is changed upon shutdown // Fix Apache bug where CWD is changed upon shutdown
chdir(self::$cwd); chdir(self::$cwd);
@ -154,9 +154,9 @@ class Core
* *
* @param string $varName * @param string $varName
* @param string|null $default * @param string|null $default
* @return array|string|null * @return string|null
*/ */
public static function getEnv(string $varName, string $default = null) public static function getEnv(string $varName, string $default = null): string|null
{ {
// First retrieve the environment variable // First retrieve the environment variable
$var = getenv($varName); $var = getenv($varName);
@ -172,10 +172,10 @@ class Core
/** /**
* Checks whether the current running version of PHP is equal to the input string. * Checks whether the current running version of PHP is equal to the input string.
* *
* @param string * @param string $version
* @return bool true if running higher than input string * @return bool true if running higher than input string
*/ */
public static function isPHP($version): bool public static function isPHP(string $version): bool
{ {
static $_is_php; static $_is_php;
$version = (string) $version; $version = (string) $version;
@ -188,7 +188,7 @@ class Core
return $_is_php[$version]; return $_is_php[$version];
} }
public static function exceptionHandler() public static function exceptionHandler(): void
{ {
for ($i = Priority::getHighestPriority(); $i <= Priority::getLowestPriority(); $i++) for ($i = Priority::getHighestPriority(); $i <= Priority::getLowestPriority(); $i++)
{ {
@ -200,7 +200,7 @@ class Core
} }
} }
public static function errorHandler() public static function errorHandler(): void
{ {
for ($i = Priority::getHighestPriority(); $i <= Priority::getLowestPriority(); $i++) for ($i = Priority::getHighestPriority(); $i <= Priority::getLowestPriority(); $i++)
{ {
@ -218,7 +218,7 @@ class Core
* @param callable $callback * @param callable $callback
* @param int $priority * @param int $priority
*/ */
public static function addExceptionHandler(callable $callback, int $priority = Priority::NORMAL) public static function addExceptionHandler(callable $callback, int $priority = Priority::NORMAL): void
{ {
if (!isset(self::$exceptionHandlers[$priority])) if (!isset(self::$exceptionHandlers[$priority]))
self::$exceptionHandlers[$priority] = []; self::$exceptionHandlers[$priority] = [];
@ -233,7 +233,7 @@ class Core
* @param callable $callback * @param callable $callback
* @param int $priority * @param int $priority
*/ */
public static function removeExceptionHandler(callable $callback, int $priority = Priority::NORMAL) public static function removeExceptionHandler(callable $callback, int $priority = Priority::NORMAL): void
{ {
if (isset(self::$exceptionHandlers[$priority]) && in_array($callback, self::$exceptionHandlers[$priority])) if (isset(self::$exceptionHandlers[$priority]) && in_array($callback, self::$exceptionHandlers[$priority]))
{ {
@ -249,7 +249,7 @@ class Core
* @param callable $callback * @param callable $callback
* @param int $priority * @param int $priority
*/ */
public static function addErrorHandler(callable $callback, int $priority = Priority::NORMAL) public static function addErrorHandler(callable $callback, int $priority = Priority::NORMAL): void
{ {
if (!isset(self::$errorHandlers[$priority])) if (!isset(self::$errorHandlers[$priority]))
self::$errorHandlers[$priority] = []; self::$errorHandlers[$priority] = [];
@ -264,7 +264,7 @@ class Core
* @param callable $callback * @param callable $callback
* @param int $priority * @param int $priority
*/ */
public static function removeErrorHandler(callable $callback, int $priority = Priority::NORMAL) public static function removeErrorHandler(callable $callback, int $priority = Priority::NORMAL): void
{ {
if (isset(self::$errorHandlers[$priority]) && in_array($callback, self::$errorHandlers[$priority])) if (isset(self::$errorHandlers[$priority]) && in_array($callback, self::$errorHandlers[$priority]))
{ {
@ -279,7 +279,7 @@ class Core
* @param string $filePath * @param string $filePath
* @throws CoreException * @throws CoreException
*/ */
public static function addAutoloadMap(string $nameSpacePrefix, string $filePath) public static function addAutoloadMap(string $nameSpacePrefix, string $filePath): void
{ {
// Remove leading slashes // Remove leading slashes
$nameSpacePrefix = ltrim($nameSpacePrefix, '\\'); $nameSpacePrefix = ltrim($nameSpacePrefix, '\\');
@ -293,7 +293,7 @@ class Core
self::$autoloadMap[$nameSpacePrefix] = $filePath; self::$autoloadMap[$nameSpacePrefix] = $filePath;
} }
public static function autoloader(string $class) public static function autoloader(string $class): void
{ {
// Remove leading slashes // Remove leading slashes
$class = ltrim($class, '\\'); $class = ltrim($class, '\\');
@ -302,7 +302,7 @@ class Core
foreach (self::$autoloadMap as $prefix => $path) foreach (self::$autoloadMap as $prefix => $path)
{ {
// If not, try next // If not, try next
if (strpos($class, $prefix) === false) if (!str_contains($class, $prefix))
continue; continue;
// If it contains the prefix, attempt to find the file // If it contains the prefix, attempt to find the file
@ -319,7 +319,7 @@ class Core
* Not intended for use by developer. Only for use during testing * Not intended for use by developer. Only for use during testing
* @internal * @internal
*/ */
public static function clearAutoloader() public static function clearAutoloader(): void
{ {
self::$autoloadMap = []; self::$autoloadMap = [];
} }
@ -332,16 +332,14 @@ class Core
* on Unix servers if safe_mode is on. * on Unix servers if safe_mode is on.
* *
* @link https://bugs.php.net/bug.php?id=54709 * @link https://bugs.php.net/bug.php?id=54709
* @param string * @param string $file
* @return bool * @return bool
*/ */
public static function isReallyWritable($file): bool public static function isReallyWritable(string $file): bool
{ {
// If we're on a Unix server with safe_mode off we call is_writable // If we're on a Unix server with safe_mode off we call is_writable
if (DIRECTORY_SEPARATOR === '/' && ! ini_get('safe_mode')) if (DIRECTORY_SEPARATOR === '/' && ! ini_get('safe_mode'))
{
return is_writable($file); return is_writable($file);
}
/* For Windows servers and safe_mode "on" installations we'll actually /* For Windows servers and safe_mode "on" installations we'll actually
* write a file then read it. Bah... * write a file then read it. Bah...
@ -360,9 +358,7 @@ class Core
return TRUE; return TRUE;
} }
elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE)
{
return FALSE; return FALSE;
}
fclose($fp); fclose($fp);
return TRUE; return TRUE;

View File

@ -57,7 +57,7 @@ class DeferredComponentClass
/** /**
* @var mixed return from the invoked method * @var mixed return from the invoked method
*/ */
protected $return; protected mixed $return;
/** /**
* @var bool Whether the method has been invoked * @var bool Whether the method has been invoked
@ -82,7 +82,7 @@ class DeferredComponentClass
* *
* @param $result * @param $result
*/ */
public function invoke($result) public function invoke($result): void
{ {
$this->return = $result; $this->return = $result;
$this->invoked = true; $this->invoked = true;
@ -97,7 +97,7 @@ class DeferredComponentClass
public function getResult() public function getResult()
{ {
if ($this->invoked == true) if ($this->invoked)
return $this->return; return $this->return;
else else
return false; return false;

View File

@ -59,12 +59,11 @@ class Event
/** /**
* @param bool $cancelled True if the event is cancelled, false if the event is not cancelled * @param bool $cancelled True if the event is cancelled, false if the event is not cancelled
*/ */
public function setCancelled(bool $cancelled) public function setCancelled(bool $cancelled): void
{ {
if ($cancelled == true) { if ($cancelled)
$this->cancelled = true; $this->cancelled = true;
} else { else
$this->cancelled = false; $this->cancelled = false;
}
} }
} }

View File

@ -66,14 +66,14 @@ class Events
* *
* @var array * @var array
*/ */
public static array $listeners = array(); public static array $listeners = [];
/** /**
* Whether the event system is enabled or not. * Whether the event system is enabled or not.
* *
* @var array * @var bool
*/ */
private static $enabled = true; private static bool $enabled = true;
/** /**
* Adds a function as listener. * Adds a function as listener.
@ -87,33 +87,25 @@ class Events
* *
* @throws EventException * @throws EventException
*/ */
public static function addListener(callable $callback, string $eventName, int $priority = Priority::NORMAL) public static function addListener(callable $callback, string $eventName, int $priority = Priority::NORMAL): void
{ {
// Perform multiple checks // Perform multiple checks
if (Priority::getPriority($priority) == false) { if (!Priority::getPriority($priority))
throw new EventException('Can not add listener: Unknown priority '.$priority, 1); throw new EventException('Can not add listener: Unknown priority '.$priority, 1);
}
if (empty($eventName)) if (empty($eventName))
{ throw new EventException("Can not add listener: No event name provided", 1);
throw new EventException("Can not add listener: No eventname provided", 1);
}
if (!isset(self::$listeners[$eventName])) { if (!isset(self::$listeners[$eventName]))
self::$listeners[$eventName] = array(); self::$listeners[$eventName] = array();
}
if (!isset(self::$listeners[$eventName][$priority])) { if (!isset(self::$listeners[$eventName][$priority]))
self::$listeners[$eventName][$priority] = array(); self::$listeners[$eventName][$priority] = array();
}
if (func_num_args() > 3) { if (func_num_args() > 3)
$args = array_slice(func_get_args(), 3); $args = array_slice(func_get_args(), 3);
}
else else
{
$args = array(); $args = array();
}
self::$listeners[$eventName][$priority][] = array($callback, $args); self::$listeners[$eventName][$priority][] = array($callback, $args);
} }
@ -121,7 +113,7 @@ class Events
/** /**
* Removes a function as listener. * Removes a function as listener.
* *
* @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net} * @param callable $callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net}
* @param string $eventName The name of the event * @param string $eventName The name of the event
* @param int $priority The priority, even though integers are valid, please use Priority (for example Priority::Lowest) * @param int $priority The priority, even though integers are valid, please use Priority (for example Priority::Lowest)
* *
@ -129,15 +121,13 @@ class Events
* *
* @throws EventException * @throws EventException
*/ */
public static function removeListener(callable $callback, string $eventName, int $priority = Priority::NORMAL) public static function removeListener(callable $callback, string $eventName, int $priority = Priority::NORMAL): void
{ {
if (Priority::getPriority($priority) == false) { if (!Priority::getPriority($priority))
throw new EventException('Unknown priority '.$priority); throw new EventException('Unknown priority '.$priority);
}
if (!isset(self::$listeners[$eventName]) || !isset(self::$listeners[$eventName][$priority])) { if (!isset(self::$listeners[$eventName]) || !isset(self::$listeners[$eventName][$priority]))
return; return;
}
foreach (self::$listeners[$eventName][$priority] as $i => $_callback) { foreach (self::$listeners[$eventName][$priority] as $i => $_callback) {
if ($_callback[0] == $callback) { if ($_callback[0] == $callback) {
@ -159,7 +149,7 @@ class Events
* @return Event The Event * @return Event The Event
* @throws EventException * @throws EventException
*/ */
public static function fireEvent($input): Event public static function fireEvent(mixed $input): Event
{ {
// First try and see if the object is an Event // First try and see if the object is an Event
if (is_object($input)) if (is_object($input))
@ -176,13 +166,11 @@ class Events
$eventName = $input; $eventName = $input;
// Try a direct class // Try a direct class
if (class_exists($eventClass, true)) if (class_exists($eventClass))
{
$event = new $eventClass(); $event = new $eventClass();
}
// Try a core event // Try a core event
elseif (class_exists("\FuzeWorks\Event\\".$eventClass, true)) elseif (class_exists("\FuzeWorks\Event\\".$eventClass))
{ {
$class = "\FuzeWorks\Event\\".$eventClass; $class = "\FuzeWorks\Event\\".$eventClass;
$event = new $class(); $event = new $class();
@ -190,29 +178,23 @@ class Events
// Try a notifier event // Try a notifier event
elseif (func_num_args() == 1) elseif (func_num_args() == 1)
{
$event = new NotifierEvent(); $event = new NotifierEvent();
}
// Or throw an exception on failure // Or throw an exception on failure
else else
{
throw new EventException('Event '.$eventName.' could not be found!', 1); throw new EventException('Event '.$eventName.' could not be found!', 1);
}
} }
else else
{ {
throw new EventException('Event could not be loaded. Invalid variable provided.', 1); throw new EventException('Event could not be loaded. Invalid variable provided.', 1);
} }
if (func_num_args() > 1) { if (func_num_args() > 1)
call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1)); call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1));
}
// Do not run if the event system is disabled // Do not run if the event system is disabled
if (!self::$enabled) { if (!self::$enabled)
return $event; return $event;
}
//There are listeners for this event //There are listeners for this event
if (isset(self::$listeners[$eventName])) { if (isset(self::$listeners[$eventName])) {
@ -257,7 +239,7 @@ class Events
/** /**
* Enables the event system. * Enables the event system.
*/ */
public static function enable() public static function enable(): void
{ {
Logger::log('Enabled the Event system'); Logger::log('Enabled the Event system');
self::$enabled = true; self::$enabled = true;
@ -266,7 +248,7 @@ class Events
/** /**
* Disables the event system. * Disables the event system.
*/ */
public static function disable() public static function disable(): void
{ {
Logger::log('Disabled the Event system'); Logger::log('Disabled the Event system');
self::$enabled = false; self::$enabled = false;

View File

@ -158,7 +158,7 @@ class Factory
// Load the config file of the FuzeWorks core // Load the config file of the FuzeWorks core
try { try {
$cfg = $this->config->get('core'); $cfg = $this->config->get('core');
} catch (ConfigException $e) { } catch (ConfigException) {
throw new CoreException("Could not initiate Factory. Config 'core' could not be found."); throw new CoreException("Could not initiate Factory. Config 'core' could not be found.");
} }
@ -199,7 +199,7 @@ class Factory
* @return mixed * @return mixed
* @throws FactoryException * @throws FactoryException
*/ */
public static function getInstance(string $instanceName = null) public static function getInstance(string $instanceName = null): mixed
{ {
if (is_null($instanceName)) if (is_null($instanceName))
return self::$sharedFactoryInstance; return self::$sharedFactoryInstance;
@ -258,8 +258,8 @@ class Factory
* @return mixed * @return mixed
* @throws FactoryException * @throws FactoryException
*/ */
public static function cloneInstance(string $className, bool $onlyReturn = false) public static function cloneInstance(string $className, bool $onlyReturn = false): mixed
{ {
// Determine the class to load // Determine the class to load
$instanceName = strtolower($className); $instanceName = strtolower($className);
@ -284,7 +284,7 @@ class Factory
* @param mixed $object Object to replace the class with * @param mixed $object Object to replace the class with
* @return Factory Instance * @return Factory Instance
*/ */
public function setInstance(string $objectName, $object): self public function setInstance(string $objectName, mixed $object): self
{ {
// Determine the instance name // Determine the instance name
$instanceName = strtolower($objectName); $instanceName = strtolower($objectName);

View File

@ -64,7 +64,7 @@ class Libraries
* *
* @var Factory * @var Factory
*/ */
protected $factory; protected Factory $factory;
/** /**
* Libraries constructor. * Libraries constructor.
@ -80,9 +80,9 @@ class Libraries
* Add a library to FuzeWorks by adding an object. * Add a library to FuzeWorks by adding an object.
* *
* @param string $libraryName * @param string $libraryName
* @param object $libraryObject * @param iLibrary $libraryObject
*/ */
public function addLibraryObject(string $libraryName, object $libraryObject) public function addLibraryObject(string $libraryName, iLibrary $libraryObject): void
{ {
$this->libraryObjects[strtolower($libraryName)] = $libraryObject; $this->libraryObjects[strtolower($libraryName)] = $libraryObject;
} }
@ -94,9 +94,9 @@ class Libraries
* @param string $libraryClass * @param string $libraryClass
* @throws LibraryException * @throws LibraryException
*/ */
public function addLibraryClass(string $libraryName, string $libraryClass) public function addLibraryClass(string $libraryName, string $libraryClass): void
{ {
if (!class_exists($libraryClass, true)) if (!class_exists($libraryClass))
throw new LibraryException("Could not add library class. '" . $libraryClass . "' could not be loaded.", 1); throw new LibraryException("Could not add library class. '" . $libraryClass . "' could not be loaded.", 1);
$this->libraryClasses[strtolower($libraryName)] = $libraryClass; $this->libraryClasses[strtolower($libraryName)] = $libraryClass;
@ -114,10 +114,10 @@ class Libraries
* @param string $libraryName * @param string $libraryName
* @param array $parameters * @param array $parameters
* @param array $libraryPaths * @param array $libraryPaths
* @return object * @return iLibrary
* @throws LibraryException * @throws LibraryException
*/ */
public function get(string $libraryName, array $parameters = [], array $libraryPaths = []) public function get(string $libraryName, array $parameters = [], array $libraryPaths = []): iLibrary
{ {
// Test for empty string // Test for empty string
if (empty($libraryName)) if (empty($libraryName))
@ -178,12 +178,12 @@ class Libraries
* @param string $libraryClass * @param string $libraryClass
* @param array $parameters * @param array $parameters
* @throws LibraryException * @throws LibraryException
* @return object * @return iLibrary
*/ */
protected function initLibrary(string $libraryName, string $libraryClass, array $parameters = []) protected function initLibrary(string $libraryName, string $libraryClass, array $parameters = []): iLibrary
{ {
// First check to see if the library is already loaded // First check to see if the library is already loaded
if (!class_exists($libraryClass, true)) if (!class_exists($libraryClass))
throw new LibraryException("Could not initiate library. Class not found", 1); throw new LibraryException("Could not initiate library. Class not found", 1);
// Determine what parameters to use // Determine what parameters to use
@ -191,7 +191,7 @@ class Libraries
{ {
try { try {
$parameters = $this->factory->config->getConfig(strtolower($libraryName))->toArray(); $parameters = $this->factory->config->getConfig(strtolower($libraryName))->toArray();
} catch (ConfigException $e) { } catch (ConfigException) {
// No problem, just use an empty array instead // No problem, just use an empty array instead
$parameters = array(); $parameters = array();
} }
@ -210,9 +210,9 @@ class Libraries
$headerReflection = new ReflectionClass(get_class($classObject)); $headerReflection = new ReflectionClass(get_class($classObject));
$filePath = dirname($headerReflection->getFileName()) . (!is_null($classObject->getSourceDirectory()) ? DS . $classObject->getSourceDirectory() : '' ); $filePath = dirname($headerReflection->getFileName()) . (!is_null($classObject->getSourceDirectory()) ? DS . $classObject->getSourceDirectory() : '' );
$prefix = $classObject->getClassesPrefix(); $prefix = $classObject->getClassesPrefix();
if (!is_null($filePath) && !is_null($prefix)) if (!is_null($prefix))
Core::addAutoloadMap($prefix, $filePath); Core::addAutoloadMap($prefix, $filePath);
} catch (CoreException $e) { } catch (CoreException) {
throw new LibraryException("Could not initiate library. Failed to add to autoloader."); throw new LibraryException("Could not initiate library. Failed to add to autoloader.");
} }

View File

@ -68,25 +68,25 @@ class Logger {
private static bool $print_to_screen = false; private static bool $print_to_screen = false;
/** /**
* Whether the Logger has been enabled or not * Whether currently the error and exception handlers are enabled or not.
* *
* @var bool * @var bool
*/ */
private static bool $isEnabled = false; private static bool $handlers_enabled = false;
/** /**
* whether to output the log of the last entire request to a file after FuzeWorks has run. * whether to output the log of the last entire request to a file after FuzeWorks has run.
* *
* @var bool * @var bool
*/ */
private static $log_last_request = false; private static bool $log_last_request = false;
/** /**
* Whether to output the log of all errors to a file after FuzeWorks has run * Whether to output the log of all errors to a file after FuzeWorks has run
* *
* @var bool * @var bool
*/ */
private static $log_errors_to_file = false; private static bool $log_errors_to_file = false;
/** /**
* The template to use when parsing the debug log * The template to use when parsing the debug log
@ -102,13 +102,6 @@ class Logger {
*/ */
public static bool $debug = false; public static bool $debug = false;
/**
* List of all benchmark markpoints.
*
* @var array
*/
public static array $markPoints = [];
/** /**
* Initiates the Logger. * Initiates the Logger.
* *
@ -122,10 +115,8 @@ class Logger {
// Register the error handler, Untestable // Register the error handler, Untestable
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if ($cfg_error->get('fuzeworks_error_reporting') == true) if ($cfg_error->get('fuzeworks_error_reporting'))
{
self::enableHandlers(); self::enableHandlers();
}
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
// Set PHP error reporting // Set PHP error reporting
@ -143,17 +134,17 @@ class Logger {
/** /**
* Enable error to screen logging. * Enable error to screen logging.
*/ */
public static function enable() public static function enable(): void
{ {
self::$isEnabled = true; self::$print_to_screen = true;
} }
/** /**
* Disable error to screen logging. * Disable error to screen logging.
*/ */
public static function disable() public static function disable(): void
{ {
self::$isEnabled = false; self::$print_to_screen = false;
} }
/** /**
@ -161,24 +152,7 @@ class Logger {
*/ */
public static function isEnabled(): bool public static function isEnabled(): bool
{ {
return self::$isEnabled; return self::$print_to_screen;
}
/**
* Enable outputting the debugger after the request has been processed
*/
public static function enableScreenLog()
{
if (!Core::isProduction())
self::$print_to_screen = true;
}
/**
* Disable outputting the debugger after the request has been processed
*/
public static function disableScreenLog()
{
self::$print_to_screen = false;
} }
/** /**
@ -187,8 +161,9 @@ class Logger {
* Registers errorHandler() and exceptionHandler() as the respective handlers for PHP * Registers errorHandler() and exceptionHandler() as the respective handlers for PHP
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function enableHandlers() public static function enableHandlers(): void
{ {
self::$handlers_enabled = true;
Core::addErrorHandler(['\FuzeWorks\Logger', 'errorHandler']); Core::addErrorHandler(['\FuzeWorks\Logger', 'errorHandler']);
Core::addExceptionHandler(['\FuzeWorks\Logger', 'exceptionHandler']); Core::addExceptionHandler(['\FuzeWorks\Logger', 'exceptionHandler']);
} }
@ -199,8 +174,9 @@ class Logger {
* Unregisters errorHandler() and exceptionHandler() as the respective handlers for PHP * Unregisters errorHandler() and exceptionHandler() as the respective handlers for PHP
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function disableHandlers() public static function disableHandlers(): void
{ {
self::$handlers_enabled = false;
Core::removeErrorHandler(['\FuzeWorks\Logger', 'errorHandler']); Core::removeErrorHandler(['\FuzeWorks\Logger', 'errorHandler']);
Core::removeExceptionHandler(['\FuzeWorks\Logger', 'exceptionHandler']); Core::removeExceptionHandler(['\FuzeWorks\Logger', 'exceptionHandler']);
} }
@ -213,7 +189,7 @@ class Logger {
* Logs data to screen when requested to do so * Logs data to screen when requested to do so
* @throws EventException * @throws EventException
*/ */
public static function shutdown() public static function shutdown(): void
{ {
// And finally stop the Logging // And finally stop the Logging
self::stopLevel(); self::stopLevel();
@ -223,10 +199,10 @@ class Logger {
self::logToScreen(); self::logToScreen();
} }
if (self::$log_last_request == true) if (self::$log_last_request)
self::logLastRequest(); self::logLastRequest();
if (self::$log_errors_to_file == true) if (self::$log_errors_to_file)
self::logErrorsToFile(); self::logErrorsToFile();
} }
@ -237,13 +213,13 @@ class Logger {
* *
* Logs a fatal error and outputs the log when configured or requested to do so * Logs a fatal error and outputs the log when configured or requested to do so
*/ */
public static function shutdownError() public static function shutdownError(): void
{ {
$error = error_get_last(); $error = error_get_last();
if ($error !== null) { if ($error !== null && self::$handlers_enabled) {
// Log it! // Log it!
$thisType = self::getType($error['type']); $thisType = self::getType($error['type']);
$LOG = array('type' => (!is_null($thisType) ? $thisType : 'ERROR'), $LOG = array('type' => $thisType,
'message' => $error['message'], 'message' => $error['message'],
'logFile' => $error['file'], 'logFile' => $error['file'],
'logLine' => $error['line'], 'logLine' => $error['line'],
@ -251,9 +227,7 @@ class Logger {
self::$logs[] = $LOG; self::$logs[] = $LOG;
if ($thisType == 'ERROR') if ($thisType == 'ERROR')
{
self::haltExecution($LOG); self::haltExecution($LOG);
}
} }
} }
@ -261,20 +235,19 @@ class Logger {
* System that redirects the errors to the appropriate logging method. * System that redirects the errors to the appropriate logging method.
* *
* @param int $type Error-type, Pre defined PHP Constant * @param int $type Error-type, Pre defined PHP Constant
* @param string error. The error itself * @param string $error . The error itself
* @param string File. The absolute path of the file * @param string|null $errFile . The absolute path of the file
* @param int Line. The line on which the error occured. * @param int|null $errLine . The line on which the error occurred.
* @param array context. Some of the error's relevant variables
*/ */
public static function errorHandler(int $type = E_USER_NOTICE, $error = 'Undefined Error', $errFile = null, $errLine = null) public static function errorHandler(int $type = E_USER_NOTICE, string $error = 'Undefined Error', string $errFile = null, int $errLine = null): void
{ {
// Check type // Check type
$thisType = self::getType($type); $thisType = self::getType($type);
$LOG = array('type' => (!is_null($thisType) ? $thisType : 'ERROR'), $LOG = array('type' => $thisType,
'message' => (!is_null($error) ? $error : ''), 'message' => (!is_null($error) ? $error : ''),
'logFile' => (!is_null($errFile) ? $errFile : ''), 'logFile' => (!is_null($errFile) ? $errFile : ''),
'logLine' => (!is_null($errLine) ? $errLine : ''), 'logLine' => (!is_null($errLine) ? $errLine : ''),
'runtime' => round(self::getRelativeTime(), 4),); 'runtime' => round(self::getRelativeTime(), 4));
self::$logs[] = $LOG; self::$logs[] = $LOG;
} }
@ -286,7 +259,7 @@ class Logger {
* @param Throwable $exception The occurred exception. * @param Throwable $exception The occurred exception.
* @param bool $haltExecution. Defaults to true * @param bool $haltExecution. Defaults to true
*/ */
public static function exceptionHandler(Throwable $exception, bool $haltExecution = true) public static function exceptionHandler(Throwable $exception, bool $haltExecution = true): void
{ {
$LOG = [ $LOG = [
'type' => $exception instanceof Exception ? "EXCEPTION" : "ERROR", 'type' => $exception instanceof Exception ? "EXCEPTION" : "ERROR",
@ -307,9 +280,9 @@ class Logger {
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* *
* @var string Name of the template file * @var string $templateName of the template file
*/ */
public static function setLoggerTemplate($templateName) public static function setLoggerTemplate(string $templateName): void
{ {
self::$logger_template = $templateName; self::$logger_template = $templateName;
} }
@ -319,7 +292,7 @@ class Logger {
* @codeCoverageIgnore * @codeCoverageIgnore
* @throws EventException * @throws EventException
*/ */
public static function logToScreen() public static function logToScreen(): void
{ {
// Send a screenLogEvent, allows for new screen log designs // Send a screenLogEvent, allows for new screen log designs
$event = Events::fireEvent('screenLogEvent'); $event = Events::fireEvent('screenLogEvent');
@ -335,7 +308,7 @@ class Logger {
* Output the entire log to a file. Used for debugging problems with your code. * Output the entire log to a file. Used for debugging problems with your code.
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function logLastRequest() public static function logLastRequest(): void
{ {
ob_start(function () {}); ob_start(function () {});
$logs = self::$logs; $logs = self::$logs;
@ -350,15 +323,14 @@ class Logger {
* Output all errors to a file. Used for tracking all errors in FuzeWorks and associated code * Output all errors to a file. Used for tracking all errors in FuzeWorks and associated code
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function logErrorsToFile() public static function logErrorsToFile(): void
{ {
ob_start(function() {}); ob_start(function() {});
$logs = []; $logs = [];
foreach (self::$logs as $log) foreach (self::$logs as $log)
{
if ($log['type'] === 'ERROR' || $log['type'] === 'EXCEPTION') if ($log['type'] === 'ERROR' || $log['type'] === 'EXCEPTION')
$logs[] = $log; $logs[] = $log;
}
require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.logger_file.php'); require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.logger_file.php');
$contents = ob_get_clean(); $contents = ob_get_clean();
$file = Core::$logDir . DS . 'fwlog_errors.log'; $file = Core::$logDir . DS . 'fwlog_errors.log';
@ -377,10 +349,10 @@ class Logger {
* @param string $name Marker name * @param string $name Marker name
* @return void * @return void
*/ */
public static function mark(string $name) public static function mark(string $name): void
{ {
$LOG = array('type' => 'BMARK', $LOG = array('type' => 'BMARK',
'message' => (!is_null($name) ? $name : ''), 'message' => $name,
'logFile' => '', 'logFile' => '',
'logLine' => '', 'logLine' => '',
'context' => '', 'context' => '',
@ -397,7 +369,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function log(string $msg, string $mod = null, string $file = null, int $line = null) public static function log(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
self::logInfo($msg, $mod, $file, $line); self::logInfo($msg, $mod, $file, $line);
} }
@ -410,7 +382,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function logInfo(string $msg, string $mod = null, string $file = null, int $line = null) public static function logInfo(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'INFO', $LOG = array('type' => 'INFO',
'message' => ($msg), 'message' => ($msg),
@ -430,7 +402,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function logDebug(string $msg, string $mod = null, string $file = null, int $line = null) public static function logDebug(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'DEBUG', $LOG = array('type' => 'DEBUG',
'message' => ($msg), 'message' => ($msg),
@ -450,7 +422,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function logError(string $msg, string $mod = null, string $file = null, int $line = null) public static function logError(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'ERROR', $LOG = array('type' => 'ERROR',
'message' => ($msg), 'message' => ($msg),
@ -470,7 +442,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function logWarning(string $msg, string $mod = null, string $file = null, int $line = null) public static function logWarning(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'WARNING', $LOG = array('type' => 'WARNING',
'message' => ($msg), 'message' => ($msg),
@ -490,7 +462,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function newLevel(string $msg, string $mod = null, string $file = null, int $line = null) public static function newLevel(string $msg, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'LEVEL_START', $LOG = array('type' => 'LEVEL_START',
'message' => ($msg), 'message' => ($msg),
@ -510,7 +482,7 @@ class Logger {
* @param string|null $file The file where the log occurred * @param string|null $file The file where the log occurred
* @param int|null $line The line where the log occurred * @param int|null $line The line where the log occurred
*/ */
public static function stopLevel(string $msg = null, string $mod = null, string $file = null, int $line = null) public static function stopLevel(string $msg = null, string $mod = null, string $file = null, int $line = null): void
{ {
$LOG = array('type' => 'LEVEL_STOP', $LOG = array('type' => 'LEVEL_STOP',
'message' => (!is_null($msg) ? $msg : ''), 'message' => (!is_null($msg) ? $msg : ''),
@ -534,27 +506,12 @@ class Logger {
*/ */
public static function getType(int $type): string public static function getType(int $type): string
{ {
switch ($type) { return match ($type) {
case E_PARSE: E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_STRICT, E_RECOVERABLE_ERROR, E_ERROR => 'ERROR',
case E_CORE_ERROR: E_NOTICE, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING, E_USER_NOTICE, E_USER_DEPRECATED, E_DEPRECATED, E_WARNING => 'WARNING',
case E_COMPILE_ERROR: default => 'Unknown error: ' . $type,
case E_USER_ERROR: };
case E_STRICT:
case E_RECOVERABLE_ERROR:
case E_ERROR:
return 'ERROR';
case E_NOTICE:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
case E_USER_NOTICE:
case E_USER_DEPRECATED:
case E_DEPRECATED:
case E_WARNING:
return 'WARNING';
}
return 'Unknown error: ' . $type;
} }
/** /**
@ -564,7 +521,7 @@ class Logger {
* @param array $log * @param array $log
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public static function haltExecution(array $log) public static function haltExecution(array $log): void
{ {
self::logError("Halting execution..."); self::logError("Halting execution...");
try { try {
@ -573,7 +530,7 @@ class Logger {
self::logError("Can't fire haltExecutionEvent: '".$e->getMessage()."'"); self::logError("Can't fire haltExecutionEvent: '".$e->getMessage()."'");
die(PHP_EOL . "FuzeWorks execution halted. See error log for more information"); die(PHP_EOL . "FuzeWorks execution halted. See error log for more information");
} }
if ($event->isCancelled() == true) if ($event->isCancelled())
return; return;
die(PHP_EOL . "FuzeWorks execution halted. See error log for more information"); die(PHP_EOL . "FuzeWorks execution halted. See error log for more information");

View File

@ -94,16 +94,16 @@ class Plugins
* @throws FactoryException * @throws FactoryException
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function init() public function init(): void
{ {
$this->cfg = Factory::getInstance()->config->getConfig('plugins'); $this->cfg = Factory::getInstance()->config->getConfig('plugins');
} }
/** /**
* Load the header files of all plugins. * Load the header files of all plugins.
*/ */
public function loadHeadersFromPluginPaths() public function loadHeadersFromPluginPaths(): void
{ {
// Cycle through all pluginPaths // Cycle through all pluginPaths
for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++)
{ {
@ -197,7 +197,7 @@ class Plugins
* @throws Exception\EventException * @throws Exception\EventException
* @throws PluginException * @throws PluginException
*/ */
public function get(string $pluginName, array $parameters = null) public function get(string $pluginName, array $parameters = null): mixed
{ {
if (empty($pluginName)) if (empty($pluginName))
throw new PluginException("Could not load plugin. No name provided", 1); throw new PluginException("Could not load plugin. No name provided", 1);
@ -237,7 +237,7 @@ class Plugins
$prefix = $header->getClassesPrefix(); $prefix = $header->getClassesPrefix();
$filePath = dirname($headerReflection->getFileName()) . (!empty($header->getSourceDirectory()) ? DS . $header->getSourceDirectory() : ''); $filePath = dirname($headerReflection->getFileName()) . (!empty($header->getSourceDirectory()) ? DS . $header->getSourceDirectory() : '');
$pluginClass = $header->getPluginClass(); $pluginClass = $header->getPluginClass();
if (!is_null($prefix) && !is_null($filePath)) if (!is_null($prefix))
{ {
try { try {
Core::addAutoloadMap($prefix, $filePath); Core::addAutoloadMap($prefix, $filePath);
@ -255,7 +255,7 @@ class Plugins
} }
// Attempt to load the plugin // Attempt to load the plugin
if (!class_exists($pluginClass, true)) if (!class_exists($pluginClass))
throw new PluginException("Could not load plugin. Class does not exist", 1); throw new PluginException("Could not load plugin. Class does not exist", 1);
$this->plugins[$pluginName] = new $pluginClass($parameters); $this->plugins[$pluginName] = new $pluginClass($parameters);

View File

@ -64,28 +64,21 @@ abstract class Priority
/** /**
* Returns the string of the priority based on the integer. * Returns the string of the priority based on the integer.
* *
* @param $intPriorty * @param int $priority
* *
* @return bool|string A bool when the integer isn't a priority. If the integer is a priority, the name is returned * @return bool|string A bool when the integer isn't a priority. If the integer is a priority, the name is returned
*/ */
public static function getPriority($intPriorty) public static function getPriority(int $priority): bool|string
{ {
switch ($intPriorty) { return match ($priority) {
case 5: 5 => 'Priority::LOWEST',
return 'Priority::LOWEST'; 4 => 'Priority::LOW',
case 4: 3 => 'Priority::NORMAL',
return 'Priority::LOW'; 2 => 'Priority::HIGH',
case 3: 1 => 'Priority::HIGHEST',
return 'Priority::NORMAL'; 0 => 'Priority::MONITOR',
case 2: default => false,
return 'Priority::HIGH'; };
case 1:
return 'Priority::HIGHEST';
case 0:
return 'Priority::MONITOR';
default:
return false;
}
} }
/** /**

View File

@ -38,7 +38,7 @@ $mask = "|%5s |%5s |%-90s |\n";
$id = 1; $id = 1;
if (!empty($logs)) if (!empty($logs))
printf($mask, $id, 'REQUEST', ' ' . date('Y-m-d H:i') . '-'.substr(sha1(uniqid()), 0, 8).''); printf($mask, $id, 'REQUEST', ' ' . date('Y-m-d H:i') . '-'.substr(sha1(uniqid()), 0, 8));
foreach ($logs as $log) { foreach ($logs as $log) {
$id++; $id++;

View File

@ -401,7 +401,7 @@ class configuratorTest extends CoreTestAbstract
$this->assertTrue($this->configurator->isDebugMode()); $this->assertTrue($this->configurator->isDebugMode());
// Set a debug address, all in this case; also verify return type // Set a debug address, all in this case; also verify return type
$this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator->setDebugAddress('NONE')); $this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator->setDebugAddress());
// No match should be found. Verify that debug has been deactivated // No match should be found. Verify that debug has been deactivated
$this->assertFalse($this->configurator->isDebugMode()); $this->assertFalse($this->configurator->isDebugMode());
@ -470,16 +470,6 @@ class configuratorTest extends CoreTestAbstract
// Unset // Unset
unset($_COOKIE[Configurator::COOKIE_SECRET], $_SERVER['REMOTE_ADDR']); unset($_COOKIE[Configurator::COOKIE_SECRET], $_SERVER['REMOTE_ADDR']);
} }
/**
* @depends testEnableDebugMode
* @covers ::setDebugAddress
*/
public function testSetDebugAddressInvalidArgument()
{
$this->expectException(\FuzeWorks\Exception\InvalidArgumentException::class);
$this->configurator->setDebugAddress(null);
}
} }
class MockComponent implements iComponent class MockComponent implements iComponent
@ -492,6 +482,7 @@ class MockComponent implements iComponent
public function getClasses(): array public function getClasses(): array
{ {
return [];
} }
public function onAddComponent(Configurator $configurator): Configurator public function onAddComponent(Configurator $configurator): Configurator

View File

@ -174,10 +174,10 @@ class eventsTest extends CoreTestAbstract
// First add the listener, expect it to be never called // First add the listener, expect it to be never called
$listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock(); $listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$listener->expects($this->never())->method('mockListener'); $listener->expects($this->never())->method('mockListener');
Events::addListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); Events::addListener(array($listener, 'mockListener'), 'mockEvent');
// Now try and remove it // Now try and remove it
Events::removeListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); Events::removeListener(array($listener, 'mockListener'), 'mockEvent');
// And now fire the event // And now fire the event
Events::fireEvent('mockEvent'); Events::fireEvent('mockEvent');
@ -219,7 +219,7 @@ class eventsTest extends CoreTestAbstract
*/ */
public function testRemoveUnsetEventListener() public function testRemoveUnsetEventListener()
{ {
$this->assertNull(Events::removeListener(function($event){}, 'emptyListenerArray', Priority::NORMAL)); $this->assertNull(Events::removeListener(function($event){}, 'emptyListenerArray'));
} }
/** /**
@ -229,7 +229,7 @@ class eventsTest extends CoreTestAbstract
public function testRemoveUnsetListener() public function testRemoveUnsetListener()
{ {
Events::addListener(function($e) {}, 'mockEvent', Priority::NORMAL); Events::addListener(function($e) {}, 'mockEvent', Priority::NORMAL);
$this->assertNull(Events::removeListener(function() {echo "Called"; }, 'mockEvent', Priority::NORMAL)); $this->assertNull(Events::removeListener(function() {echo "Called"; }, 'mockEvent'));
} }
/** /**
@ -298,8 +298,8 @@ class eventsTest extends CoreTestAbstract
class Observer class Observer
{ {
public function mockMethod() {} public function mockMethod(): void {}
public function mockListener($event) {} public function mockListener($event): void {}
} }
class MockEvent extends Event class MockEvent extends Event

View File

@ -36,6 +36,7 @@
use FuzeWorks\Exception\LibraryException; use FuzeWorks\Exception\LibraryException;
use FuzeWorks\Factory; use FuzeWorks\Factory;
use FuzeWorks\iLibrary;
use FuzeWorks\Libraries; use FuzeWorks\Libraries;
/** /**
@ -167,10 +168,10 @@ class libraryTest extends CoreTestAbstract
*/ */
public function testAddLibraryObject() public function testAddLibraryObject()
{ {
$z = new stdClass(); $lib = $this->getMockForAbstractClass(iLibrary::class);
$this->libraries->addLibraryObject('TestAddLibraryObject', $z); $this->libraries->addLibraryObject('TestAddLibraryObject', $lib);
$this->assertEquals($z, $this->libraries->get('TestAddLibraryObject')); $this->assertEquals($lib, $this->libraries->get('TestAddLibraryObject'));
} }
/** /**
@ -203,13 +204,13 @@ class libraryTest extends CoreTestAbstract
public function testAddLibraryWithAutoloader() public function testAddLibraryWithAutoloader()
{ {
// First assert the extra class can't be autoloaded // First assert the extra class can't be autoloaded
$this->assertFalse(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass', true)); $this->assertFalse(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass'));
// Load the library and test the instance type // Load the library and test the instance type
$this->assertInstanceOf('Application\Library\TestAddLibraryWithAutoloader', $this->libraries->get('TestAddLibraryWithAutoloader')); $this->assertInstanceOf('Application\Library\TestAddLibraryWithAutoloader', $this->libraries->get('TestAddLibraryWithAutoloader'));
// Afterwards test if the loader has been correctly added // Afterwards test if the loader has been correctly added
$this->assertTrue(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass', true)); $this->assertTrue(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass'));
} }
/** /**

View File

@ -57,5 +57,5 @@ class coreStartEventTest extends CoreTestAbstract
} }
class MockStartEvent { class MockStartEvent {
public function mockMethod() {} public function mockMethod(): void {}
} }

View File

@ -38,7 +38,7 @@ use FuzeWorks\iLibrary;
class TestGetLibraryParametersFromConfig implements iLibrary { class TestGetLibraryParametersFromConfig implements iLibrary {
public $parameters; public mixed $parameters;
public function __construct($parameters) public function __construct($parameters)
{ {

View File

@ -58,7 +58,7 @@ class TestLoadHeaderNotIPluginHeaderHeader
return '\FuzeWorks\UnitTest\Plugins\TestLoadHeaderNotIPluginHeader\TestLoadPlugin'; return '\FuzeWorks\UnitTest\Plugins\TestLoadHeaderNotIPluginHeader\TestLoadPlugin';
} }
public function init() public function init(): void
{ {
} }
} }