Skip to content

Commit

Permalink
Merge pull request #335 from lptn/support-more-helpers
Browse files Browse the repository at this point in the history
Support more helpers (+18 more)
  • Loading branch information
lptn authored Feb 26, 2023
2 parents 6a73324 + 3c6485c commit 0b42a51
Show file tree
Hide file tree
Showing 8 changed files with 597 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ protected function getStubsForVersion(string $version): array
{
[$majorVersion] = explode('.', $version);

return glob(dirname(__DIR__) . '/stubs/' . $majorVersion . '/*.stubphp');
return array_merge(
glob(dirname(__DIR__) . '/stubs/' . $majorVersion . '/*.stubphp'),
glob(dirname(__DIR__) . '/stubs/' . $majorVersion . '/**/*.stubphp'),
);
}

private function registerStubs(RegistrationInterface $registration): void
Expand Down
12 changes: 12 additions & 0 deletions stubs/9/Foundation/helpers.stubphp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/**
* Dispatch a command to its appropriate handler in the current process.
*
* @param object|callable $job
* @param mixed $handler
* @return mixed
*
* @deprecated Will be removed in a future Laravel version.
*/
function dispatch_now($job, $handler = null) {}
29 changes: 27 additions & 2 deletions stubs/Collections/helpers.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,34 @@
*/

// collect: nothing to stub
// data_fill: nothing to stub

/**
* Fill in data where it's missing.
*
* @template TTarget
*
* @param TTarget $target
* @param string|array $key
* @param mixed $value
* @return mixed
* @psalm-return TTarget is array ? array : TTarget
*/
function data_fill(&$target, $key, $value) {}

// data_get: nothing to stub
// data_set: nothing to stub

/**
* Set an item on an array or object using dot notation.
*
* @template TTarget
*
* @param TTarget $target
* @param string|array $key
* @param mixed $value
* @param bool $overwrite
* @psalm-return TTarget is array ? array : TTarget
*/
function data_set(&$target, $key, $value, $overwrite = true) {}

/**
* Get the first element of an array. Useful for method chaining.
Expand Down
162 changes: 156 additions & 6 deletions stubs/Foundation/helpers.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* Stubs for {@see https://github.com/laravel/framework/blob/master/src/Illuminate/Foundation/helpers.php}
*/

// abort: nothing to stub

/**
* Throw an HttpException with the given data if the given condition is true.
*
* @param bool $boolean
* @psalm-assert falsy $boolean
* @psalm-return ($boolean is false ? never-return : void )
* @param int $code
* @param \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int<400, 511> $code
* @param string $message
* @param array $headers
* @return void
Expand All @@ -21,6 +23,39 @@
function abort_if($boolean, $code, $message = '', array $headers = []) {}

/**
* Throw an HttpException with the given data unless the given condition is true.
*
* @param bool $boolean
* @param \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int<400, 511> $code
* @param string $message
* @param array $headers
* @return void
* @psalm-return ($boolean is true ? never-return : void )
* @psalm-assert !falsy $boolean
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
function abort_unless($boolean, $code, $message = '', array $headers = []) {}

/**
* Generate the URL to a controller action.
*
* @param callable-array|class-string $name
* @param mixed $parameters
* @param bool $absolute
* @return string
*/
function action($name, $parameters = [], $absolute = true) {}

// app: processed by Psalm handlers
// app_path: processed by Psalm handlers
// asset: nothing to stub
// auth: processed by Psalm handlers

/**
* Get the available auth instance.
*
* @param string|null $guard
* @return (
* $guard is null
Expand All @@ -30,6 +65,37 @@ function abort_if($boolean, $code, $message = '', array $headers = []) {}
*/
function auth($guard = null) {}

/**
* Create a new redirect response to the previous location.
*
* @param int<300, 308> $status
* @param array<string, mixed> $headers
* @param false|string $fallback
* @return \Illuminate\Http\RedirectResponse
*/
function back($status = 302, $headers = [], $fallback = false) {}

// base_path: processed by Psalm handlers

/**
* Hash the given value against the bcrypt algorithm.
*
* @param string $value
* @param array{rounds?: string, ...} $options
* @return non-empty-string
*/
function bcrypt($value, $options = []) {}

/**
* Begin broadcasting an event.
*
* @param object|null $event
* @return \Illuminate\Broadcasting\PendingBroadcast
*/
function broadcast($event = null) {}

// cache: processed by Psalm handlers

/**
* Get / set the specified configuration value.
*
Expand All @@ -41,6 +107,8 @@ function auth($guard = null) {}
*/
function config($key = null, $default = null) {}

// config_path: processed by Psalm handlers

/**
* Create a new cookie instance.
*
Expand All @@ -57,32 +125,83 @@ function config($key = null, $default = null) {}
*/
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = true, $raw = false, $sameSite = null) {}

// csrf_field: nothing to stub
// csrf_token: nothing to stub
// database_path: processed by Psalm handlers
// decrypt: nothing to stub

