Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Code Review: Happy New Year 2023 #877

Merged
merged 5 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

UH_ANONYMIZE_IP_ADDR=true
UH_PUBLIC_SITE=true
UH_REGISTRATION=true
UH_HASH_LENGTH=6
Expand Down
1 change: 0 additions & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ APP_KEY=base64:SsuVzwH9xQnlEqSgTdTbBKyJ0rYrgt5Wr71vv02jDV8=
APP_DEBUG=true
APP_URL=http://localhost

UH_ANONYMIZE_IP_ADDR=true
UH_PUBLIC_SITE=true
UH_REGISTRATION=true
UH_HASH_LENGTH=6
Expand Down
65 changes: 0 additions & 65 deletions app/Actions/UrlRedirectAction.php

This file was deleted.

16 changes: 0 additions & 16 deletions app/Helpers/Global/NumHelper.php

This file was deleted.

15 changes: 0 additions & 15 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,9 @@
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
use Spatie\Url\Url as SpatieUrl;
use Symfony\Component\HttpFoundation\IpUtils;

class Helper
{
/**
* Anonymize an IPv4 or IPv6 address.
*
* @param string|null $address
*/
public static function anonymizeIp($address): string
{
if (config('urlhub.anonymize_ip_addr') === false) {
return $address;
}

return IPUtils::anonymize($address);
}

/**
* Display the link according to what You need.
*
Expand Down
63 changes: 0 additions & 63 deletions app/Helpers/NumHelper.php

This file was deleted.

43 changes: 0 additions & 43 deletions app/Http/Controllers/API/UrlController.php

This file was deleted.

5 changes: 3 additions & 2 deletions app/Http/Controllers/Dashboard/AllUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Models\Url;

class AllUrlController extends Controller
{
Expand All @@ -27,10 +28,10 @@ public function view()
/**
* Delete a Short URL on user (Admin) request.
*
* @param mixed $url
* @param Url $url \App\Models\Url
* @return \Illuminate\Http\RedirectResponse
*/
public function delete($url)
public function delete(Url $url)
{
$url->delete();

Expand Down
33 changes: 16 additions & 17 deletions app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use App\Http\Controllers\Controller;
use App\Models\Url;
use App\Models\User;
use App\Models\Visit;
use App\Services\KeyGeneratorService;
use App\Services\UHubLinkService;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
public function __construct(
public Url $url,
public User $user,
public Visit $visit
public UHubLinkService $uHubLinkService,
) {
}

Expand All @@ -27,39 +28,37 @@ public function view()
return view('backend.dashboard', [
'url' => $this->url,
'user' => $this->user,
'visit' => $this->visit,
'keyGeneratorService' => app(KeyGeneratorService::class),
]);
}

/**
* Show shortened url details page
*
* @param mixed $key
* @param string $urlKey A unique key for the shortened URL
* @return \Illuminate\Contracts\View\View
*/
public function edit($key)
public function edit(string $urlKey)
{
$url = Url::whereKeyword($key)->firstOrFail();
$url = Url::whereKeyword($urlKey)->firstOrFail();

$this->authorize('updateUrl', $url);

return view('backend.edit', compact('url'));
return view('backend.edit', ['url' => $url]);
}

/**
* Update the destination URL
*
* @param Request $request \Illuminate\Http\Request
* @param mixed $url
* @param Url $url \App\Models\Url
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function update(Request $request, $url)
public function update(Request $request, Url $url)
{
$url->destination = $request->long_url;
$url->title = $request->title;
$url->save();
$this->uHubLinkService->update($request, $url);

return to_route('dashboard')
->withFlashSuccess(__('Link changed successfully !'));
Expand All @@ -68,12 +67,12 @@ public function update(Request $request, $url)
/**
* Delete shortened URLs
*
* @param mixed $url
* @param Url $url \App\Models\Url
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function delete($url)
public function delete(Url $url)
{
$this->authorize('forceDelete', $url);

Expand All @@ -84,12 +83,12 @@ public function delete($url)
}

/**
* @param mixed $key
* @param string $urlKey A unique key for the shortened URL
* @return \Illuminate\Http\RedirectResponse
*/
public function duplicate($key)
public function duplicate($urlKey)
{
$this->url->duplicate($key, auth()->id());
$this->uHubLinkService->duplicate($urlKey);

return redirect()->back()
->withFlashSuccess(__('The link has successfully duplicated.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function view(User $user)
{
$this->authorize('view', $user);

return view('backend.user.changepassword', compact('user'));
return view('backend.user.changepassword', ['user' => $user]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function edit(User $user)
{
$this->authorize('view', $user);

return view('backend.user.profile', compact('user'));
return view('backend.user.profile', ['user' => $user]);
}

/**
Expand Down