Skip to content

Commit

Permalink
AsCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Mar 12, 2024
1 parent ff8f1f7 commit eee23e1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/Console/ParallelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers;
use Illuminate\Support\Facades\Auth;
use Recca0120\LaravelParallel\ResponseIdentifier;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Response;

#[AsCommand(self::COMMAND_NAME)]
class ParallelCommand extends Command
{
use MakesHttpRequests;
Expand All @@ -35,7 +37,7 @@ class ParallelCommand extends Command
*/
protected $app;

public function __construct(Application $app = null)
public function __construct(?Application $app = null)
{
parent::__construct();
$this->setLaravel($app);
Expand All @@ -44,7 +46,7 @@ public function __construct(Application $app = null)
/**
* @return $this
*/
public function setLaravel(Application $app = null): self
public function setLaravel(?Application $app = null): self
{
$this->app = $app;

Expand Down
10 changes: 5 additions & 5 deletions src/ParallelArtisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ParallelArtisan
*/
private $process;

public function __construct(Request $request = null, array $env = [])
public function __construct(?Request $request = null, array $env = [])
{
$this->request = $request ?? Request::capture();
$this->setEnv($env);
Expand Down Expand Up @@ -90,14 +90,14 @@ private function parseParameters(array $parameters): array

$params = [];
foreach ($parameters as $param => $val) {
if ($param && is_string($param) && '-' === $param[0]) {
$glue = ('-' === $param[1]) ? '=' : ' ';
if ($param && is_string($param) && $param[0] === '-') {
$glue = ($param[1] === '-') ? '=' : ' ';
if (is_array($val)) {
foreach ($val as $v) {
$params[] = $param.('' !== $v ? $glue.$v : '');
$params[] = $param.($v !== '' ? $glue.$v : '');
}
} else {
$params[] = $param.('' !== $val ? $glue.$val : '');
$params[] = $param.($val !== '' ? $glue.$val : '');
}
} else {
$params[] = is_array($val) ? implode(' ', $val) : $val;
Expand Down
6 changes: 3 additions & 3 deletions src/ParallelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class ParallelRequest
{
use MakesHttpRequests;
use InteractsWithAuthentication;
use MakesHttpRequests;

/**
* @var Request|null
Expand All @@ -23,7 +23,7 @@ class ParallelRequest
/**
* AsyncRequest constructor.
*/
public function __construct(Request $request = null)
public function __construct(?Request $request = null)
{
$this->request = $request ?? Request::capture();
}
Expand All @@ -36,7 +36,7 @@ public static function setBinary(string $binary): void
/**
* @return $this
*/
public static function create(Request $request = null): self
public static function create(?Request $request = null): self
{
return new static($request);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ResponseIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function toResponse(): Response
*
* @license https://github.com/guzzle/psr7/blob/2.4.0/LICENSE
*
* @param string $message HTTP request or response to parse.
* @param string $message HTTP request or response to parse.
*/
private static function parseMessage(string $message): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Tests/Concerns/WithParallelPhyiscalDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ protected function refreshParallelPhyiscalDatabase(): void
}
}

/**
* @return void
*/
private function bindParallelRequest(): void
{
$this->app->bind(ParallelRequest::class, function () {
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/artisan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Orchestra\Testbench\Concerns\HandlesRoutes;
use Recca0120\LaravelParallel\Console\ParallelCommand;
use Recca0120\LaravelParallel\Tests\Fixtures\SetupDatabase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -118,6 +119,7 @@ $laravel = new class() {
}
};

#[AsCommand('echo')]
class EchoCommand extends Command
{
protected static $defaultName = 'echo';
Expand Down

0 comments on commit eee23e1

Please sign in to comment.