Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Aug 15, 2024
1 parent 1a691bb commit 5a2abf6
Show file tree
Hide file tree
Showing 28 changed files with 1,472 additions and 68 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
title_goes_here [![required php version](https://img.shields.io/packagist/php-v/open-southeners/packagist_package_here)](https://www.php.net/supported-versions.php) [![codecov](https://codecov.io/gh/open-southeners/packagist_package_here/branch/main/graph/badge.svg?token=codecov_badge_token)](https://codecov.io/gh/open-southeners/packagist_package_here) [![Edit on VSCode online](https://img.shields.io/badge/vscode-edit%20online-blue?logo=visualstudiocode)](https://vscode.dev/github/open-southeners/packagist_package_here)
Extended Laravel [![required php version](https://img.shields.io/packagist/php-v/open-southeners/extended-laravel)](https://www.php.net/supported-versions.php) [![codecov](https://codecov.io/gh/open-southeners/extended-laravel/branch/main/graph/badge.svg?token=zx68fmehzI)](https://codecov.io/gh/open-southeners/extended-laravel) [![Edit on VSCode online](https://img.shields.io/badge/vscode-edit%20online-blue?logo=visualstudiocode)](https://vscode.dev/github/open-southeners/extended-laravel)
===

and_description_here

**Search & replace:**

| Keys | Replacement |
| --------------------------------------------------------- | ------------------------------------------------------------- |
| `title_goes_here` | Fancy title from the repository (only README and stuff) |
| `and_description_here` | Short package description (only for README and composer.json) |
| `packagist_package_here` | Packagist (composer) published package name |
| `codecov_badge_token` | Codecov token for the coverage badge |
| `OpenSoutheners\PhpPackage`, `OpenSoutheners\\PhpPackage` | PSR-0 and PSR-4 complaint package namespace |
Extended Laravel framework functionalities and out-of-the-box stuff

## Getting started

```
composer require open-southeners/packagist_package_here
composer require open-southeners/extended-laravel
```

## Partners
Expand All @@ -25,4 +15,4 @@ composer require open-southeners/packagist_package_here

## License

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
111 changes: 62 additions & 49 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,65 @@
{
"name": "open-southeners/packagist_package_here",
"description": "and_description_here",
"license": "MIT",
"keywords": [
"open-southeners"
],
"authors": [
{
"name": "Ruben Robles",
"email": "[email protected]",
"homepage": "https://d8vjork.com"
}
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/open-southeners"
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"larastan/larastan": "^2.0",
"orchestra/testbench": "^8.0 || ^9.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^10.0"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OpenSoutheners\\PhpPackage\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"OpenSoutheners\\PhpPackage\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
"name": "open-southeners/packagist_package_here",
"description": "and_description_here",
"license": "MIT",
"keywords": [
"open-southeners",
"laravel",
"utilities",
"php8",
"php"
],
"authors": [
{
"name": "Ruben Robles",
"email": "[email protected]",
"homepage": "https://d8vjork.com"
}
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/open-southeners"
}
],
"require": {
"php": "^8.1",
"open-southeners/byte-unit-converter": "^3.0",
"open-southeners/extended-php": "^1.0"
},
"require-dev": {
"larastan/larastan": "^2.0",
"laravel/cashier": "^15.0",
"laravel/passport": "^12.0",
"laravel/pint": "^1.5",
"laravel/socialite": "^5.0",
"orchestra/testbench": "^8.0 || ^9.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^10.0"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OpenSoutheners\\ExtendedLaravel\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"OpenSoutheners\\ExtendedLaravel\\Tests\\": "tests"
},
"extra": {
"laravel": {
"providers": [
"OpenSoutheners\\PhpPackage\\ServiceProvider"
]
}
"files": [
"src/Models/functions.php"
]
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"OpenSoutheners\\ExtendedLaravel\\ServiceProvider"
]
}
}
}
}
114 changes: 114 additions & 0 deletions src/AboutCommandIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace OpenSoutheners\ExtendedLaravel;

use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Laravel\Cashier\Cashier;
use Laravel\Passport\Passport;
use Laravel\Socialite\Contracts\Factory;
use ReflectionClass;
use Stripe\Stripe;

class AboutCommandIntegration
{
public static function register()

Check failure on line 16 in src/AboutCommandIntegration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method OpenSoutheners\ExtendedLaravel\AboutCommandIntegration::register() has no return type specified.
{
if (! class_exists(AboutCommand::class)) {
return;
}

(new static)

Check failure on line 22 in src/AboutCommandIntegration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unsafe usage of new static().
->printExtendedDriversInfo()
->printIntegrationsInfo()
->printCashierInfo();
}

private function getUserConfigured(string $variable, string $value): string
{
$userConfiguredValue = env($variable);

if (! empty($userConfiguredValue)) {
return sprintf('<fg=yellow;options=bold>%s</>', $value);
}

return $value;
}

public function printExtendedDriversInfo(): self
{
AboutCommand::add('Drivers', fn (): array => [
'Storage' => $this->getUserConfigured('FILESYSTEM_DISK', Storage::getDefaultDriver()),
]);

return $this;
}

public function printIntegrationsInfo(): self
{
AboutCommand::add('Integrations', function (): array {
$integrations = [];

if (class_exists(Factory::class)) {
$socialiteManager = app(Factory::class);

$providers = array_keys((new ReflectionClass($socialiteManager))

Check failure on line 56 in src/AboutCommandIntegration.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $array of function array_keys expects array, mixed given.
->getProperty('customCreators')
->getValue($socialiteManager));

$integrations['Socialite'] = sprintf(
'%s %s',
! empty($providers) ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>',
! empty($providers) ? Str::wrap(implode(', ', $providers), '(', ')') : ''
);
}

if (class_exists(Passport::class)) {
$integrations['Passport'] = (
! empty(env('PASSPORT_PRIVATE_KEY')) && ! empty(env('PASSPORT_PUBLIC_KEY'))
|| (Passport::keyPath('oauth-public.key') && Passport::keyPath('oauth-private.key')
)) ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>';
}

return $integrations;
});

return $this;
}

public function printCashierInfo(): self
{
$cashierDriver = match (true) {
class_exists('Laravel\Cashier\Cashier') => 'Stripe',
class_exists('Laravel\Paddle\Cashier') => 'Paddle',
default => false,
};

if (! $cashierDriver) {
return $this;
}

AboutCommand::add('Cashier', function () use ($cashierDriver): array {
$infoArray = [
'Driver' => $cashierDriver,
'Cashier version' => Cashier::VERSION,
'Customer model' => Cashier::$customerModel,
'Enables routes' => Cashier::$registersRoutes ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>',
'Enables taxes' => Cashier::$calculatesTaxes ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>',
'Enables incomplete subscriptions' => Cashier::$deactivateIncomplete ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>',
'Enables past due subscriptions' => Cashier::$deactivatePastDue ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>',
];

if ($cashierDriver === 'Stripe') {
$infoArray['Enabled'] = Cashier::stripe()->getApiKey() ? '<fg=green;options=bold>YES</>' : '<fg=yellow;options=bold>NO</>';
$infoArray['Stripe SDK version'] = Stripe::VERSION;
$infoArray['Stripe API version'] = Cashier::STRIPE_VERSION;
}

return $infoArray;
});

return $this;
}
}
58 changes: 58 additions & 0 deletions src/Console/Commands/BatchesQueueCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace OpenSoutheners\ExtendedLaravel\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;

class BatchesQueueCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:batches';

/**
* The console command description.
*
* @var string
*/
protected $description = 'List queued job batches';

/**
* Execute the console command.
*/
public function handle(): int
{
$columns = ['id', 'name', 'completion', 'total_jobs', 'pending_jobs', 'failed_job_ids', 'created_at', 'finished_at'];

$this->table(
Arr::exceptValues($columns, ['total_jobs', 'pending_jobs']),

Check failure on line 34 in src/Console/Commands/BatchesQueueCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined static method Illuminate\Support\Arr::exceptValues().
DB::connection(config('queue.batching.database'))

Check failure on line 35 in src/Console/Commands/BatchesQueueCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $name of static method Illuminate\Database\DatabaseManager::connection() expects string|null, mixed given.
->table(config('queue.batching.table', 'job_batches'))

Check failure on line 36 in src/Console/Commands/BatchesQueueCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $table of method Illuminate\Database\Connection::table() expects Closure|Illuminate\Contracts\Database\Query\Expression|Illuminate\Database\Query\Builder|string, mixed given.
->get(Arr::exceptValues($columns, ['completion']))

Check failure on line 37 in src/Console/Commands/BatchesQueueCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined static method Illuminate\Support\Arr::exceptValues().
->map(function (\stdClass $jobBatch) {

Check failure on line 38 in src/Console/Commands/BatchesQueueCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $callback of method Illuminate\Support\Collection<(int|string),mixed>::map() expects callable(mixed, int|string): non-empty-array, Closure(stdClass): non-empty-array given.
$jobBatch = (array) $jobBatch;

$jobBatch['total_jobs'] = sprintf('%d%%', $jobBatch['pending_jobs'] / $jobBatch['total_jobs'] * 100);

unset($jobBatch['pending_jobs']);

$jobBatch['created_at'] = Carbon::createFromTimestamp($jobBatch['created_at']);

if ($jobBatch['finished_at']) {
$jobBatch['finished_at'] = Carbon::createFromTimestamp($jobBatch['finished_at']);
}

return $jobBatch;
})
->all(),
);

return 0;
}
}
Loading

0 comments on commit 5a2abf6

Please sign in to comment.