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

More enhancement #335

Closed
wants to merge 13 commits into from
24 changes: 24 additions & 0 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'

jobs:
php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Audit

on:
pull_request:
push:
branches:
- main
pull_request:

jobs:
audit:
name: Audit Composer
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Test Build

on:
pull_request:
push:
branches:
- main
pull_request:

jobs:
test:
name: PHP 8.0, Laravel 9.*
Expand Down
5 changes: 4 additions & 1 deletion app/BitBucketRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App;

use App\BaseRepo;
use App\Exceptions\BitBucketException;
use App\Http\Remotes\BitBucket;
use Illuminate\Support\Arr;
Expand All @@ -15,6 +14,10 @@ class BitBucketRepo extends BaseRepo

protected $bitBucket;

protected $username;

protected $repo;

private function __construct($url, BitBucket $bitBucket)
{
if (! $bitBucket->validateUrl($url)) {
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/CheckPackageUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
namespace App\Console\Commands;

use App\Jobs\CheckPackageUrlsForAvailability as CheckPackageUrlsJob;
use App\Package;
use App\Models\Package;
use Illuminate\Console\Command;

class CheckPackageUrls extends Command
{

protected $signature = 'novapackages:check-package-urls';

protected $description = 'Check all package URLs for 4XX errors';

public function handle()
{
$validPackages = Package::whereNull('marked_as_unavailable_at')
$validPackages = Package::query()
->whereNull('marked_as_unavailable_at')
->with('author')
->get();

Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/DeleteOpenGraphImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Package;
use App\Models\Package;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

Expand All @@ -15,14 +15,14 @@ class DeleteOpenGraphImages extends Command
public function handle()
{
if (! $this->argument('package')) {
$files = Storage::allFiles(config('opengraph.image_directory_name') . '/');
$files = Storage::allFiles(config('opengraph.image_directory_name').'/');
Storage::delete($files);

return;
}

$package = Package::where('id', $this->argument('package'))->first();
$file = config('opengraph.image_directory_name') . "/{$package->og_image_name}";
$file = config('opengraph.image_directory_name')."/{$package->og_image_name}";

Storage::delete($file);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/DeleteSelfAuthoredPackageRatings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function handle()

private function deleteSelfAuthoredPackageRatings()
{
$query = Rating::whereHasMorph('rateable', \App\Package::class, function ($query) {
$query = Rating::whereHasMorph('rateable', \App\Models\Package::class, function ($query) {
return $query
->join('collaborators', 'collaborators.id', '=', 'packages.author_id')
->whereRaw('collaborators.user_id = ratings.user_id');
Expand All @@ -32,7 +32,7 @@ private function deleteSelfAuthoredPackageRatings()

private function deleteSelfContributedPackageRatings()
{
$query = Rating::whereHasMorph('rateable', \App\Package::class, function ($query) {
$query = Rating::whereHasMorph('rateable', \App\Models\Package::class, function ($query) {
return $query
->join('collaborator_package', 'collaborator_package.package_id', '=', 'packages.id')
->join('collaborators', 'collaborators.id', '=', 'collaborator_package.collaborator_id')
Expand Down
7 changes: 4 additions & 3 deletions app/Console/Commands/DisableUnavailablePackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

namespace App\Console\Commands;

use App\Models\Package;
use App\Notifications\NotifyAuthorOfDisabledPackage;
use App\Package;
use Illuminate\Console\Command;

class DisableUnavailablePackages extends Command
{

protected $signature = 'novapackages:disable-unavailable-packages';

protected $description = 'Disable unavailable packages after one month.';

public function handle()
{
$unavailablePackages = Package::whereNotNull('marked_as_unavailable_at')
// TODO: Get all packages from database in the past 30 days
$unavailablePackages = Package::query()
->whereNotNull('marked_as_unavailable_at')
->where('is_disabled', 0)
->get();

Expand Down
8 changes: 4 additions & 4 deletions app/Console/Commands/GenerateOpenGraphImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Console\Commands;

use App\Jobs\GeneratePackageOpenGraphImage;
use App\Package;
use App\Models\Package;
use Illuminate\Console\Command;

class GenerateOpenGraphImages extends Command
Expand All @@ -16,9 +16,9 @@ public function handle()
{
$this->callSilent('purge:ogimage', ['package' => $this->argument('package')]);

$packages = $this->argument('package')
? Package::where('id', $this->argument('package'))->get()
: Package::all();
$packages = Package::query()
->when($this->argument('package'), fn ($query, $id) => $query->where('id', $id))
->get();

$bar = $this->output->createProgressBar(count($packages));
$this->info('Generating images ...');
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/GithubAuthNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Console\Commands;

use App\Models\User;
use App\Notifications\GithubAuthNotification;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification;

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SendUnavailablePackageFollowUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace App\Console\Commands;

use App\Models\Package;
use App\Notifications\RemindAuthorOfUnavailablePackage;
use App\Package;
use Illuminate\Console\Command;

class SendUnavailablePackageFollowUp extends Command
{

protected $signature = 'novapackages:send-unavailable-package-followup';

protected $description = 'If package has been unavailable for two weeks, send follow-up to package author.';

public function handle()
{
// TODO: Get all packages from database in the past 14 days
$unavailablePackages = Package::whereNotNull('marked_as_unavailable_at')
->where('is_disabled', 0)
->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/SyncPackagistData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Console\Commands;

use App\Jobs\SyncPackagePackagistData;
use App\Package;
use App\Models\Package;
use Illuminate\Console\Command;

class SyncPackagistData extends Command
Expand Down
8 changes: 4 additions & 4 deletions app/Console/Commands/SyncRepositoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Console\Commands;

use App\Jobs\SyncPackageRepositoryData;
use App\Package;
use App\Models\Package;
use Illuminate\Console\Command;

class SyncRepositoryData extends Command
Expand All @@ -14,9 +14,9 @@ class SyncRepositoryData extends Command

public function handle()
{
$packages = $this->argument('package')
? Package::where('id', $this->argument('package'))->get()
: Package::all();
$packages = Package::query()
->when($this->argument('package'), fn ($query, $id) => $query->where('id', $id))
->get();

foreach ($packages as $package) {
dispatch(new SyncPackageRepositoryData($package));
Expand Down
12 changes: 0 additions & 12 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@

namespace App\Console;

use App\Console\Commands\CheckPackageUrls;
use App\Console\Commands\DeleteAbandonedScreenshots;
use App\Console\Commands\SyncPackagistData;
use App\Console\Commands\SyncRepositoryData;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

protected $commands = [
SyncPackagistData::class,
DeleteAbandonedScreenshots::class,
SyncRepositoryData::class,
CheckPackageUrls::class
];

protected function schedule(Schedule $schedule)
{
$schedule->command('sync:packagist')->everyTwoHours();
Expand Down
16 changes: 6 additions & 10 deletions app/Events/CollaboratorClaimed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Events;

use App\Collaborator;
use App\User;
use App\Models\Collaborator;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand All @@ -12,13 +12,9 @@ class CollaboratorClaimed
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $collaborator;

public $user;

public function __construct(Collaborator $collaborator, User $user)
{
$this->collaborator = $collaborator;
$this->user = $user;
public function __construct(
public Collaborator $collaborator,
public User $user
) {
}
}
7 changes: 2 additions & 5 deletions app/Events/CollaboratorCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events;

use App\Collaborator;
use App\Models\Collaborator;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand All @@ -11,10 +11,7 @@ class CollaboratorCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $collaborator;

public function __construct(Collaborator $collaborator)
public function __construct(public Collaborator $collaborator)
{
$this->collaborator = $collaborator;
}
}
7 changes: 2 additions & 5 deletions app/Events/NewUserSignedUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events;

use App\User;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand All @@ -11,10 +11,7 @@ class NewUserSignedUp
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $user;

public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}
7 changes: 2 additions & 5 deletions app/Events/PackageCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events;

use App\Package;
use App\Models\Package;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand All @@ -11,10 +11,7 @@ class PackageCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $package;

public function __construct(Package $package)
public function __construct(public Package $package)
{
$this->package = $package;
}
}
2 changes: 1 addition & 1 deletion app/Events/PackageDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events;

use App\User;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand Down
1 change: 0 additions & 1 deletion app/Events/PackageRated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Events;

use App\Package;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand Down
Loading