mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-12 14:31:35 +00:00
Fixed potential bugs
This commit is contained in:
parent
a6ef9a58ec
commit
3431320d03
4 changed files with 8 additions and 5 deletions
|
|
@ -156,8 +156,8 @@ class AttachmentManager
|
|||
//Taken from: https://www.php.net/manual/de/function.filesize.php#106569 and slightly modified
|
||||
|
||||
$sz = 'BKMGTP';
|
||||
$factor = (int) floor((strlen((string) $bytes) - 1) / 3);
|
||||
$factor = min((int) floor((strlen((string) $bytes) - 1) / 3), strlen($sz) - 1);
|
||||
//Use real (10 based) SI prefixes
|
||||
return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).@$sz[$factor];
|
||||
return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).$sz[$factor];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ class SIFormatter
|
|||
$prefixes_neg = ['', 'm', 'μ', 'n', 'p', 'f', 'a', 'z', 'y'];
|
||||
|
||||
if ($magnitude >= 0) {
|
||||
$nearest = (int) floor(abs($magnitude) / 3);
|
||||
$nearest = min((int) floor(abs($magnitude) / 3), count($prefixes_pos) - 1);
|
||||
$symbol = $prefixes_pos[$nearest];
|
||||
} else {
|
||||
$nearest = (int) round(abs($magnitude) / 3);
|
||||
$nearest = min((int) round(abs($magnitude) / 3), count($prefixes_neg) - 1);
|
||||
$symbol = $prefixes_neg[$nearest];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ trait PKImportHelperTrait
|
|||
//Use mime type to determine the extension like PartKeepr does in legacy implementation (just use the second part of the mime type)
|
||||
//See UploadedFile.php:291 in PartKeepr (https://github.com/partkeepr/PartKeepr/blob/f6176c3354b24fa39ac8bc4328ee0df91de3d5b6/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php#L291)
|
||||
if (!empty ($attachment_row['mimetype'])) {
|
||||
$attachment_row['extension'] = explode('/', (string) $attachment_row['mimetype'])[1];
|
||||
$attachment_row['extension'] = explode('/', (string) $attachment_row['mimetype'])[1] ?? '';
|
||||
} else {
|
||||
//If the mime type is empty, we use the original extension
|
||||
$attachment_row['extension'] = pathinfo((string) $attachment_row['originalname'], PATHINFO_EXTENSION);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ final readonly class GitVersionInfoProvider
|
|||
{
|
||||
if (is_file($this->getGitDirectory() . '/HEAD')) {
|
||||
$git = file($this->getGitDirectory() . '/HEAD');
|
||||
if ($git === false) {
|
||||
return null;
|
||||
}
|
||||
$head = explode('/', $git[0], 3);
|
||||
|
||||
if (!isset($head[2])) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue