Skip to content

Commit

Permalink
Fix PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
toby7002 committed Oct 1, 2023
1 parent ce5225e commit 1ee16c4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
6 changes: 0 additions & 6 deletions phpstan-baseline.neon

This file was deleted.

4 changes: 1 addition & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
parameters:
level: 9
paths:
- src
includes:
- phpstan-baseline.neon
- src
4 changes: 2 additions & 2 deletions src/thebigcrafter/omp/OhMyPMMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace thebigcrafter\omp;

use pocketmine\lang\Language;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\SingletonTrait;
use thebigcrafter\Fluorine\Fluorine;
Expand Down Expand Up @@ -40,6 +39,7 @@ public function onEnable(): void
public function loadLanguage(): void
{
$langFolder = Path::join($this->getDataFolder(), "lang");
/** @var string $selectedLanguage */
$selectedLanguage = $this->getConfig()->get("lang");
$selectedLanguagePath = Path::join($this->getDataFolder(), "lang", "$selectedLanguage.json");

Expand All @@ -58,7 +58,7 @@ public function loadLanguage(): void
$this->language = new OMPLanguage($selectedLanguage);
}

public function getLanguage() {
public function getLanguage(): OMPLanguage {
return $this->language;
}
}
16 changes: 8 additions & 8 deletions src/thebigcrafter/omp/lang/OMPLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class OMPLanguage
/** @var array<string, string> $languages */
private static array $languages;

private $default;
private string $default;

public static function loadLanguageFile(string $name, string $path)
public static function loadLanguageFile(string $name, string $path): void
{
if (!file_exists($path)) {
throw new Exception('File not found.');
}

self::$languages[$name] = json_decode(\thebigcrafter\omp\utils\Filesystem::readFile($path)->await() ?: '', true);
self::$languages[$name] = json_decode(\thebigcrafter\omp\utils\Filesystem::readFile($path)->await() ?: '', true); /** @phpstan-ignore-line */
}

public function __construct(string $default)
Expand All @@ -32,7 +32,7 @@ public function __construct(string $default)
$this->default = $default;
}

public function setDefaultLanguage(string $name)
public function setDefaultLanguage(string $name): void
{
if (!array_key_exists($name, self::$languages)) {
throw new Exception('Language not found');
Expand All @@ -41,12 +41,12 @@ public function setDefaultLanguage(string $name)
$this->default = $name;
}

public function get(string $key)
public function get(string $key): string
{
if (!array_key_exists($key, self::$languages[$this->default])) {
if (!array_key_exists($key, self::$languages[$this->default])) { /** @phpstan-ignore-line */
throw new Exception("$key not found");
}

return self::$languages[$this->default][$key];
return self::$languages[$this->default][$key]; /** @phpstan-ignore-line */
}
}
6 changes: 5 additions & 1 deletion src/thebigcrafter/omp/utils/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use Exception;
use thebigcrafter\Fluorine\Fluorine;
use thebigcrafter\Iodine\DeferredFuture;
use thebigcrafter\Iodine\Future;
use thebigcrafter\Iodine\Iodine;
use thebigcrafter\Sulfur\Path;

class Filesystem
{
public static function readFile(string $path)
/**
* @return Future<mixed>
*/
public static function readFile(string $path): Future
{
if (!file_exists($path)) {
throw new Exception("File not found");
Expand Down
16 changes: 13 additions & 3 deletions src/thebigcrafter/omp/utils/Internet.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@
namespace thebigcrafter\omp\utils;

use pocketmine\utils\InternetException;
use pocketmine\utils\InternetRequestResult;
use thebigcrafter\Fluorine\Fluorine;
use thebigcrafter\Iodine\DeferredFuture;
use thebigcrafter\Iodine\Future;
use thebigcrafter\Iodine\Iodine;

final class Internet
{
public static function fetch(string $url)
/**
* @return Future<mixed>
*/
public static function fetch(string $url): Future
{
return Iodine::async(function () use ($url) {
try {
$res = \pocketmine\utils\Internet::getURL($url);

return ($res->getBody());
if ($res instanceof InternetRequestResult) {
return $res->getBody();
}
} catch (InternetException $e) {
throw $e;
}
});
}

public static function getRemoteFileSize(string $url)
/**
* @return Future<mixed>
*/
public static function getRemoteFileSize(string $url): Future
{
return Iodine::async(function () use ($url) {
$headers = get_headers($url, true);
Expand Down

0 comments on commit 1ee16c4

Please sign in to comment.