Skip to content

Commit

Permalink
Formatting cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Jun 13, 2024
1 parent 5cbaeab commit 96a9619
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 46 deletions.
4 changes: 0 additions & 4 deletions src/AlwaysProp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

class AlwaysProp
{
/** @var mixed */
protected $value;

/**
* @param mixed $value
*/
public function __construct($value)
{
$this->value = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CreateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Inertia\Commands;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'inertia:middleware')]
class CreateMiddleware extends GeneratorCommand
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/StartSsr.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Inertia\Ssr\SsrException;
use Illuminate\Console\Command;
use Inertia\Ssr\BundleDetector;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'inertia:start-ssr')]
class StartSsr extends Command
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Inertia;

use Closure;
use Inertia\Support\Header;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Support\Header;
use Symfony\Component\HttpFoundation\Response;

class Middleware
Expand Down
16 changes: 7 additions & 9 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
namespace Inertia;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Inertia\Support\Header;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use GuzzleHttp\Promise\PromiseInterface;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceResponse;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Response as ResponseFactory;
use Inertia\Support\Header;

class Response implements Responsable
{
Expand All @@ -40,7 +40,6 @@ public function __construct(string $component, array $props, string $rootView =

/**
* @param string|array $key
* @param mixed $value
*
* @return $this
*/
Expand All @@ -57,7 +56,6 @@ public function with($key, $value = null): self

/**
* @param string|array $key
* @param mixed $value
*
* @return $this
*/
Expand Down Expand Up @@ -111,19 +109,19 @@ public function resolveProperties(Request $request, array $props): array
{
$isPartial = $request->header(Header::PARTIAL_COMPONENT) === $this->component;

if(! $isPartial) {
if (! $isPartial) {
$props = array_filter($this->props, static function ($prop) {
return ! ($prop instanceof LazyProp);
});
}

$props = $this->resolveArrayableProperties($props, $request);

if($isPartial && $request->hasHeader(Header::PARTIAL_ONLY)) {
if ($isPartial && $request->hasHeader(Header::PARTIAL_ONLY)) {
$props = $this->resolveOnly($request, $props);
}

if($isPartial && $request->hasHeader(Header::PARTIAL_EXCEPT)) {
if ($isPartial && $request->hasHeader(Header::PARTIAL_EXCEPT)) {
$props = $this->resolveExcept($request, $props);
}

Expand Down Expand Up @@ -168,7 +166,7 @@ public function resolveOnly(Request $request, array $props): array

$value = [];

foreach($only as $key) {
foreach ($only as $key) {
Arr::set($value, $key, data_get($props, $key));
}

Expand Down
13 changes: 2 additions & 11 deletions src/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Closure;
use Illuminate\Support\Arr;
use Inertia\Support\Header;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Response as BaseResponse;
use Inertia\Support\Header;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirect;

Expand All @@ -34,7 +34,6 @@ public function setRootView(string $name): void

/**
* @param string|array|Arrayable $key
* @param mixed $value
*/
public function share($key, $value = null): void
{
Expand All @@ -47,11 +46,6 @@ public function share($key, $value = null): void
}
}

/**
* @param mixed $default
*
* @return mixed
*/
public function getShared(string $key = null, $default = null)
{
if ($key) {
Expand Down Expand Up @@ -88,9 +82,6 @@ public function lazy(callable $callback): LazyProp
return new LazyProp($callback);
}

/**
* @param mixed $value
*/
public function always($value): AlwaysProp
{
return new AlwaysProp($value);
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use LogicException;
use Inertia\Ssr\Gateway;
use ReflectionException;
use Inertia\Support\Header;
use Illuminate\Http\Request;
use Inertia\Ssr\HttpGateway;
use Illuminate\Routing\Router;
Expand All @@ -13,7 +14,6 @@
use Inertia\Testing\TestResponseMacros;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse;
use Inertia\Support\Header;

class ServiceProvider extends BaseServiceProvider
{
Expand Down
2 changes: 0 additions & 2 deletions src/Testing/Concerns/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function hasAll($key): self
}

/**
* @param mixed $value
*
* @return $this
*/
public function has(string $key, $value = null, Closure $scope = null): self
Expand Down
7 changes: 4 additions & 3 deletions tests/AlwaysPropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Inertia\Tests;

use Illuminate\Http\Request;
use Inertia\AlwaysProp;
use Illuminate\Http\Request;

class AlwaysPropTest extends TestCase
{
Expand All @@ -25,8 +25,9 @@ public function test_can_accept_scalar_values(): void

public function test_can_accept_callables(): void
{
$callable = new class {
public function __invoke() {
$callable = new class() {
public function __invoke()
{
return 'An always value';
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LogicException;
use Inertia\Inertia;
use Inertia\AlwaysProp;
use Inertia\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;
Expand All @@ -12,7 +13,6 @@
use Illuminate\Support\Facades\Session;
use Inertia\Tests\Stubs\ExampleMiddleware;
use Illuminate\Session\Middleware\StartSession;
use Inertia\AlwaysProp;

class MiddlewareTest extends TestCase
{
Expand Down
10 changes: 5 additions & 5 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

use Inertia\Inertia;
use Inertia\LazyProp;
use Inertia\AlwaysProp;
use Inertia\ResponseFactory;
use Illuminate\Http\Response;
use Illuminate\Session\Store;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Request;
use Illuminate\Session\NullSessionHandler;
use Inertia\Tests\Stubs\ExampleMiddleware;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Session\NullSessionHandler;
use Illuminate\Session\Store;
use Inertia\AlwaysProp;

class ResponseFactoryTest extends TestCase
{
Expand Down Expand Up @@ -91,8 +91,8 @@ public function test_location_redirects_are_not_modified(): void
public function test_location_response_for_non_inertia_requests_using_redirect_response_with_existing_session_and_request_properties(): void
{
$redirect = new RedirectResponse('https://inertiajs.com');
$redirect->setSession($session = new Store('test', new NullSessionHandler));
$redirect->setRequest($request = new HttpRequest);
$redirect->setSession($session = new Store('test', new NullSessionHandler()));
$redirect->setRequest($request = new HttpRequest());
$response = (new ResponseFactory())->location($redirect);

$this->assertInstanceOf(RedirectResponse::class, $response);
Expand Down
6 changes: 3 additions & 3 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mockery;
use Inertia\LazyProp;
use Inertia\Response;
use Inertia\AlwaysProp;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\Fluent;
Expand All @@ -15,7 +16,6 @@
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Inertia\AlwaysProp;

class ResponseTest extends TestCase
{
Expand Down Expand Up @@ -400,9 +400,9 @@ public function test_always_props_are_included_on_partial_reload(): void
],
'errors' => new AlwaysProp(function () {
return [
'name' => 'The email field is required.'
'name' => 'The email field is required.',
];
})
}),
];

$response = new Response('User/Edit', $props, 'app', '123');
Expand Down
3 changes: 0 additions & 3 deletions tests/Stubs/ExampleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class ExampleMiddleware extends Middleware
{
/**
* @var mixed
*/
protected $version;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/FakeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FakeResource extends JsonResource
*
* @var string|null
*/
public static $wrap = null;
public static $wrap;

public function __construct(array $resource)
{
Expand Down

0 comments on commit 96a9619

Please sign in to comment.