/**
* Dispatch a job to its appropriate handler.
*
* @param mixed $job
* @param object|callable $job
* @return ($job is \Closure ? \Illuminate\Foundation\Bus\PendingDispatch : \Illuminate\Foundation\Bus\PendingDispatch)
*/
function dispatch($job) {}

/**
* Dispatch a command to its appropriate handler in the current process.
*
* Queueable jobs will be dispatched to the "sync" queue.
*
* @param object|callable $job
* @param mixed $handler
* @return mixed
*/
function dispatch_sync($job, $handler = null) {}

// encrypt: nothing to stub

/**
* Dispatch an event and call the listeners.
*
* @param string|object $event
* @param mixed $payload
* @param bool $halt
* @return list<scalar|array|object>|scalar|array|object|null
*/
function event(...$args) {}

// fake: nothing to stub
// info: nothing to stub

/**
* Log a debug message to the logs.
*
* @param string|null $message
* @param array $context
* @return \Illuminate\Log\LogManager|null
* @psalm-return (func_num_args() is 0 ? \Illuminate\Log\LogManager : void)
* @psalm-return ($message is null ? \Illuminate\Log\LogManager : null)
*/
function logger($message = null, array $context = []) {}

// lang_path: processed by Psalm handlers

/**
* Get a log driver instance.
*
* @param string|null $driver
* @return ($driver is null ? \Illuminate\Log\LogManager : \Psr\Log\LoggerInterface)
* @return ($driver is null ? \Illuminate\Log\LogManager : \Psr\Log\LoggerInterface&\Illuminate\Log\Logger)
*/
function logs($driver = null) {}

// method_field: nothing to stub
// mix: nothing to stub
// now: nothing to stub
// old: nothing to stub
// policy: nothing to stub

/**
* Handle a Precognition controller hook.
*
* @template TCallableReturn
*
* @param null|callable(callable(\Illuminate\Http\Response=, mixed=): void): TCallableReturn $callable
* @return TCallableReturn
*/
function precognitive($callable = null) {}

// public_path: processed by Psalm handlers

/**
* @param string|null $to
* @param int<300, 308> $status
Expand All @@ -92,6 +211,10 @@ function logs($driver = null) {}
*/
function redirect($to = null, $status = 302, $headers = [], $secure = null) {}

// report: nothing to stub
// report_if: nothing to stub
// report_unless: nothing to stub

/**
* Get an instance of the current request or an input item from the request.
*
Expand All @@ -102,6 +225,8 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null) {}
function request($key = null, $default = null) {}

/**
* Catch a potential exception and return a default value.
*
* @template TValue
* @template TDefault
* @template TDefaultCallableReturn
Expand All @@ -113,6 +238,9 @@ function request($key = null, $default = null) {}
*/
function rescue(callable $callback, $rescue = null, $report = true) {}

// resolve: processed by Psalm handlers
// resource_path: processed by Psalm handlers

/**
* Return a new response from the application.
*
Expand All @@ -124,6 +252,19 @@ function rescue(callable $callback, $rescue = null, $report = true) {}
*/
function response($content = '', $status = 200, array $headers = []) {}

/**
* Generate the URL to a named route.
*
* @param string $name
* @param scalar|array|null $parameters
* @param bool $absolute
* @return string
*/
function route($name, $parameters = [], $absolute = true) {}

// secure_asset: nothing to stub
// secure_url: nothing to stub

/**
* Get / set the specified session value.
*
Expand All @@ -135,6 +276,8 @@ function response($content = '', $status = 200, array $headers = []) {}
*/
function session($key = null, $default = null) {}

// storage_path: nothing to stub

/**
* Create a new redirect response to a named route.
*
Expand All @@ -146,6 +289,10 @@ function session($key = null, $default = null) {}
*/
function to_route($route, $parameters = [], $status = 302, $headers = []) {}

// today: nothing to stub
// trans: processed by Psalm handlers
// trans_choice: processed by Psalm handlers

/**
* Translate the given message.
*
Expand All @@ -158,6 +305,7 @@ function __($key = null, $replace = [], $locale = null) {}

/**
* Generate a url for the application.
*
* @param string|null $path
* @param mixed $parameters
* @param bool|null $secure
Expand All @@ -177,9 +325,11 @@ function url($path = null, $parameters = [], $secure = null) {}
function validator(array $data = [], array $rules = [], array $messages = [], array $customAttributes = []) {}

/**
* Get the evaluated view contents for the given view.
*
* @param string|null $view
* @param \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<string, mixed> $data
* @param \Illuminate\Contracts\Support\Arrayable<string, mixed>|array<string, mixed> $data
* @param array<string, mixed> $mergeData
* @return ($view is null ? \Illuminate\Contracts\View\Factory : \Illuminate\Contracts\View\View)
* @return ($view is null ? \Illuminate\Contracts\View\Factory : (\Illuminate\View\View|\Illuminate\Contracts\View\View))
*/
function view($view = null, $data = [], $mergeData = []) {}
Loading

0 comments on commit 0b42a51

Please sign in to comment.