Make explicit comparisons

pull/567/head
fadrian06 10 months ago
parent 99a7d75440
commit 8f3f6b5c74

@ -24,8 +24,7 @@
], ],
"require": { "require": {
"php": "^7.4|^8.0|^8.1|^8.2|^8.3", "php": "^7.4|^8.0|^8.1|^8.2|^8.3",
"ext-json": "*", "ext-json": "*"
"symfony/polyfill-php80": "^1.29"
}, },
"autoload": { "autoload": {
"files": [ "files": [

@ -277,8 +277,8 @@ class Dispatcher
public function execute($callback, array &$params = []) public function execute($callback, array &$params = [])
{ {
if ( if (
is_string($callback) is_string($callback) === true
&& (str_contains($callback, '->') || str_contains($callback, '::')) && (strpos($callback, '->') !== false || strpos($callback, '::') !== false)
) { ) {
$callback = $this->parseStringClassAndMethod($callback); $callback = $this->parseStringClassAndMethod($callback);
} }
@ -347,7 +347,7 @@ class Dispatcher
public function invokeCallable($func, array &$params = []) public function invokeCallable($func, array &$params = [])
{ {
// If this is a directly callable function, call it // If this is a directly callable function, call it
if (!is_array($func)) { if (is_array($func) === false) {
$this->verifyValidFunction($func); $this->verifyValidFunction($func);
return call_user_func_array($func, $params); return call_user_func_array($func, $params);
@ -355,12 +355,12 @@ class Dispatcher
[$class, $method] = $func; [$class, $method] = $func;
$mustUseTheContainer = $this->containerHandler && ( $mustUseTheContainer = $this->containerHandler !== null && (
(is_object($class) && !str_starts_with(get_class($class), 'flight\\')) (is_object($class) === true && strpos(get_class($class), 'flight\\') === false)
|| is_string($class) || is_string($class)
); );
if ($mustUseTheContainer) { if ($mustUseTheContainer === true) {
$resolvedClass = $this->resolveContainerClass($class, $params); $resolvedClass = $this->resolveContainerClass($class, $params);
if ($resolvedClass) { if ($resolvedClass) {
@ -408,20 +408,20 @@ class Dispatcher
$exception = null; $exception = null;
// Final check to make sure it's actually a class and a method, or throw an error // Final check to make sure it's actually a class and a method, or throw an error
if (!is_object($class) && !class_exists($class)) { if (is_object($class) === false && class_exists($class) === false) {
$exception = new Exception("Class '$class' not found. Is it being correctly autoloaded with Flight::path()?"); $exception = new Exception("Class '$class' not found. Is it being correctly autoloaded with Flight::path()?");
// If this tried to resolve a class in a container and failed somehow, throw the exception // If this tried to resolve a class in a container and failed somehow, throw the exception
} elseif (!$resolvedClass && $this->containerException) { } elseif (!$resolvedClass && $this->containerException !== null) {
$exception = $this->containerException; $exception = $this->containerException;
// Class is there, but no method // Class is there, but no method
} elseif (is_object($class) && !method_exists($class, $method)) { } elseif (is_object($class) === true && method_exists($class, $method) === false) {
$classNamespace = get_class($class); $classNamespace = get_class($class);
$exception = new Exception("Class found, but method '$classNamespace::$method' not found."); $exception = new Exception("Class found, but method '$classNamespace::$method' not found.");
} }
if ($exception) { if ($exception !== null) {
$this->fixOutputBuffering(); $this->fixOutputBuffering();
throw $exception; throw $exception;

Loading…
Cancel
Save