Fixed static analysis detections.

This commit is contained in:
flash 2023-10-31 15:30:22 +00:00
parent ef12a7b0d4
commit f4c3d34b70
6 changed files with 92 additions and 13 deletions

View file

@ -5,6 +5,9 @@
"flashwave/index": "dev-master", "flashwave/index": "dev-master",
"flashwave/syokuhou": "dev-master" "flashwave/syokuhou": "dev-master"
}, },
"require-dev": {
"phpstan/phpstan": "^1.10"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"EEPROM\\": "src" "EEPROM\\": "src"

67
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d909826a501788db19148054e389ec5f", "content-hash": "973c3ff84696d18c37f24ebc2f89d068",
"packages": [ "packages": [
{ {
"name": "flashwave/index", "name": "flashwave/index",
@ -92,7 +92,70 @@
"time": "2023-10-20T21:26:38+00:00" "time": "2023-10-20T21:26:38+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [
{
"name": "phpstan/phpstan",
"version": "1.10.40",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d",
"reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"keywords": [
"dev",
"static analysis"
],
"support": {
"docs": "https://phpstan.org/user-guide/getting-started",
"forum": "https://github.com/phpstan/phpstan/discussions",
"issues": "https://github.com/phpstan/phpstan/issues",
"security": "https://github.com/phpstan/phpstan/security/policy",
"source": "https://github.com/phpstan/phpstan-src"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2023-10-30T14:48:31+00:00"
}
],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {

6
phpstan.neon Normal file
View file

@ -0,0 +1,6 @@
parameters:
level: 5
paths:
- src
bootstrapFiles:
- eeprom.php

View file

@ -2,7 +2,7 @@
namespace EEPROM\Auth; namespace EEPROM\Auth;
use EEPROM\Config; use EEPROM\Config;
use Index\Serialisation\Serialiser; use Index\Serialisation\UriBase64;
class NabuccoAuth implements IAuth { class NabuccoAuth implements IAuth {
private $secretKey = ''; private $secretKey = '';
@ -22,7 +22,7 @@ class NabuccoAuth implements IAuth {
if($length < 32 || $length > 100) if($length < 32 || $length > 100)
return -1; return -1;
$userHash = substr($token, 0, 32); $userHash = substr($token, 0, 32);
$packed = Serialiser::uriBase64()->deserialise(substr($token, 32)); $packed = UriBase64::decode(substr($token, 32));
$realHash = $this->hashToken($packed); $realHash = $this->hashToken($packed);
if(!hash_equals($realHash, $userHash)) if(!hash_equals($realHash, $userHash))
return -1; return -1;
@ -30,6 +30,6 @@ class NabuccoAuth implements IAuth {
if(empty($unpacked['userId']) || empty($unpacked['time']) if(empty($unpacked['userId']) || empty($unpacked['time'])
|| $unpacked['time'] < strtotime('-1 month')) || $unpacked['time'] < strtotime('-1 month'))
return -1; return -1;
return intval($unpacked['userId'] ?? -1); return intval($unpacked['userId']);
} }
} }

View file

@ -115,7 +115,7 @@ final class Upload implements JsonSerializable {
return $this->deleted; return $this->deleted;
} }
public function isDeleted(): bool { public function isDeleted(): bool {
return $this->deleted; return $this->deleted > 0;
} }
public function getDMCA(): int { public function getDMCA(): int {
@ -129,6 +129,10 @@ final class Upload implements JsonSerializable {
return $this->bump; return $this->bump;
} }
public function getRemoteAddress(): string {
return $this->ipAddress;
}
public function bumpExpiry(IDbConnection $conn): void { public function bumpExpiry(IDbConnection $conn): void {
if(empty($this->id) || $this->expires < 1) if(empty($this->id) || $this->expires < 1)
return; return;
@ -144,7 +148,7 @@ final class Upload implements JsonSerializable {
} }
public function restore(IDbConnection $conn): void { public function restore(IDbConnection $conn): void {
$this->upload_deleted = null; $this->deleted = 0;
$restore = $conn->prepare('UPDATE `prm_uploads` SET `upload_deleted` = NULL WHERE `upload_id` = ?'); $restore = $conn->prepare('UPDATE `prm_uploads` SET `upload_deleted` = NULL WHERE `upload_id` = ?');
$restore->addParameter(1, $this->id, DbType::STRING); $restore->addParameter(1, $this->id, DbType::STRING);
@ -152,7 +156,7 @@ final class Upload implements JsonSerializable {
} }
public function delete(IDbConnection $conn, bool $hard): void { public function delete(IDbConnection $conn, bool $hard): void {
$this->upload_deleted = time(); $this->deleted = time();
if($hard) { if($hard) {
if(is_file($this->getPath())) if(is_file($this->getPath()))
@ -378,13 +382,16 @@ final class Upload implements JsonSerializable {
$height = $imagick->getImageHeight(); $height = $imagick->getImageHeight();
if ($width > $height) { if ($width > $height) {
$resizeWidth = ceil($width * $thumbRes / $height); $resizeWidth = $width * $thumbRes / $height;
$resizeHeight = $thumbRes; $resizeHeight = $thumbRes;
} else { } else {
$resizeWidth = $thumbRes; $resizeWidth = $thumbRes;
$resizeHeight = ceil($height * $thumbRes / $width); $resizeHeight = $height * $thumbRes / $width;
} }
$resizeWidth = (int)$resizeWidth;
$resizeHeight = (int)$resizeHeight;
$imagick->resizeImage( $imagick->resizeImage(
$resizeWidth, $resizeHeight, $resizeWidth, $resizeHeight,
Imagick::FILTER_GAUSSIAN, 0.7 Imagick::FILTER_GAUSSIAN, 0.7
@ -393,8 +400,8 @@ final class Upload implements JsonSerializable {
$imagick->cropImage( $imagick->cropImage(
$thumbRes, $thumbRes,
$thumbRes, $thumbRes,
ceil(($resizeWidth - $thumbRes) / 2), (int)ceil(($resizeWidth - $thumbRes) / 2),
ceil(($resizeHeight - $thumbRes) / 2) (int)ceil(($resizeHeight - $thumbRes) / 2)
); );
$imagick->writeImage($this->getThumbPath()); $imagick->writeImage($this->getThumbPath());

View file

@ -81,7 +81,7 @@ class User implements JsonSerializable {
if(!$result->next()) if(!$result->next())
throw new UserNotFoundException; throw new UserNotFoundException;
return new static( return new User(
$result->getInteger(0), $result->getInteger(0),
$result->getInteger(1), $result->getInteger(1),
$result->getInteger(2), $result->getInteger(2),