diff --git a/app/Services/Hook.php b/app/Services/Hook.php index 36754ae8..5900e540 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -1,5 +1,7 @@ router); }); } - public static function registerPluginTransScripts($id, $pages = ['*'], $priority = 999) + public static function registerPluginTransScripts(string $id, $pages = ['*'], $priority = 999): void { Event::listen(Events\RenderingFooter::class, function ($event) use ($id, $pages) { foreach ($pages as $pattern) { @@ -83,7 +85,7 @@ class Hook }, $priority); } - public static function addStyleFileToPage($urls, $pages = ['*'], $priority = 1) + public static function addStyleFileToPage($urls, $pages = ['*'], $priority = 1): void { Event::listen(Events\RenderingHeader::class, function ($event) use ($urls, $pages) { foreach ($pages as $pattern) { @@ -100,7 +102,7 @@ class Hook }, $priority); } - public static function addScriptFileToPage($urls, $pages = ['*'], $priority = 1) + public static function addScriptFileToPage($urls, $pages = ['*'], $priority = 1): void { Event::listen(Events\RenderingFooter::class, function ($event) use ($urls, $pages) { foreach ($pages as $pattern) { diff --git a/app/Services/Minecraft.php b/app/Services/Minecraft.php index 05ce4193..aa671977 100644 --- a/app/Services/Minecraft.php +++ b/app/Services/Minecraft.php @@ -14,7 +14,7 @@ class Minecraft * @param string $view Which side of head to be captured, defaults to 'f' for front view. * @return resource */ - public static function generateAvatarFromSkin($binary, $height, $view = 'f') + public static function generateAvatarFromSkin(string $binary, int $height, string $view = 'f') { $src = imagecreatefromstring($binary); $dest = imagecreatetruecolor($height, $height); @@ -47,7 +47,7 @@ class Minecraft * @param int $gap Gap size between front & back preview in relative pixel. * @return resource */ - public static function generatePreviewFromSkin($binary, $height, $alex = false, $side = 'both', $gap = 4) + public static function generatePreviewFromSkin(string $binary, int $height, $alex = false, $side = 'both', $gap = 4) { $src = imagecreatefromstring($binary); @@ -172,7 +172,7 @@ class Minecraft * @param int $fillHeight Set the value to 0 to disable. * @return resource */ - public static function generatePreviewFromCape($binary, $height, $fillWidth = 0, $fillHeight = 0) + public static function generatePreviewFromCape(string $binary, int $height, $fillWidth = 0, $fillHeight = 0) { $src = imagecreatefromstring($binary); $ratio = imagesx($src) / 64; diff --git a/app/Services/PackageManager.php b/app/Services/PackageManager.php index 74cc9a5a..4f1ef5ef 100644 --- a/app/Services/PackageManager.php +++ b/app/Services/PackageManager.php @@ -1,5 +1,7 @@ path = $path; $this->cacheKey = "download_$url"; @@ -44,7 +46,7 @@ class PackageManager return $this; } - public function extract($destination) + public function extract(string $destination): void { $zip = new \ZipArchive(); $resource = $zip->open($this->path); @@ -57,7 +59,7 @@ class PackageManager } } - public function progress() + public function progress(): float { $progress = unserialize(Cache::get($this->cacheKey)); if ($progress['total'] == 0) { diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index 9e37268a..23d6f89f 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -1,8 +1,11 @@ path = $path; $this->packageInfo = $packageInfo; } - public function __get($name) + public function __get(string $name) { - return $this->packageInfoAttribute(snake_case($name, '-')); + return $this->packageInfoAttribute(Str::snake($name, '-')); } - public function __isset($name) + public function __isset(string $name) { return isset($this->{$name}) || $this->packageInfoAttribute(snake_case($name, '-')); } - public function packageInfoAttribute($name) + public function packageInfoAttribute(string $name) { return Arr::get($this->packageInfo, $name); } - public function assets($relativeUri) + public function assets(string $relativeUri): string { $baseUrl = config('plugins.url') ?: url('plugins'); return "$baseUrl/{$this->getDirname()}/assets/$relativeUri?v=".$this->version; } - /** - * @param bool $installed - * @return Plugin - */ - public function setInstalled($installed) + public function setInstalled(bool $installed): self { $this->installed = $installed; return $this; } - public function getDirname() + public function getDirname(): string { return $this->dirname; } - public function setDirname($dirname) + public function setDirname(string $dirname): self { $this->dirname = $dirname; return $this; } - public function getNameSpace() + public function getNameSpace(): string { return $this->namespace; } - public function setNameSpace($namespace) + public function setNameSpace(string $namespace): self { $this->namespace = $namespace; return $this; } - public function getViewPath($name) + public function getViewPath(string $name): string { return $this->getViewPathByFileName("$name.tpl"); } - public function getViewPathByFileName($filename) + public function getViewPathByFileName(string $filename): string { return $this->path."/views/$filename"; } @@ -143,74 +138,50 @@ class Plugin return $this->hasConfigView() ? view()->file($this->getViewPathByFileName(Arr::get($this->packageInfo, 'config'))) : null; } - public function hasConfigView() + public function hasConfigView(): bool { $filename = Arr::get($this->packageInfo, 'config'); return $filename && file_exists($this->getViewPathByFileName($filename)); } - /** - * @param string $version - * @return Plugin - */ - public function setVersion($version) + public function setVersion(string $version): self { $this->version = $version; return $this; } - /** - * @return string - */ - public function getVersion() + public function getVersion(): string { return $this->version; } - /** - * @param array $require - * @return Plugin - */ - public function setRequirements($require) + public function setRequirements(array $require): self { $this->require = $require; return $this; } - /** - * @return array - */ - public function getRequirements() + public function getRequirements(): array { return (array) $this->require; } - /** - * @param bool $enabled - * @return Plugin - */ - public function setEnabled($enabled) + public function setEnabled(bool $enabled): self { $this->enabled = $enabled; return $this; } - /** - * @return bool - */ - public function isEnabled() + public function isEnabled(): bool { return $this->enabled; } - /** - * @return string - */ - public function getPath() + public function getPath(): string { return $this->path; } diff --git a/app/Services/Webpack.php b/app/Services/Webpack.php index 54748dc0..df33d695 100644 --- a/app/Services/Webpack.php +++ b/app/Services/Webpack.php @@ -1,5 +1,7 @@ manifest, $path, ''); } diff --git a/app/helpers.php b/app/helpers.php index d968483e..fc3af916 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,12 +1,14 @@ environment('development')) { // @codeCoverageIgnoreStart @@ -23,19 +25,14 @@ if (! function_exists('webpack_assets')) { } if (! function_exists('plugin')) { - - /** - * @param string $id - * @return \App\Services\Plugin - */ - function plugin($id) + function plugin(string $id) { return app('plugins')->getPlugin($id); } } if (! function_exists('plugin_assets')) { - function plugin_assets($id, $relativeUri) + function plugin_assets(string $id, string $relativeUri): string { if ($plugin = plugin($id)) { return $plugin->assets($relativeUri); @@ -69,7 +66,7 @@ if (! function_exists('json')) { } if (! function_exists('bs_footer_extra')) { - function bs_footer_extra() + function bs_footer_extra(): string { $extraContents = []; @@ -80,7 +77,7 @@ if (! function_exists('bs_footer_extra')) { } if (! function_exists('bs_header_extra')) { - function bs_header_extra() + function bs_header_extra(): string { $extraContents = []; @@ -91,7 +88,7 @@ if (! function_exists('bs_header_extra')) { } if (! function_exists('bs_menu')) { - function bs_menu($type) + function bs_menu(string $type): string { $menu = config('menu'); @@ -139,7 +136,7 @@ if (! function_exists('bs_menu')) { return bs_menu_render($menu[$type]); } - function bs_menu_render($data) + function bs_menu_render(array $data): string { $content = ''; @@ -187,7 +184,7 @@ if (! function_exists('bs_menu')) { } if (! function_exists('bs_copyright')) { - function bs_copyright() + function bs_copyright(): string { return Arr::get( [ @@ -239,7 +236,7 @@ if (! function_exists('option_localized')) { } if (! function_exists('humanize_db_type')) { - function humanize_db_type($type = null) + function humanize_db_type($type = null): string { $map = [ 'mysql' => 'MySQL', @@ -271,7 +268,7 @@ if (! function_exists('format_http_date')) { * @param int $timestamp * @return string */ - function format_http_date($timestamp) + function format_http_date($timestamp): string { return Carbon::createFromTimestampUTC($timestamp)->format('D, d M Y H:i:s \G\M\T'); } @@ -284,7 +281,7 @@ if (! function_exists('get_datetime_string')) { * @param int $timestamp * @return string */ - function get_datetime_string($timestamp = 0) + function get_datetime_string($timestamp = 0): string { return $timestamp == 0 ? Carbon::now()->toDateTimeString() : Carbon::createFromTimestamp($timestamp)->toDateTimeString(); } @@ -299,7 +296,7 @@ if (! function_exists('get_client_ip')) { * * @return string */ - function get_client_ip() + function get_client_ip(): string { if (option('ip_get_method') == '0') { // Use `HTTP_X_FORWARDED_FOR` if available first @@ -330,7 +327,7 @@ if (! function_exists('get_string_replaced')) { * @param array $rules * @return string */ - function get_string_replaced($str, $rules) + function get_string_replaced(string $str, array $rules): string { foreach ($rules as $search => $replace) { $str = str_replace($search, $replace, $str); @@ -350,7 +347,7 @@ if (! function_exists('is_request_secure')) { * * @return bool */ - function is_request_secure() + function is_request_secure(): bool { if (Arr::get($_SERVER, 'HTTPS') == 'on') { return true; @@ -375,7 +372,7 @@ if (! function_exists('nl2p')) { * @param string $text * @return string */ - function nl2p($text) + function nl2p(string $text): string { $parts = explode("\n", $text); $result = '

'.implode('

', $parts).'

'; diff --git a/tests/Concerns/FakePackageManager.php b/tests/Concerns/FakePackageManager.php index 60cb8f57..02c3f5fa 100644 --- a/tests/Concerns/FakePackageManager.php +++ b/tests/Concerns/FakePackageManager.php @@ -1,8 +1,12 @@ throw = $throw; } - public function download($url, $path, $shasum = null) + public function download(string $url, string $path, $shasum = null): PackageManager { if ($this->throw) { throw new \Exception(''); @@ -21,13 +25,13 @@ class FakePackageManager extends \App\Services\PackageManager } } - public function extract($destination) + public function extract(string $destination): void { - return true; + // } - public function progress() + public function progress(): float { - return '0'; + return 0.0; } }