Enable strict types partially
This commit is contained in:
parent
f93e0d1755
commit
be9f6011bb
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Event;
|
||||
|
|
@ -23,7 +25,7 @@ class Hook
|
|||
* ]
|
||||
* @return void
|
||||
*/
|
||||
public static function addMenuItem($category, $position, array $menu)
|
||||
public static function addMenuItem(string $category, int $position, array $menu): void
|
||||
{
|
||||
$class = 'App\Events\Configure'.Str::title($category).'Menu';
|
||||
|
||||
|
|
@ -54,14 +56,14 @@ class Hook
|
|||
*
|
||||
* @param Closure $callback
|
||||
*/
|
||||
public static function addRoute(Closure $callback)
|
||||
public static function addRoute(Closure $callback): void
|
||||
{
|
||||
Event::listen(Events\ConfigureRoutes::class, function ($event) use ($callback) {
|
||||
return call_user_func($callback, $event->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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Cache;
|
||||
|
|
@ -20,7 +22,7 @@ class PackageManager
|
|||
};
|
||||
}
|
||||
|
||||
public function download($url, $path, $shasum = null)
|
||||
public function download(string $url, string $path, $shasum = null): self
|
||||
{
|
||||
$this->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) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $name
|
||||
|
|
@ -61,79 +64,71 @@ class Plugin
|
|||
*/
|
||||
protected $enabled = false;
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param array $packageInfo
|
||||
*/
|
||||
public function __construct($path, $packageInfo)
|
||||
public function __construct(string $path, array $packageInfo)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use File;
|
||||
|
|
@ -17,7 +19,7 @@ class Webpack
|
|||
}
|
||||
}
|
||||
|
||||
public function __get($path)
|
||||
public function __get(string $path)
|
||||
{
|
||||
return Arr::get($this->manifest, $path, '');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
if (! function_exists('webpack_assets')) {
|
||||
function webpack_assets($relativeUri)
|
||||
function webpack_assets(string $relativeUri): string
|
||||
{
|
||||
if (app()->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 = '<p>'.implode('</p><p>', $parts).'</p>';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Concerns;
|
||||
|
||||
class FakePackageManager extends \App\Services\PackageManager
|
||||
use App\Services\PackageManager;
|
||||
|
||||
class FakePackageManager extends PackageManager
|
||||
{
|
||||
private $throw;
|
||||
|
||||
|
|
@ -12,7 +16,7 @@ class FakePackageManager extends \App\Services\PackageManager
|
|||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user