Skip to content

Commit eeeba72

Browse files
authored
Merge pull request #153 from Lomkit/coderabbitai/docstrings/3541bef
📝 Add docstrings to `feature/laravel-12`
2 parents 3541bef + 7f71444 commit eeeba72

File tree

6 files changed

+86
-9
lines changed

6 files changed

+86
-9
lines changed

src/Actions/DispatchAction.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ public function dispatch($chunkCount)
109109
}
110110

111111
/**
112-
* Dispatch the given action.
112+
* Processes models in chunks using classic mode and dispatches an action for each set.
113113
*
114-
* @param int $chunkCount
114+
* The method builds a search query for the resource associated with the current request, applying
115+
* search criteria from the request input and removing any default result limits. It then processes
116+
* the query results in chunks (of size $chunkCount) by invoking the forModels method on each chunk.
117+
* Finally, it returns the query limit if one is set; otherwise, it returns the total count of models.
115118
*
116-
* @return int
119+
* @param int $chunkCount The number of models to process per chunk.
120+
*
121+
* @return int The effective result limit if set, or the total count of models.
117122
*/
118123
public function handleClassic(int $chunkCount)
119124
{

src/Http/Response.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ protected function buildGatesForModel(Model $model, Resource $resource, array $g
4141
);
4242
}
4343

44+
/**
45+
* Convert an Eloquent model into an array representation for the HTTP response.
46+
*
47+
* This method transforms the given model by selecting only the specified attributes and aggregates as defined in the request parameters or resource. If authorization gating is enabled and gate parameters are provided, it appends the corresponding authorization data. Additionally, it recursively processes any loaded relations—returning pivot data when applicable and mapping related models (or collections of models) using the resource’s configuration.
48+
*
49+
* @param Model $model The Eloquent model instance to be converted.
50+
* @param resource $resource The resource defining the fields and structure of the response.
51+
* @param array $requestArray Request parameters that control field selection, aggregates, and authorization gates.
52+
* @param Relation|null $relation Optional relation context for processing nested relationships.
53+
*
54+
* @return array The structured array representation of the model, including attributes and recursively processed relations.
55+
*/
4456
public function modelToResponse(Model $model, Resource $resource, array $requestArray, Relation $relation = null)
4557
{
4658
$currentRequestArray = $relation === null ? $requestArray : collect($requestArray['includes'] ?? [])

src/Query/Builder.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,32 @@ public function newQueryBuilder($parameters)
6363
return app()->make(QueryBuilder::class, $parameters);
6464
}
6565

66+
/**
67+
* Sets the security flag for the query builder.
68+
*
69+
* Toggling this flag disables or enables security checks during query building.
70+
*
71+
* @param bool $disable Set to true to disable security checks (default), or false to enable them.
72+
*
73+
* @return $this The current instance for method chaining.
74+
*/
6675
public function disableSecurity($disable = true)
6776
{
6877
$this->disableSecurity = $disable;
6978

7079
return $this;
7180
}
7281

82+
/**
83+
* Set whether to disable applying the default query limit.
84+
*
85+
* When disabled, the query will not enforce any default limit on the number of results,
86+
* allowing retrieval of all matching records unless a custom limit is specified.
87+
*
88+
* @param bool $disable True to disable the default limit, false to enable it.
89+
*
90+
* @return self Returns the current instance for chaining.
91+
*/
7392
public function disableDefaultLimit($disable = true)
7493
{
7594
$this->disableDefaultLimit = $disable;

src/Query/ScoutBuilder.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,23 @@ class ScoutBuilder implements QueryBuilder
1313
use Conditionable;
1414

1515
/**
16-
* Perform a search operation on the query builder.
16+
* Executes a search query using Laravel Scout with customizable criteria.
1717
*
18-
* @param array $parameters An array of search parameters.
18+
* This method configures the underlying search builder by setting the query text,
19+
* and conditionally applying filters, sort orders, and additional instructions based
20+
* on the provided parameters. It also enforces a limit on the number of results,
21+
* defaulting to 50 if no limit is specified. Any extra parameters, after excluding
22+
* reserved keys (filters, instructions, sorts, text, and limit), are forwarded to the
23+
* underlying search operation.
1924
*
20-
* @return \Laravel\Scout\Builder The modified query builder.
25+
* @param array $parameters An associative array of search criteria, which may include:
26+
* - 'text': The search query string.
27+
* - 'filters': An array of filter conditions.
28+
* - 'sorts': An array of sorting directives.
29+
* - 'instructions': Additional query instructions.
30+
* - 'limit': Maximum number of results to return (defaults to 50 if not provided).
31+
*
32+
* @return \Laravel\Scout\Builder The configured Scout query builder.
2133
*/
2234
public function search(array $parameters = [])
2335
{

src/Query/Traits/PerformSearch.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@
1010
trait PerformSearch
1111
{
1212
/**
13-
* Perform a search operation on the query builder.
13+
* Executes a modular search on the query builder based on provided parameters.
1414
*
15-
* @param array $parameters An array of search parameters.
15+
* This method first authorizes the view operation on the model and then, unless security is disabled,
16+
* applies a security-aware search query. It conditionally processes various search parameters to:
17+
* - Filter results via a nested subquery to prevent conflicts.
18+
* - Sort results using custom definitions if provided, or default ordering from the resource.
19+
* - Apply named scopes, instructions, includes, and aggregate functions.
20+
* - Limit the result set according to a specified limit or a default value of 50.
1621
*
17-
* @return Builder The modified query builder.
22+
* @param array $parameters An associative array of search parameters that may include:
23+
* - 'filters': Criteria for filtering the results.
24+
* - 'sorts': Definitions for ordering the results.
25+
* - 'scopes': Named scopes to refine the query.
26+
* - 'instructions': Additional instructions for query customization.
27+
* - 'includes': Related resources to include in the query.
28+
* - 'aggregates': Aggregate functions to apply on related data.
29+
* - 'limit': Maximum number of records to return.
30+
*
31+
* @return Builder The modified query builder with the applied search parameters.
1832
*/
1933
public function search(array $parameters = [])
2034
{

tests/Support/Rest/Resources/BelongsToManyResource.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public function relations(RestRequest $request): array
2323
];
2424
}
2525

26+
/**
27+
* Returns the list of field names for the resource.
28+
*
29+
* This method defines the fields that are part of the resource representation.
30+
*
31+
* @return array Array of field names.
32+
*/
2633
public function fields(RestRequest $request): array
2734
{
2835
return [
@@ -32,6 +39,14 @@ public function fields(RestRequest $request): array
3239
];
3340
}
3441

42+
/**
43+
* Returns an array of predefined pagination limit values.
44+
*
45+
* This method provides a fixed set of integer values that can be used to control the number
46+
* of items returned in paginated responses.
47+
*
48+
* @return int[] Array of allowed limit values.
49+
*/
3550
public function limits(RestRequest $request): array
3651
{
3752
return [

0 commit comments

Comments
 (0)