diff --git a/composer.json b/composer.json index d8d1b8b..02c6f3d 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,9 @@ "flashwave/index": "dev-master", "flashwave/syokuhou": "dev-master" }, + "require-dev": { + "phpstan/phpstan": "^1.10" + }, "autoload": { "psr-4": { "EEPROM\\": "src" diff --git a/composer.lock b/composer.lock index 7d04793..278b312 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d909826a501788db19148054e389ec5f", + "content-hash": "973c3ff84696d18c37f24ebc2f89d068", "packages": [ { "name": "flashwave/index", @@ -92,7 +92,70 @@ "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": [], "minimum-stability": "dev", "stability-flags": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b10eea8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 5 + paths: + - src + bootstrapFiles: + - eeprom.php diff --git a/src/Auth/NabuccoAuth.php b/src/Auth/NabuccoAuth.php index 51029c3..03abcd8 100644 --- a/src/Auth/NabuccoAuth.php +++ b/src/Auth/NabuccoAuth.php @@ -2,7 +2,7 @@ namespace EEPROM\Auth; use EEPROM\Config; -use Index\Serialisation\Serialiser; +use Index\Serialisation\UriBase64; class NabuccoAuth implements IAuth { private $secretKey = ''; @@ -22,7 +22,7 @@ class NabuccoAuth implements IAuth { if($length < 32 || $length > 100) return -1; $userHash = substr($token, 0, 32); - $packed = Serialiser::uriBase64()->deserialise(substr($token, 32)); + $packed = UriBase64::decode(substr($token, 32)); $realHash = $this->hashToken($packed); if(!hash_equals($realHash, $userHash)) return -1; @@ -30,6 +30,6 @@ class NabuccoAuth implements IAuth { if(empty($unpacked['userId']) || empty($unpacked['time']) || $unpacked['time'] < strtotime('-1 month')) return -1; - return intval($unpacked['userId'] ?? -1); + return intval($unpacked['userId']); } } diff --git a/src/Upload.php b/src/Upload.php index d66a9a8..6430251 100644 --- a/src/Upload.php +++ b/src/Upload.php @@ -115,7 +115,7 @@ final class Upload implements JsonSerializable { return $this->deleted; } public function isDeleted(): bool { - return $this->deleted; + return $this->deleted > 0; } public function getDMCA(): int { @@ -129,6 +129,10 @@ final class Upload implements JsonSerializable { return $this->bump; } + public function getRemoteAddress(): string { + return $this->ipAddress; + } + public function bumpExpiry(IDbConnection $conn): void { if(empty($this->id) || $this->expires < 1) return; @@ -144,7 +148,7 @@ final class Upload implements JsonSerializable { } 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->addParameter(1, $this->id, DbType::STRING); @@ -152,7 +156,7 @@ final class Upload implements JsonSerializable { } public function delete(IDbConnection $conn, bool $hard): void { - $this->upload_deleted = time(); + $this->deleted = time(); if($hard) { if(is_file($this->getPath())) @@ -378,13 +382,16 @@ final class Upload implements JsonSerializable { $height = $imagick->getImageHeight(); if ($width > $height) { - $resizeWidth = ceil($width * $thumbRes / $height); + $resizeWidth = $width * $thumbRes / $height; $resizeHeight = $thumbRes; } else { $resizeWidth = $thumbRes; - $resizeHeight = ceil($height * $thumbRes / $width); + $resizeHeight = $height * $thumbRes / $width; } + $resizeWidth = (int)$resizeWidth; + $resizeHeight = (int)$resizeHeight; + $imagick->resizeImage( $resizeWidth, $resizeHeight, Imagick::FILTER_GAUSSIAN, 0.7 @@ -393,8 +400,8 @@ final class Upload implements JsonSerializable { $imagick->cropImage( $thumbRes, $thumbRes, - ceil(($resizeWidth - $thumbRes) / 2), - ceil(($resizeHeight - $thumbRes) / 2) + (int)ceil(($resizeWidth - $thumbRes) / 2), + (int)ceil(($resizeHeight - $thumbRes) / 2) ); $imagick->writeImage($this->getThumbPath()); diff --git a/src/User.php b/src/User.php index 05a14dc..2408c21 100644 --- a/src/User.php +++ b/src/User.php @@ -81,7 +81,7 @@ class User implements JsonSerializable { if(!$result->next()) throw new UserNotFoundException; - return new static( + return new User( $result->getInteger(0), $result->getInteger(1), $result->getInteger(2),