Skip to content

Commit

Permalink
realodix/relax v1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Aug 7, 2024
1 parent 120fd8d commit 7a94cd9
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 98 deletions.
14 changes: 7 additions & 7 deletions app/Helpers/Global/GeneralHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
use App\Helpers\Helper;
use Illuminate\Support\Number;

if (! function_exists('urlFormat')) {
if (!function_exists('urlFormat')) {
/**
* Display the link according to what You need.
*
* @param string $value
* @param null|int $limit
* @param bool $scheme
* @param string $value
* @param int|null $limit
* @param bool $scheme
* @return string
*/
function urlFormat($value, $limit = null, $scheme = true)
Expand All @@ -18,7 +18,7 @@ function urlFormat($value, $limit = null, $scheme = true)
}
}

if (! function_exists('n_abb')) {
if (!function_exists('n_abb')) {
/**
* This is modified version of Laravel Number::abbreviate() method with the
* default value of maxPrecision is 2.
Expand All @@ -27,8 +27,8 @@ function urlFormat($value, $limit = null, $scheme = true)
* - https://github.com/laravel/framework/blob/5d4b26e/src/Illuminate/Support/Number.php#L154
*
* @param int|float $number
* @param int $precision
* @param null|int $maxPrecision
* @param int $precision
* @param int|null $maxPrecision
* @return bool|string
*/
function n_abb($number, $precision = 0, $maxPrecision = 2)
Expand Down
18 changes: 9 additions & 9 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public static function deviceDetector()
/**
* A URL formatted according to the specified format.
*
* @param string $value URL links
* @param null|int $limit Length string will be truncated to, including suffix
* @param bool $scheme Show or remove URL schemes
* @param bool $trailingSlash Show or remove trailing slash
* @param string $value URL links
* @param int|null $limit Length string will be truncated to, including suffix
* @param bool $scheme Show or remove URL schemes
* @param bool $trailingSlash Show or remove trailing slash
* @return string
*/
public static function urlFormat(string $value, ?int $limit = null, bool $scheme = true, bool $trailingSlash = true)
{
$sUrl = SpatieUrl::fromString($value);
$hostLen = strlen($sUrl->getScheme().'://'.$sUrl->getHost());
$limit = $limit ?? strlen($value);
$hostLen = strlen($sUrl->getScheme() . '://' . $sUrl->getHost());
$limit ??= strlen($value);

// Optionally strip scheme
if ($scheme === false) {
Expand All @@ -52,7 +52,7 @@ public static function urlFormat(string $value, ?int $limit = null, bool $scheme
$firstPartLen = $hostLen + intval(($pathLen - 1) * 0.5) + strlen($trimMarker);
$lastPartLen = -abs($limit - $firstPartLen);

return mb_strimwidth($value, 0, $firstPartLen, $trimMarker).substr($value, $lastPartLen);
return mb_strimwidth($value, 0, $firstPartLen, $trimMarker) . substr($value, $lastPartLen);
}

return $value;
Expand All @@ -67,7 +67,7 @@ public static function routeCollisionList()
{
return collect(\Illuminate\Support\Facades\Route::getRoutes()->get())
->map(fn(\Illuminate\Routing\Route $route) => $route->uri)
->reject(fn($value) => ! preg_match('/^[a-zA-Z\-]+$/', $value))
->reject(fn($value) => !preg_match('/^[a-zA-Z\-]+$/', $value))
->unique()->sort()
->toArray();
}
Expand All @@ -89,7 +89,7 @@ public static function publicPathCollisionList()
// remove ., ..,
->reject(fn($value) => in_array($value, ['.', '..']))
// remove file with extension
->filter(fn($value) => ! preg_match('/\.[a-z]+$/', $value))
->filter(fn($value) => !preg_match('/\.[a-z]+$/', $value))
// remove array value which is in config('urlhub.reserved_keyword')
->reject(fn($value) => in_array($value, config('urlhub.reserved_keyword')))
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function edit(Url $url)
* Update the destination URL.
*
* @param UpdateUrlRequest $request \App\Http\Requests\UpdateUrlRequest
* @param Url $url \App\Models\Url
* @param Url $url \App\Models\Url
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function view(User $user)
* Change the password.
*
* @param UpdateUserPassword $request \App\Http\Requests\UpdateUserPassword
* @param User $user \App\Models\User
* @param User $user \App\Models\User
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
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 @@ -44,7 +44,7 @@ public function edit(User $user)
* Update the specified user in storage.
*
* @param UpdateUserEmail $request \App\Http\Requests\UpdateUserEmail
* @param User $user \App\Models\User
* @param User $user \App\Models\User
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Auth\Access\AuthorizationException
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/StoreUrlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function rules()
'long_url' => ['required', 'url', 'max:65535', new NotBlacklistedDomain],
'custom_key' => [
'nullable', 'unique:urls,keyword',
"min:$minLen", "max:$maxLen", 'lowercase',
"min:{$minLen}", "max:{$maxLen}", 'lowercase',
new \App\Rules\AlphaNumHyphen,
new \App\Rules\NotBlacklistedKeyword,
],
Expand Down
16 changes: 8 additions & 8 deletions app/Livewire/Table/UserTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ public function fields(): PowerGridFields
return PowerGrid::fields()
->add('name', function (User $user) {
$urlsCount = $user->urls_count;
$urlCountTitle = number_format($urlsCount).' short '.Str::plural('link', $urlsCount);
$urlCountTitle = number_format($urlsCount) . ' short ' . Str::plural('link', $urlsCount);

return $user->name.' <span title="'.$urlCountTitle.'">('.n_abb($urlsCount).')</span>';
return $user->name . ' <span title="' . $urlCountTitle . '">(' . n_abb($urlsCount) . ')</span>';
})
->add('email')
->add('created_at_formatted', function (User $user) {
return
'<span title="'.$user->created_at->toDayDateTimeString().'">'
.$user->created_at->shortRelativeDiffForHumans().
'<span title="' . $user->created_at->toDayDateTimeString() . '">'
. $user->created_at->shortRelativeDiffForHumans() .
'</span>';
})
->add('action', function (User $user) {
return
'<a role="button" href="'.route('user.edit', $user).'" title="'.__('Details').'"
'<a role="button" href="' . route('user.edit', $user) . '" title="' . __('Details') . '"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-person-edit\')').
. Blade::render('@svg(\'icon-person-edit\')') .
'</a>
<a role="button" href="'.route('user.password.show', $user).'" title="'.__('Change Password').'"
<a role="button" href="' . route('user.password.show', $user) . '" title="' . __('Change Password') . '"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-key\')').
. Blade::render('@svg(\'icon-key\')') .
'</a>';
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Validation/ValidateCustomKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function rules()

return [
'keyword' => [
"min:$minLen", "max:$maxLen", 'unique:App\Models\Url', 'lowercase:field',
"min:{$minLen}", "max:{$maxLen}", 'unique:App\Models\Url', 'lowercase:field',
new \App\Rules\AlphaNumHyphen,
new \App\Rules\NotBlacklistedKeyword,
],
Expand Down
26 changes: 13 additions & 13 deletions app/Models/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use Illuminate\Database\Eloquent\Model;

/**
* @property int $id
* @property null|int $user_id
* @property string $keyword
* @property bool $is_custom
* @property string $destination
* @property string $title
* @property string $user_sign
* @property int $id
* @property int|null $user_id
* @property string $keyword
* @property bool $is_custom
* @property string $destination
* @property string $title
* @property string $user_sign
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property User $author
* @property Visit $visits
* @property string $short_url
* @property User $author
* @property Visit $visits
* @property string $short_url
*/
class Url extends Model
{
Expand Down Expand Up @@ -48,7 +48,7 @@ class Url extends Model
/**
* Get the attributes that should be cast.
*
* @return array{user_id: 'integer', is_custom: 'boolean'}
* @return array{user_id:'integer',is_custom:'boolean'}
*/
protected function casts(): array
{
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function userId(): Attribute
protected function shortUrl(): Attribute
{
return Attribute::make(
get: fn($value, $attr) => url('/'.$attr['keyword']),
get: fn($value, $attr) => url('/' . $attr['keyword']),
);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public function getKeyword(StoreUrlRequest $request): string
public function getWebTitle(string $value): string
{
$spatieUrl = \Spatie\Url\Url::fromString($value);
$defaultTitle = $spatieUrl->getHost().' - Untitled';
$defaultTitle = $spatieUrl->getHost() . ' - Untitled';

if (config('urlhub.web_title')) {
try {
Expand Down
28 changes: 14 additions & 14 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
use Illuminate\Notifications\Notifiable;

/**
* @property int $id
* @property string $name
* @property string $email
* @property string $email_verified_at
* @property string $password
* @property string $two_factor_secret
* @property string $two_factor_recovery_codes
* @property string $remember_token
* @property int $id
* @property string $name
* @property string $email
* @property string $email_verified_at
* @property string $password
* @property string $two_factor_secret
* @property string $two_factor_recovery_codes
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property Url $urls
* @property Url $urls
*/
class User extends Authenticatable
{
Expand Down Expand Up @@ -47,7 +47,7 @@ class User extends Authenticatable
/**
* Get the attributes that should be cast.
*
* @return array{email_verified_at: 'datetime', password: 'hashed'}
* @return array{email_verified_at:'datetime',password:'hashed'}
*/
protected function casts(): array
{
Expand Down Expand Up @@ -98,10 +98,10 @@ public function signature(): string

$userDeviceInfo = implode([
request()->ip(),
isset($browser['name']) ? $browser['name'] : '',
isset($os['name']) ? $os['name'] : '',
isset($os['version']) ? $os['version'] : '',
$device->getDeviceName().$device->getModel().$device->getBrandName(),
$browser['name'] ?? '',
$os['name'] ?? '',
$os['version'] ?? '',
$device->getDeviceName() . $device->getModel() . $device->getBrandName(),
request()->getPreferredLanguage(),
]);

Expand Down
14 changes: 7 additions & 7 deletions app/Models/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Illuminate\Database\Eloquent\Model;

/**
* @property int $id
* @property int $url_id
* @property string $visitor_id
* @property bool $is_first_click
* @property string $referer
* @property int $id
* @property int $url_id
* @property string $visitor_id
* @property bool $is_first_click
* @property string $referer
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property Url $urls
* @property Url $urls
*/
class Visit extends Model
{
Expand All @@ -34,7 +34,7 @@ class Visit extends Model
/**
* Get the attributes that should be cast.
*
* @return array{is_first_click: 'boolean'}
* @return array{is_first_click:'boolean'}
*/
protected function casts(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function boot()
RateLimiter::for('login', function (Request $request) {
$email = (string) $request->identity;

return Limit::perMinute(5)->by($email.$request->ip());
return Limit::perMinute(5)->by($email . $request->ip());
});

RateLimiter::for('two-factor', function (Request $request) {
Expand Down
4 changes: 2 additions & 2 deletions app/Providers/HelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class HelperServiceProvider extends ServiceProvider
*/
public function boot()
{
$rdi = new \RecursiveDirectoryIterator(app_path('Helpers'.DIRECTORY_SEPARATOR.'Global'));
$rdi = new \RecursiveDirectoryIterator(app_path('Helpers' . DIRECTORY_SEPARATOR . 'Global'));
$it = new \RecursiveIteratorIterator($rdi);

while ($it->valid()) {
if (
! $it->isDot()
!$it->isDot()
&& $it->isFile()
&& $it->isReadable()
&& $it->current()->getExtension() === 'php'
Expand Down
6 changes: 3 additions & 3 deletions app/Rules/NotBlacklistedDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function validate(string $attribute, mixed $value, \Closure $fail): void

foreach ($blackLists as $blackList) {
$blackList = Helper::urlFormat($blackList, scheme: false);
$segment1 = '://'.$blackList.'/';
$segment2 = '://www.'.$blackList.'/';
$segment1 = '://' . $blackList . '/';
$segment2 = '://www.' . $blackList . '/';

if (strstr($longUrl, $segment1) || strstr($longUrl, $segment2)) {
$bool = false;
Expand All @@ -26,7 +26,7 @@ public function validate(string $attribute, mixed $value, \Closure $fail): void
if ($bool === false) {
$fail(
'Sorry, the URL you entered is on our internal blacklist. '
.'It may have been used abusively in the past, or it may link to another URL redirection service.',
. 'It may have been used abusively in the past, or it may link to another URL redirection service.',
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Services/KeyGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function generate(string $value): string
{
$string = $this->simpleString($value);

if (! $this->verify($string) || strlen($string) < config('urlhub.keyword_length')) {
if (!$this->verify($string) || strlen($string) < config('urlhub.keyword_length')) {
do {
$randomString = $this->randomString();
} while (! $this->verify($randomString));
} while (!$this->verify($randomString));

return $randomString;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public function totalKey(): int
$length = config('urlhub.keyword_length');

return Url::whereRaw('LENGTH(keyword) = ?', [$length])
->whereRaw('keyword REGEXP "^[a-zA-Z0-9]{'.$length.'}$"')
->whereRaw('keyword REGEXP "^[a-zA-Z0-9]{' . $length . '}$"')
->count();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/VisitorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function getRefererHost(?string $value): ?string

$referer = SpatieUrl::fromString($value);

return $referer->getScheme().'://'.$referer->getHost();
return $referer->getScheme() . '://' . $referer->getHost();
}
}
4 changes: 2 additions & 2 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
Expand Down
Loading

0 comments on commit 7a94cd9

Please sign in to comment.