Skip to content

Commit ebb4688

Browse files
authored
Add missing parameter types and return types to method signatures. (#8215)
Update method signatures across documentation to include proper type declarations matching the CakePHP 5.x source code. Fixes untyped parameters, missing return types, and incorrect class references in RouteBuilder, CacheEngine, Session, Debugger, ServerRequest, Response, Mailer, and other documented APIs.
1 parent c772dc8 commit ebb4688

13 files changed

Lines changed: 57 additions & 57 deletions

File tree

docs/en/console-commands/input-output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ The `BannerHelper` was added in 5.1
179179

180180
## Getting User Input
181181

182-
`method` Cake\\Console\\ConsoleIo::**ask**($question, $choices = null, $default = null): string
182+
`method` Cake\\Console\\ConsoleIo::**ask**(string $question, ?array $choices = null, ?string $default = null): string
183183

184184
When building interactive console applications you'll need to get user input.
185185
CakePHP provides a way to do this:
@@ -196,7 +196,7 @@ Selection validation is case-insensitive.
196196

197197
## Creating Files
198198

199-
`method` Cake\\Console\\ConsoleIo::**createFile**($path, $contents): bool
199+
`method` Cake\\Console\\ConsoleIo::**createFile**(string $path, string $contents): bool
200200

201201
Creating files is often important part of many console commands that help
202202
automate development and deployment. The `createFile()` method gives you

docs/en/controllers/request-response.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ are also all found in the routing parameters:
7575

7676
### Query String Parameters
7777

78-
`method` Cake\\Http\\ServerRequest::**getQuery**($name, $default = null): mixed
78+
`method` Cake\\Http\\ServerRequest::**getQuery**(?string $name = null, mixed $default = null): mixed
7979

8080
Query string parameters can be read using the `getQuery()` method:
8181

@@ -135,7 +135,7 @@ Casting functions were added.
135135

136136
### Request Body Data
137137

138-
`method` Cake\\Http\\ServerRequest::**getData**($name, $default = null): mixed
138+
`method` Cake\\Http\\ServerRequest::**getData**(?string $name = null, mixed $default = null): mixed
139139

140140
All POST data normally available through PHP's `$_POST` global variable can be
141141
accessed using `Cake\Http\ServerRequest::getData()`. For example:
@@ -210,7 +210,7 @@ necessary. In an CLI environment, where the concept of uploading files doesn't
210210
exist, it will allow to move the file that you've referenced irrespective of its
211211
origins, which makes testing file uploads possible.
212212

213-
`method` Cake\\Http\\ServerRequest::**getUploadedFile**($path): UploadedFileInterface|null
213+
`method` Cake\\Http\\ServerRequest::**getUploadedFile**(string $path): UploadedFileInterface|null
214214

215215
Returns the uploaded file at a specific path. The path uses the same dot syntax as the
216216
`Cake\Http\ServerRequest::getData()` method:
@@ -296,7 +296,7 @@ types making the parsed data available in `$request->getData()` and
296296

297297
### Environment Variables (from $_SERVER and $_ENV)
298298

299-
`method` Cake\\Http\\ServerRequest::**getEnv**($key, $default = null): string|null
299+
`method` Cake\\Http\\ServerRequest::**getEnv**(string $key, ?string $default = null): string|null
300300

301301
`ServerRequest::getEnv()` is a wrapper for `getenv()` global function and acts as
302302
a getter for environment variables without possible undefined keys:
@@ -311,7 +311,7 @@ To access all the environment variables in a request use `getServerParams()`:
311311
$env = $this->request->getServerParams();
312312
```
313313

314-
`method` Cake\\Http\\ServerRequest::**withEnv**($key, $value): static
314+
`method` Cake\\Http\\ServerRequest::**withEnv**(string $key, string $value): static
315315

316316
`ServerRequest::withEnv()` is a wrapper for `putenv()` global function and acts as
317317
a setter for environment variables without having to modify globals
@@ -368,7 +368,7 @@ $base = $request->getAttribute('webroot');
368368

369369
### Checking Request Conditions
370370

371-
`method` Cake\\Http\\ServerRequest::**is**($type, $args...): bool
371+
`method` Cake\\Http\\ServerRequest::**is**(array|string $type, mixed ...$args): bool
372372

373373
The request object provides a way to inspect certain conditions in a given
374374
request. By using the `is()` method you can check a number of common
@@ -395,7 +395,7 @@ detectors. There are different types of detectors that you can create:
395395
to handle the check. The callback will receive the request object as its only
396396
parameter.
397397

398-
`method` Cake\\Http\\ServerRequest::**addDetector**($name, $options): void
398+
`method` Cake\\Http\\ServerRequest::**addDetector**(string $name, Closure|array $options): void
399399

400400
Some examples would be:
401401

@@ -492,7 +492,7 @@ to use the session object.
492492

493493
### Host and Domain Name
494494

495-
`method` Cake\\Http\\ServerRequest::**domain**($tldLength = 1): string
495+
`method` Cake\\Http\\ServerRequest::**domain**(int $tldLength = 1): string
496496

497497
Returns the domain name your application is running on:
498498

@@ -501,7 +501,7 @@ Returns the domain name your application is running on:
501501
echo $request->domain();
502502
```
503503

504-
`method` Cake\\Http\\ServerRequest::**subdomains**($tldLength = 1): array
504+
`method` Cake\\Http\\ServerRequest::**subdomains**(int $tldLength = 1): array
505505

506506
Returns the subdomains your application is running on as an array:
507507

@@ -532,7 +532,7 @@ echo $request->getMethod();
532532

533533
### Restricting Which HTTP method an Action Accepts
534534

535-
`method` Cake\\Http\\ServerRequest::**allowMethod**($methods): bool
535+
`method` Cake\\Http\\ServerRequest::**allowMethod**(array|string $methods): bool
536536

537537
Set allowed HTTP methods. If not matched, will throw
538538
`MethodNotAllowedException`. The 405 response will include the required
@@ -566,7 +566,7 @@ $hasAcceptHeader = $this->request->hasHeader('Accept');
566566
While some apache installs don't make the `Authorization` header accessible,
567567
CakePHP will make it available through apache specific methods as required.
568568

569-
`method` Cake\\Http\\ServerRequest::**referer**($local = true): string|null
569+
`method` Cake\\Http\\ServerRequest::**referer**(bool $local = true): string|null
570570

571571
Returns the referring address for the request.
572572

@@ -608,7 +608,7 @@ proxy.
608608

609609
### Checking Accept Headers
610610

611-
`method` Cake\\Http\\ServerRequest::**accepts**($type = null): array|bool
611+
`method` Cake\\Http\\ServerRequest::**accepts**(?string $type = null): array|bool
612612

613613
Find out which content types the client accepts, or check whether it accepts a
614614
particular type of content.
@@ -625,7 +625,7 @@ Check for a single type:
625625
$acceptsJson = $this->request->accepts('application/json');
626626
```
627627

628-
`method` Cake\\Http\\ServerRequest::**acceptLanguage**($language = null): array|bool
628+
`method` Cake\\Http\\ServerRequest::**acceptLanguage**(?string $language = null): array|bool
629629

630630
Get all the languages accepted by the client,
631631
or check whether a specific language is accepted.
@@ -717,7 +717,7 @@ tasks such as:
717717

718718
### Dealing with Content Types
719719

720-
`method` Cake\\Http\\Response::**withType**($contentType = null): static
720+
`method` Cake\\Http\\Response::**withType**(string $contentType): static
721721

722722
You can control the Content-Type of your application's responses with
723723
`Cake\Http\Response::withType()`. If your application needs to deal
@@ -836,7 +836,7 @@ redirect location header.
836836

837837
### Setting the Body
838838

839-
`method` Cake\\Http\\Response::**withStringBody**($string): static
839+
`method` Cake\\Http\\Response::**withStringBody**(string $string): static
840840

841841
To set a string as the response body, do the following:
842842

@@ -891,7 +891,7 @@ $response = $response->withBody($stream);
891891

892892
### Setting the Character Set
893893

894-
`method` Cake\\Http\\Response::**withCharset**($charset): static
894+
`method` Cake\\Http\\Response::**withCharset**(string $charset): static
895895

896896
Sets the charset that will be used in the response:
897897

@@ -919,7 +919,7 @@ public function index()
919919
> Disabling caching from SSL domains while trying to send
920920
> files to Internet Explorer can result in errors.
921921
922-
`method` Cake\\Http\\Response::**withCache**($since, $time = '+1 day'): static
922+
`method` Cake\\Http\\Response::**withCache**(string $since, string $time = '+1 day'): static
923923

924924
You can also tell clients that you want them to cache responses. By using
925925
`Cake\Http\Response::withCache()`:
@@ -957,7 +957,7 @@ or reverse proxy caching.
957957

958958
#### The Cache Control Header
959959

960-
`method` Cake\\Http\\Response::**withSharable**($public, $time = null): static
960+
`method` Cake\\Http\\Response::**withSharable**(bool $public, ?int $time = null): static
961961

962962
Used under the expiration model, this header contains multiple indicators that
963963
can change the way browsers or proxies use the cached content. A
@@ -998,7 +998,7 @@ the `Cache-Control` header.
998998

999999
#### The Expiration Header
10001000

1001-
`method` Cake\\Http\\Response::**withExpires**($time): static
1001+
`method` Cake\\Http\\Response::**withExpires**(DateTimeInterface|string $time): static
10021002

10031003
You can set the `Expires` header to a date and time after which the response
10041004
is no longer considered fresh. This header can be set using the
@@ -1016,7 +1016,7 @@ be parsed by the `DateTime` class.
10161016

10171017
#### The Etag Header
10181018

1019-
`method` Cake\\Http\\Response::**withEtag**($tag, $weak = false): static
1019+
`method` Cake\\Http\\Response::**withEtag**(string $tag, bool $weak = false): static
10201020

10211021
Cache validation in HTTP is often used when content is constantly changing, and
10221022
asks the application to only generate the response contents if the cache is no
@@ -1059,7 +1059,7 @@ public function index()
10591059
10601060
#### The Last Modified Header
10611061

1062-
`method` Cake\\Http\\Response::**withModified**($time): static
1062+
`method` Cake\\Http\\Response::**withModified**(DateTimeInterface|string $time): static
10631063

10641064
Also, under the HTTP cache validation model, you can set the `Last-Modified`
10651065
header to indicate the date and time at which the resource was modified for the
@@ -1085,7 +1085,7 @@ public function view()
10851085

10861086
#### The Vary Header
10871087

1088-
`method` Cake\\Http\\Response::**withVary**($header): static
1088+
`method` Cake\\Http\\Response::**withVary**(string $header): static
10891089

10901090
In some cases, you might want to serve different content using the same URL.
10911091
This is often the case if you have a multilingual page or respond with different
@@ -1100,7 +1100,7 @@ $response = $this->response->withVary('Accept-Language');
11001100

11011101
#### Sending Not-Modified Responses
11021102

1103-
`method` Cake\\Http\\Response::**isNotModified**(Request $request): bool
1103+
`method` Cake\\Http\\Response::**isNotModified**(ServerRequest $request): bool
11041104

11051105
Compares the cache headers for the request object with the cache header from the
11061106
response and determines whether it can still be considered fresh. If so, deletes

docs/en/core-libraries/caching.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,19 +672,19 @@ The required API for a CacheEngine is
672672

673673
`class` Cake\\Cache\\**CacheEngine**
674674

675-
`method` Cake\\Cache\\CacheEngine::**write**($key, $value)
675+
`method` Cake\\Cache\\CacheEngine::**write**(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
676676

677-
`method` Cake\\Cache\\CacheEngine::**read**($key)
677+
`method` Cake\\Cache\\CacheEngine::**read**(string $key, mixed $default = null): mixed
678678

679-
`method` Cake\\Cache\\CacheEngine::**delete**($key): bool
679+
`method` Cake\\Cache\\CacheEngine::**delete**(string $key): bool
680680

681-
`method` Cake\\Cache\\CacheEngine::**clear**($check): bool
681+
`method` Cake\\Cache\\CacheEngine::**clear**(): bool
682682

683-
`method` Cake\\Cache\\CacheEngine::**clearGroup**($group): bool
683+
`method` Cake\\Cache\\CacheEngine::**clearGroup**(string $group): bool
684684

685-
`method` Cake\\Cache\\CacheEngine::**decrement**($key, $offset = 1): int|false
685+
`method` Cake\\Cache\\CacheEngine::**decrement**(string $key, int $offset = 1): int|false
686686

687-
`method` Cake\\Cache\\CacheEngine::**increment**($key, $offset = 1): int|false
687+
`method` Cake\\Cache\\CacheEngine::**increment**(string $key, int $offset = 1): int|false
688688

689689
## Cache Events
690690

docs/en/core-libraries/email.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ you want the filenames to appear in the recipient's mail client:
300300

301301
### Mailer::addAttachment()
302302

303-
`method` Cake\\Mailer\\Mailer::**addAttachment**(\\Psr\\Http\\Message\\UploadedFileInterface|string $path, ?string $name, ?string $mimetype, ?string $contentId, ?bool $contentDisposition)
303+
`method` Cake\\Mailer\\Mailer::**addAttachment**(\\Psr\\Http\\Message\\UploadedFileInterface|string $path, ?string $name = null, ?string $mimetype = null, ?string $contentId = null, ?bool $contentDisposition = null): static
304304

305305
You can also add attachments using the `addAttachment()` method.
306306

@@ -546,7 +546,7 @@ query string arguments.
546546

547547
### Mailer::drop()
548548

549-
`static` Cake\\Mailer\\Mailer::**drop**($key)
549+
`static` Cake\\Mailer\\Mailer::**drop**(string $config): bool
550550

551551
Once configured, transports cannot be modified. In order to modify a transport
552552
you must first drop it and then reconfigure it.

docs/en/core-libraries/httpclient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ $this->mockClientDelete(/* ... */);
596596

597597
### Response::newClientResponse()
598598

599-
`method` Cake\\Http\\TestSuite\\Response::**newClientResponse**(int $code = 200, array $headers = [], string $body = '')
599+
`method` Cake\\Http\\TestSuite\\Response::**newClientResponse**(int $code = 200, array $headers = [], string $body = ''): Cake\\Http\\Client\\Response
600600

601601
As seen above you can use the `newClientResponse()` method to create responses
602602
for the requests your application will make. The headers need to be a list of

docs/en/core-libraries/logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ appropriate log level.
533533
534534
### Log::log()
535535

536-
`method` Cake\\Log\\Log::**log**($msg, $level = LOG_ERR): bool
536+
`method` Cake\\Log\\Log::**log**(string $msg, string|int $level = LOG_ERR): bool
537537

538538
## Using Monolog
539539

docs/en/development/debugging.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The `Debugger.editorBasePath` configure option was added.
6969

7070
## Outputting Values
7171

72-
`static` Cake\\Error\\Debugger::**dump**($var, $depth = 3): void
72+
`static` Cake\\Error\\Debugger::**dump**(mixed $var, int $maxDepth = 3): void
7373

7474
Dump prints out the contents of a variable. It will print out all
7575
properties and methods (if any) of the supplied variable:
@@ -118,7 +118,7 @@ output masks.
118118

119119
## Logging With Stack Traces
120120

121-
`static` Cake\\Error\\Debugger::**log**($var, $level = 7, $depth = 3): void
121+
`static` Cake\\Error\\Debugger::**log**(mixed $var, string|int $level = 'debug', int $maxDepth = 3): void
122122

123123
Creates a detailed stack trace log at the time of invocation. The
124124
`log()` method prints out data similar to that done by
@@ -128,7 +128,7 @@ writable by the web server for `log()` to work correctly.
128128

129129
## Generating Stack Traces
130130

131-
`static` Cake\\Error\\Debugger::**trace**($options): array|string
131+
`static` Cake\\Error\\Debugger::**trace**(array $options = []): array|string
132132

133133
Returns the current stack trace. Each line of the trace includes
134134
the calling method, including which file and line the call
@@ -151,7 +151,7 @@ the order of currently running functions (stack frames).
151151

152152
## Getting an Excerpt From a File
153153

154-
`static` Cake\\Error\\Debugger::**excerpt**($file, $line, $context): array
154+
`static` Cake\\Error\\Debugger::**excerpt**(string $file, int $line, int $context = 2): array
155155

156156
Grab an excerpt from the file at `$path` (which is an absolute
157157
filepath), highlights line number `$line` with `$context` number of
@@ -176,7 +176,7 @@ Although this method is used internally, it can be handy if you're
176176
creating your own error messages or log entries for custom
177177
situations.
178178

179-
`static` Debugger::**getType**($var): string
179+
`static` Cake\\Error\\Debugger::**getType**(mixed $var): string
180180

181181
Get the type of a variable. Objects will return their class name
182182

docs/en/development/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ In addition, CakePHP uses the following exceptions:
555555
These exception classes all extend `Exception`.
556556
By extending Exception, you can create your own 'framework' errors.
557557

558-
`method` Class::**responseHeader**($header = null, $value = null)
558+
`method` Cake\\Http\\Exception\\HttpException::**setHeader**(string $header, array|string|null $value = null): void
559559

560560
All Http and Cake exceptions extend the Exception class, which has a method
561561
to add headers to the response. For instance when throwing a 405

docs/en/development/routing.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ named. Nameless routes will not have the `_namePrefix` applied to them.
681681

682682
### Prefix Routing
683683

684-
`static` Cake\\Routing\\RouteBuilder::**prefix**($name, $callback)
684+
`static` Cake\\Routing\\RouteBuilder::**prefix**(string $name, Closure|array $params = [], ?Closure $callback = null): static
685685

686686
Many applications require an administration section where
687687
privileged users can make changes. This is often done through a
@@ -824,7 +824,7 @@ This would link to a controller with the namespace `App\Controller\Admin\MyPrefi
824824
825825
### Plugin Routing
826826

827-
`static` Cake\\Routing\\RouteBuilder::**plugin**($name, $options = [], $callback)
827+
`static` Cake\\Routing\\RouteBuilder::**plugin**(string $name, Closure|array $options = [], ?Closure $callback = null): static
828828

829829
Routes for [Plugins](../plugins) should be created using the `plugin()`
830830
method. This method creates a new routing scope for the plugin's routes:
@@ -987,7 +987,7 @@ echo Router::url([
987987

988988
### Routing File Extensions
989989

990-
`method` Cake\\Routing\\RouteBuilder::**setExtensions**(array|string $extensions)
990+
`method` Cake\\Routing\\RouteBuilder::**setExtensions**(array|string $extensions): static
991991

992992
To handle different file extensions in your URLs, you can define the extensions
993993
using the `Cake\Routing\RouteBuilder::setExtensions()` method:
@@ -1410,9 +1410,9 @@ Since `5` has a numeric key, it is treated as a passed argument.
14101410

14111411
## Generating URLs
14121412

1413-
`static` Cake\\Routing\\RouteBuilder::**url**($url = null, $full = false)
1413+
`static` Cake\\Routing\\Router::**url**(Psr\\Http\\Message\\UriInterface|array|string|null $url = null, bool $full = false): string
14141414

1415-
`static` Cake\\Routing\\RouteBuilder::**reverse**($params, $full = false)
1415+
`static` Cake\\Routing\\Router::**reverse**(Cake\\Http\\ServerRequest|array $params, bool $full = false): string
14161416

14171417
Generating URLs or Reverse routing is a feature in CakePHP that is used to
14181418
allow you to change your URL structure without having to modify all your code.
@@ -1793,7 +1793,7 @@ standard `plugin syntax`.
17931793

17941794
### Default Route Class
17951795

1796-
`static` Cake\\Routing\\RouteBuilder::**setRouteClass**($routeClass = null)
1796+
`method` Cake\\Routing\\RouteBuilder::**setRouteClass**(string $routeClass): static
17971797

17981798
If you want to use an alternate route class for your routes besides the
17991799
default `Route`, you can do so by calling `RouteBuilder::setRouteClass()`
@@ -1811,7 +1811,7 @@ Calling the method without an argument will return current default route class.
18111811

18121812
### Fallbacks Method
18131813

1814-
`method` Cake\\Routing\\RouteBuilder::**fallbacks**($routeClass = null)
1814+
`method` Cake\\Routing\\RouteBuilder::**fallbacks**(?string $routeClass = null): static
18151815

18161816
The fallbacks method is a simple shortcut for defining default routes. The
18171817
method uses the passed routing class for the defined rules or if no class is

0 commit comments

Comments
 (0)