Skip to content

Commit

Permalink
chore: Add php code sniffer and apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keriati committed Nov 25, 2022
1 parent 181b756 commit 7565bd4
Show file tree
Hide file tree
Showing 1,532 changed files with 166,809 additions and 151 deletions.
17 changes: 8 additions & 9 deletions app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

Expand Down Expand Up @@ -61,16 +62,14 @@ public function class(): string
$name = $this->name;
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);

$class = '\App\SupportedApps\\'.$name.'\\'.$name;

return $class;
return '\App\SupportedApps\\'.$name.'\\'.$name;
}

/**
* @param $name
* @return string
*/
public static function classFromName($name)
public static function classFromName($name): string
{
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);

Expand Down Expand Up @@ -110,6 +109,7 @@ public static function autocomplete(): array
/**
* @param $appid
* @return mixed|null
* @throws GuzzleException
*/
public static function getApp($appid)
{
Expand All @@ -121,13 +121,12 @@ public static function getApp($appid)
$application = ($localapp) ? $localapp : new self;

// Files missing? || app not in db || old sha version
if (
! file_exists(app_path('SupportedApps/'.className($app->name))) ||
if (! file_exists(app_path('SupportedApps/'.className($app->name))) ||
! $localapp ||
$localapp->sha !== $app->sha
) {
$gotFiles = SupportedApps::getFiles($app);
if($gotFiles) {
if ($gotFiles) {
$app = SupportedApps::saveApp($app, $application);
}
}
Expand All @@ -147,7 +146,7 @@ public static function single($appid)
if ($app === null) {
// Try in db for Private App
$appModel = self::where('appid', $appid)->first();
if($appModel) {
if ($appModel) {
$app = json_decode($appModel->toJson());
}
}
Expand Down Expand Up @@ -176,7 +175,7 @@ public static function applist(): array
// Check for private apps in the db
$appsListFromDB = self::all(['appid', 'name']);

foreach($appsListFromDB as $app) {
foreach ($appsListFromDB as $app) {
// Already existing keys are overwritten,
// only private apps should be added at the end
$list[$app->appid] = $app->name;
Expand Down
15 changes: 13 additions & 2 deletions app/Console/Commands/RegisterApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ public function handle()
}
}

public function addApp($folder, $remove = false)
/**
* @param $folder
* @param bool $remove
* @return void
*/
public function addApp($folder, bool $remove = false)
{
$json = app_path('SupportedApps/'.$folder.'/app.json');

Expand Down Expand Up @@ -88,7 +93,13 @@ public function addApp($folder, $remove = false)
$this->info('Application Added - ' . $app->name . ' - ' . $app->appid);
}

private function saveIcon($appFolder, $icon) {
/**
* @param $appFolder
* @param $icon
* @return void
*/
private function saveIcon($appFolder, $icon)
{
$iconPath = app_path('SupportedApps/' . $appFolder . '/' . $icon);
$contents = file_get_contents($iconPath);
Storage::disk('public')->put('icons/'.$icon, $contents);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
44 changes: 35 additions & 9 deletions app/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

use Illuminate\Support\Str;

function format_bytes($bytes, $is_drive_size = true, $beforeunit = '', $afterunit = '')
/**
* @param $bytes
* @param bool $is_drive_size
* @param string $beforeunit
* @param string $afterunit
* @return string
*/
function format_bytes($bytes, bool $is_drive_size = true, string $beforeunit = '', string $afterunit = ''): string
{
$btype = ($is_drive_size === true) ? 1000 : 1024;
$labels = ['B', 'KB', 'MB', 'GB', 'TB'];
Expand All @@ -18,7 +25,13 @@ function format_bytes($bytes, $is_drive_size = true, $beforeunit = '', $afteruni
}
}

function str_slug($title, $separator = '-', $language = 'en')
/**
* @param $title
* @param string $separator
* @param string $language
* @return string
*/
function str_slug($title, string $separator = '-', string $language = 'en'): string
{
return Str::slug($title, $separator, $language);
}
Expand All @@ -28,17 +41,21 @@ function str_slug($title, $separator = '-', $language = 'en')
* Determine if a given string matches a given pattern.
*
* @param string|array $pattern
* @param string $value
* @param string $value
* @return bool
*
* @deprecated Str::is() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_is($pattern, $value)
function str_is($pattern, string $value): bool
{
return Str::is($pattern, $value);
}
}

/**
* @param $hex
* @return float|int
*/
function get_brightness($hex)
{
// returns brightness value from 0 to 255
Expand All @@ -56,7 +73,11 @@ function get_brightness($hex)
return (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
}

function title_color($hex)
/**
* @param $hex
* @return string
*/
function title_color($hex): string
{
if (get_brightness($hex) > 130) {
return ' black';
Expand All @@ -65,7 +86,10 @@ function title_color($hex)
}
}

function getLinkTargetAttribute()
/**
* @return string
*/
function getLinkTargetAttribute(): string
{
$target = \App\Setting::fetch('window_target');

Expand All @@ -76,9 +100,11 @@ function getLinkTargetAttribute()
}
}

/**
* @param $name
* @return array|string|string[]|null
*/
function className($name)
{
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);

return $name;
return preg_replace('/[^\p{L}\p{N}]/u', '', $name);
}
45 changes: 35 additions & 10 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\URL;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Response;

class LoginController extends Controller
{
Expand All @@ -30,7 +36,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/';
protected string $redirectTo = '/';

/**
* Create a new controller instance.
Expand All @@ -43,20 +49,23 @@ public function __construct()
$this->middleware('guest')->except('logout');
}

public function username()
/**
* @return string
*/
public function username(): string
{
return 'username';
}

/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
* @param Request $request
* @return Response
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function login(Request $request)
public function login(Request $request): Response
{
$current_user = User::currentUser();
$request->merge(['username' => $current_user->username, 'remember' => true]);
Expand Down Expand Up @@ -88,15 +97,23 @@ public function index()
{
}

public function setUser(User $user)
/**
* @param User $user
* @return RedirectResponse
*/
public function setUser(User $user): RedirectResponse
{
Auth::logout();
session(['current_user' => $user]);

return redirect()->route('dash');
}

public function autologin($uuid)
/**
* @param $uuid
* @return RedirectResponse
*/
public function autologin($uuid): RedirectResponse
{
$user = User::where('autologin', $uuid)->first();
Auth::login($user, true);
Expand All @@ -108,18 +125,26 @@ public function autologin($uuid)
/**
* Show the application's login form.
*
* @return \Illuminate\Http\Response
* @return Application|Factory|View
*/
public function showLoginForm()
{
return view('auth.login');
}

protected function authenticated(Request $request, $user)
/**
* @param Request $request
* @param $user
* @return RedirectResponse
*/
protected function authenticated(Request $request, $user): RedirectResponse
{
return back();
}

/**
* @return mixed|string
*/
public function redirectTo()
{
return Session::get('url.intended') ? Session::get('url.intended') : $this->redirectTo;
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/';
protected string $redirectTo = '/';

/**
* Create a new controller instance.
Expand All @@ -45,7 +45,7 @@ public function __construct()
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
protected function validator(array $data): \Illuminate\Contracts\Validation\Validator
{
return Validator::make($data, [
'name' => 'required|string|max:255',
Expand All @@ -58,7 +58,7 @@ protected function validator(array $data)
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
* @return User
*/
protected function create(array $data)
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/';
protected string $redirectTo = '/';

/**
* Create a new controller instance.
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Artisan;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -204,7 +205,7 @@ public function storelogic(Request $request, $id = null)
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
);
$contents = file_get_contents($request->input('icon'), false, stream_context_create($options));

if ($application) {
Expand All @@ -219,9 +220,9 @@ public function storelogic(Request $request, $id = null)

// Private apps could have here duplicated icons folder
if (strpos($path, 'icons/icons/') !== false) {
$path = str_replace('icons/icons/','icons/',$path);
$path = str_replace('icons/icons/', 'icons/', $path);
}
if(! Storage::disk('public')->exists($path)) {
if (! Storage::disk('public')->exists($path)) {
Storage::disk('public')->put($path, $contents);
}
$request->merge([
Expand Down Expand Up @@ -360,6 +361,7 @@ public function restore(int $id): RedirectResponse
*
* @param Request $request
* @return string|null
* @throws GuzzleException
*/
public function appload(Request $request): ?string
{
Expand All @@ -386,9 +388,9 @@ public function appload(Request $request): ?string

$output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f';

if(strpos($app->icon, '://') !== false) {
if (strpos($app->icon, '://') !== false) {
$output['iconview'] = $app->icon;
} elseif(strpos($app->icon, 'icons/') !== false) {
} elseif (strpos($app->icon, 'icons/') !== false) {
// Private apps have the icon locally
$output['iconview'] = URL::to('/').'/storage/'.$app->icon;
$output['icon'] = str_replace('icons/', '', $output['icon']);
Expand Down
Loading

0 comments on commit 7565bd4

Please sign in to comment.