phpstan fixes
This commit is contained in:
@@ -78,16 +78,18 @@ if (isset($_SESSION)) {
|
|||||||
#
|
#
|
||||||
print "[UNSET] To set session name valid: "
|
print "[UNSET] To set session name valid: "
|
||||||
. ($session->checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
|
. ($session->checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[SET] Current session id: " . $session_id . "<br>";
|
print "[SET] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[FAILED] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
// set again
|
// set again
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[2 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[2 SET] Current session id: " . $session_id . "<br>";
|
print "[2 SET] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[2 FAILED] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
||||||
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
||||||
@@ -125,10 +127,11 @@ print "[READ MAGIC] unset Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') .
|
|||||||
|
|
||||||
// differnt session name
|
// differnt session name
|
||||||
$session_name = 'class-test-session-ALT';
|
$session_name = 'class-test-session-ALT';
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[3 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[3 SET] Current session id: " . $session_id . "<br>";
|
print "[3 SET] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[3 FAILED] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
print "[SET AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
print "[SET AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
||||||
|
|
||||||
@@ -141,10 +144,11 @@ $_SESSION['will_never_be_written'] = 'empty';
|
|||||||
|
|
||||||
// open again
|
// open again
|
||||||
$session_name = 'class-test-session';
|
$session_name = 'class-test-session';
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[4 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[4 SET] Current session id: " . $session_id . "<br>";
|
print "[4 SET] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[4 FAILED] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
print "[START AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
print "[START AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
||||||
$_SESSION['will_be_written_again'] = 'Full';
|
$_SESSION['will_be_written_again'] = 'Full';
|
||||||
@@ -153,10 +157,11 @@ $_SESSION['will_be_written_again'] = 'Full';
|
|||||||
$session->writeClose();
|
$session->writeClose();
|
||||||
// invalid
|
// invalid
|
||||||
$session_name = '123';
|
$session_name = '123';
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[5 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[5 SET] Current session id: " . $session_id . "<br>";
|
print "[5 SET] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[5 FAILED] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
print "[BAD NAME] Current session id: " . $session->getSessionId() . "<br>";
|
print "[BAD NAME] Current session id: " . $session->getSessionId() . "<br>";
|
||||||
print "[BAD NAME] Current session name: " . $session->getSessionName() . "<br>";
|
print "[BAD NAME] Current session name: " . $session->getSessionName() . "<br>";
|
||||||
|
|||||||
@@ -69,16 +69,18 @@ print "[UNSET] Current session status: " . getSessionStatusString($session->getS
|
|||||||
|
|
||||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||||
// start
|
// start
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "Session start failed: " . $session->getErrorStr() . "<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
print "[1] Current session id: " . $session_id . "<br>";
|
||||||
print "Current session id: " . $session_id . "<br>";
|
} catch (\Exception $e) {
|
||||||
|
print "[1] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
// set again
|
// set again
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
try {
|
||||||
print "[2] Session start failed<br>";
|
$session_id = $session->startSession($session_name);
|
||||||
} else {
|
|
||||||
print "[2] Current session id: " . $session_id . "<br>";
|
print "[2] Current session id: " . $session_id . "<br>";
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
print "[2] Session start failed:<br>" . $e->getMessage() . "<br>" . $e . "<br>";
|
||||||
}
|
}
|
||||||
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
||||||
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ class DateTime
|
|||||||
* @return int int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
* @return int int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
* @throws \UnexpectedValueException On empty start/end values
|
* @throws \UnexpectedValueException On empty start/end values
|
||||||
*/
|
*/
|
||||||
public static function compareDate(string $start_date, string $end_date): int|bool
|
public static function compareDate(string $start_date, string $end_date): int
|
||||||
{
|
{
|
||||||
// pre check for empty or wrong
|
// pre check for empty or wrong
|
||||||
if ($start_date == '--' || $end_date == '--' || empty($start_date) || empty($end_date)) {
|
if ($start_date == '--' || $end_date == '--' || empty($start_date) || empty($end_date)) {
|
||||||
@@ -337,18 +337,20 @@ class DateTime
|
|||||||
if (($end_timestamp = strtotime($end_date)) === false) {
|
if (($end_timestamp = strtotime($end_date)) === false) {
|
||||||
throw new \UnexpectedValueException("Error parsing end date through strtotime()");
|
throw new \UnexpectedValueException("Error parsing end date through strtotime()");
|
||||||
}
|
}
|
||||||
|
$comp = 0;
|
||||||
// convert anything to Y-m-d and then to timestamp
|
// convert anything to Y-m-d and then to timestamp
|
||||||
// this is to remove any time parts
|
// this is to remove any time parts
|
||||||
$start_timestamp = strtotime(date('Y-m-d', $start_timestamp));
|
$start_timestamp = strtotime(date('Y-m-d', $start_timestamp));
|
||||||
$end_timestamp = strtotime(date('Y-m-d', $end_timestamp));
|
$end_timestamp = strtotime(date('Y-m-d', $end_timestamp));
|
||||||
// compare, or end with false
|
// compare, or end with false
|
||||||
if ($start_timestamp < $end_timestamp) {
|
if ($start_timestamp < $end_timestamp) {
|
||||||
return -1;
|
$comp = -1;
|
||||||
} elseif ($start_timestamp == $end_timestamp) {
|
} elseif ($start_timestamp == $end_timestamp) {
|
||||||
return 0;
|
$comp = 0;
|
||||||
} elseif ($start_timestamp > $end_timestamp) {
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
return 1;
|
$comp = 1;
|
||||||
}
|
}
|
||||||
|
return $comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,7 +367,7 @@ class DateTime
|
|||||||
* @return int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
* @return int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
* @throws \UnexpectedValueException On empty start/end values
|
* @throws \UnexpectedValueException On empty start/end values
|
||||||
*/
|
*/
|
||||||
public static function compareDateTime(string $start_datetime, string $end_datetime): int|bool
|
public static function compareDateTime(string $start_datetime, string $end_datetime): int
|
||||||
{
|
{
|
||||||
// pre check for empty or wrong
|
// pre check for empty or wrong
|
||||||
if ($start_datetime == '--' || $end_datetime == '--' || empty($start_datetime) || empty($end_datetime)) {
|
if ($start_datetime == '--' || $end_datetime == '--' || empty($start_datetime) || empty($end_datetime)) {
|
||||||
@@ -378,14 +380,16 @@ class DateTime
|
|||||||
if (($end_timestamp = strtotime($end_datetime)) === false) {
|
if (($end_timestamp = strtotime($end_datetime)) === false) {
|
||||||
throw new \UnexpectedValueException("Error parsing end timestamp through strtotime()");
|
throw new \UnexpectedValueException("Error parsing end timestamp through strtotime()");
|
||||||
}
|
}
|
||||||
|
$comp = 0;
|
||||||
// compare, or return false
|
// compare, or return false
|
||||||
if ($start_timestamp < $end_timestamp) {
|
if ($start_timestamp < $end_timestamp) {
|
||||||
return -1;
|
$comp = -1;
|
||||||
} elseif ($start_timestamp == $end_timestamp) {
|
} elseif ($start_timestamp == $end_timestamp) {
|
||||||
return 0;
|
$comp = 0;
|
||||||
} elseif ($start_timestamp > $end_timestamp) {
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
return 1;
|
$comp = 1;
|
||||||
}
|
}
|
||||||
|
return $comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -292,12 +292,18 @@ class Image
|
|||||||
// image, copy source image, offset in image, source x/y, new size, source image size
|
// image, copy source image, offset in image, source x/y, new size, source image size
|
||||||
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
|
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
|
||||||
if ($thumb === false) {
|
if ($thumb === false) {
|
||||||
return false;
|
throw new \RuntimeException(
|
||||||
|
'imagecreatetruecolor failed: ' . $thumbnail . ', ' . $filename,
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ($img_type == IMAGETYPE_PNG) {
|
if ($img_type == IMAGETYPE_PNG) {
|
||||||
$imagecolorallocatealpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
|
$imagecolorallocatealpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
|
||||||
if ($imagecolorallocatealpha === false) {
|
if ($imagecolorallocatealpha === false) {
|
||||||
return false;
|
throw new \RuntimeException(
|
||||||
|
'imagecolorallocatealpha failed: ' . $thumbnail . ', ' . $filename,
|
||||||
|
2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// preservere transaprency
|
// preservere transaprency
|
||||||
imagecolortransparent(
|
imagecolortransparent(
|
||||||
@@ -359,8 +365,10 @@ class Image
|
|||||||
imagedestroy($source);
|
imagedestroy($source);
|
||||||
imagedestroy($thumb);
|
imagedestroy($thumb);
|
||||||
} else {
|
} else {
|
||||||
$exception_message = 'Invalid source image file. Only JPEG/PNG are allowed: ' . $filename;
|
throw new \RuntimeException(
|
||||||
$thumbnail = false;
|
'Invalid source image file. Only JPEG/PNG are allowed: ' . $filename,
|
||||||
|
3
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -401,14 +409,20 @@ class Image
|
|||||||
}
|
}
|
||||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||||
if ($thumb === false) {
|
if ($thumb === false) {
|
||||||
return false;
|
throw new \RuntimeException(
|
||||||
|
'imagecreatetruecolor dummy failed: ' . $thumbnail . ', ' . $filename,
|
||||||
|
3
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// add outside border px = 5% (rounded up)
|
// add outside border px = 5% (rounded up)
|
||||||
// eg 50px -> 2.5px
|
// eg 50px -> 2.5px
|
||||||
$gray = imagecolorallocate($thumb, 200, 200, 200);
|
$gray = imagecolorallocate($thumb, 200, 200, 200);
|
||||||
$white = imagecolorallocate($thumb, 255, 255, 255);
|
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||||
if ($gray === false || $white === false) {
|
if ($gray === false || $white === false) {
|
||||||
return false;
|
throw new \RuntimeException(
|
||||||
|
'imagecolorallocate/imagecolorallocate dummy failed: ' . $thumbnail . ', ' . $filename,
|
||||||
|
2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// fill gray background
|
// fill gray background
|
||||||
imagefill($thumb, 0, 0, $gray);
|
imagefill($thumb, 0, 0, $gray);
|
||||||
|
|||||||
Reference in New Issue
Block a user