Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/en/appendices/5-0-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ changes made:
### Database

- The `DateTimeType` and `DateType` now always return immutable objects.
Additionally the interface for `Date` objects reflects the `ChronosDate`
Additionally, the interface for `Date` objects reflects the `ChronosDate`
interface which lacks all the time related methods that were present in
CakePHP 4.x.
- `DateType::setLocaleFormat()` no longer accepts an array.
Expand Down Expand Up @@ -364,7 +364,7 @@ Table finders can now have typed arguments as required instead of an options arr
For e.g. a finder for fetching posts by category or user:

``` php
public function findByCategoryOrUser(SelectQuery $query, array $options)
public function findByCategoryOrUser(SelectQuery $query, array $options): SelectQuery
{
if (isset($options['categoryId'])) {
$query->where(['category_id' => $options['categoryId']]);
Expand All @@ -380,7 +380,7 @@ public function findByCategoryOrUser(SelectQuery $query, array $options)
can now be written as:

``` php
public function findByCategoryOrUser(SelectQuery $query, ?int $categoryId = null, ?int $userId = null)
public function findByCategoryOrUser(SelectQuery $query, ?int $categoryId = null, ?int $userId = null): SelectQuery
{
if ($categoryId) {
$query->where(['category_id' => $categoryId]);
Expand Down
8 changes: 4 additions & 4 deletions docs/en/console-commands/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ use Cake\Console\ConsoleOptionParser;
class UserCommand extends Command
{
// Define the default table. This allows you to use `fetchTable()` without any argument.
protected $defaultTable = 'Users';
protected ?string $defaultTable = 'Users';

protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
Expand Down Expand Up @@ -207,7 +207,7 @@ to terminate execution:
public function execute(Arguments $args, ConsoleIo $io): int
{
$name = $args->getArgument('name');
if (strlen($name) < 5) {
if (mb_strlen($name) < 5) {
// Halt execution, output to stderr, and set exit code to 1
$io->error('Name must be at least 4 characters long.');
$this->abort();
Expand All @@ -223,7 +223,7 @@ You can also use `abort()` on the `$io` object to emit a message and code:
public function execute(Arguments $args, ConsoleIo $io): int
{
$name = $args->getArgument('name');
if (strlen($name) < 5) {
if (mb_strlen($name) < 5) {
// Halt execution, output to stderr, and set exit code to 99
$io->abort('Name must be at least 4 characters long.', 99);
}
Expand Down Expand Up @@ -485,7 +485,7 @@ class UpdateTableCommandTest extends TestCase
{
use ConsoleIntegrationTestTrait;

protected $fixtures = [
protected array $fixtures = [
// assumes you have a UsersFixture
'app.Users',
];
Expand Down
2 changes: 1 addition & 1 deletion docs/en/console-commands/option-parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ can be used as part of a fluent method chain.

When creating positional arguments, you can use the `required` flag, to
indicate that an argument must be present when a shell is called.
Additionally you can use `choices` to force an argument to be from a list of
Additionally, you can use `choices` to force an argument to be from a list of
valid choices:

``` php
Expand Down
16 changes: 8 additions & 8 deletions docs/en/contributing/cakephp-coding-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ As you can see above there should be one space on both sides of equals sign (=).
Example of a method definition:

``` php
public function someFunction($arg1, $arg2 = '')
public function someFunction(string $arg1, string $arg2 = ''): mixed
{
if (expr) {
statement;
Expand All @@ -239,7 +239,7 @@ Try to make your functions return something, at least `true` or `false`, so
it can be determined whether the function call was successful:

``` php
public function connection($dns, $persistent = false)
public function connection(string|array $dns, bool $persistent = false): bool
{
if (is_array($dns)) {
$dnsInfo = $dns;
Expand All @@ -262,7 +262,7 @@ There are spaces on both side of the equals sign.
Try to avoid unnecessary nesting by bailing early:

``` php
public function run(array $data)
public function run(array $data): bool
{
...
if (!$success) {
Expand All @@ -272,7 +272,7 @@ public function run(array $data)
...
}

public function check(array $data)
public function check(array $data): void
{
...
if (!$success) {
Expand All @@ -299,7 +299,7 @@ We only typehint public methods, though, as typehinting is not cost-free:
* @param callable $callback Some callback.
* @param bool $boolean Some boolean value.
*/
public function foo(Table $table, array $array, callable $callback, $boolean)
public function foo(Table $table, array $array, callable $callback, bool $boolean): void
{
}
```
Expand All @@ -317,7 +317,7 @@ type:
*
* @param array|\ArrayObject $array Some array value.
*/
public function foo($array)
public function foo(array|\ArrayObject $array): void
{
}
```
Expand Down Expand Up @@ -456,7 +456,7 @@ instead:
*
* @return $this
*/
public function foo()
public function foo(): static
{
return $this;
}
Expand Down Expand Up @@ -650,7 +650,7 @@ class Thing
{
private $property; // Defined

public function readProperty()
public function readProperty(): void
{
// Not recommended as the property is defined in the class
if (!isset($this->property)) {
Expand Down
6 changes: 3 additions & 3 deletions docs/en/core-libraries/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ For example, you often want to cache remote service call results. You could use
``` php
class IssueService
{
public function allIssues($repo)
public function allIssues(string $repo): mixed
{
return Cache::remember($repo . '-issues', function () use ($repo) {
return $this->fetchAll($repo);
Expand Down Expand Up @@ -576,7 +576,7 @@ remove all entries associated to the `article` group:

``` php
// src/Model/Table/ArticlesTable.php
public function afterSave($event, $entity, $options = [])
public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
{
if ($entity->isNew()) {
Cache::clearGroup('article', 'site_home');
Expand All @@ -598,7 +598,7 @@ configurations, i.e.: having the same group:
* A variation of previous example that clears all Cache configurations
* having the same group
*/
public function afterSave($event, $entity, $options = [])
public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
{
if ($entity->isNew()) {
$configs = Cache::groupConfigs('article');
Expand Down
6 changes: 3 additions & 3 deletions docs/en/core-libraries/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ This can be refactored by creating another class:
``` php
class TotalOrderCalculator
{
public function __invoke($row, $key)
public function __invoke(array $row, string $key): array
{
if (!empty($row['items'])) {
$row['total'] = collection($row['items'])->sumOf('price');
Expand Down Expand Up @@ -1309,7 +1309,7 @@ be repeated every time:
``` php
class FinalCheckOutRowProcessor
{
public function __invoke($collection)
public function __invoke(CollectionInterface $collection): CollectionInterface
{
return $collection
->map(new ShippingCostCalculator)
Expand Down Expand Up @@ -1396,7 +1396,7 @@ The `buffered()` method is also useful for converting non-rewindable iterators
into collections that can be iterated more than once:

``` php
public function results()
public function results(): Generator
{
...
foreach ($transientElements as $e) {
Expand Down
4 changes: 2 additions & 2 deletions docs/en/core-libraries/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ use Cake\Mailer\Mailer;

class UserMailer extends Mailer
{
public function welcome($user)
public function welcome(User $user): void
{
$this
->setTo($user->email)
Expand All @@ -367,7 +367,7 @@ class UserMailer extends Mailer
->setTemplate('welcome_mail'); // By default, template with same name as method name is used.
}

public function resetPassword($user)
public function resetPassword(User $user): void
{
$this
->setTo($user->email)
Expand Down
12 changes: 6 additions & 6 deletions docs/en/core-libraries/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use Cake\ORM\Table;

class OrdersTable extends Table
{
public function place($order)
public function place(Order $order): bool
{
if ($this->save($order)) {
$this->Cart->remove($order);
Expand Down Expand Up @@ -536,7 +536,7 @@ In order to stop events you can either return `false` in your callbacks or
call the `stopPropagation()` method on the event object:

``` php
public function doSomething(EventInterface $event)
public function doSomething(EventInterface $event): bool
{
// ...
return false; // Stops the event
Expand All @@ -550,7 +550,7 @@ public function updateBuyStatistic(EventInterface $event): void
```

Stopping an event will prevent any additional callbacks from being called.
Additionally the code triggering the event may behave differently based on the
Additionally, the code triggering the event may behave differently based on the
event being stopped or not. Generally it does not make sense to stop 'after'
events, but stopping 'before' events is often used to prevent the entire
operation from occurring.
Expand All @@ -559,7 +559,7 @@ To check if an event was stopped, you call the `isStopped()` method in the
event object:

``` php
public function place($order)
public function place(Order $order): bool
{
$event = new Event('Order.beforePlace', $this, ['order' => $order]);
$this->getEventManager()->dispatch($event);
Expand Down Expand Up @@ -588,7 +588,7 @@ directly or returning the value in the callback itself:

``` php
// A listener callback
public function doSomething(EventInterface $event)
public function doSomething(EventInterface $event): mixed
{
// ...
$alteredData = $event->getData('order') + $moreData;
Expand All @@ -604,7 +604,7 @@ public function doSomethingElse(EventInterface $event): void
}

// Using the event result
public function place($order)
public function place(Order $order): bool
{
$event = new Event('Order.beforePlace', $this, ['order' => $order]);
$this->getEventManager()->dispatch($event);
Expand Down
2 changes: 1 addition & 1 deletion docs/en/core-libraries/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ invalidate the fields accordingly to the feedback from the remote server:

``` php
// in src/Form/ContactForm.php
public function setErrors($errors)
public function setErrors(array $errors): void
{
$this->_errors = $errors;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/core-libraries/hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ this method:
// Call the noop function $this->noop() on every element of $data
$result = Hash::map($data, "{n}", [$this, 'noop']);

public function noop(array $array)
public function noop(array $array): array
{
// Do stuff to array and return the result
return $array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ namespace App\I18n\Parser;

class YamlFileParser
{
public function parse($file)
public function parse(string $file): array
{
return yaml_parse_file($file);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/core-libraries/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class DatabaseLog extends BaseLog
// ...
}

public function log($level, string $message, array $context = [])
public function log($level, string $message, array $context = []): void
{
// Write to the database.
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/development/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use Cake\Http\BaseApplication;

class Application extends BaseApplication
{
public function bootstrap()
public function bootstrap(): void
{
// Call the parent to `require_once` config/bootstrap.php
parent::bootstrap();
Expand Down
2 changes: 1 addition & 1 deletion docs/en/development/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class BillingServiceProvider extends ServiceProvider
```

Service providers use their `services()` method to define all the services they
will provide. Additionally those services **must be** defined in the `$provides`
will provide. Additionally, those services **must be** defined in the `$provides`
property. Failing to include a service in the `$provides` property will result
in it not be loadable from the container.

Expand Down
6 changes: 3 additions & 3 deletions docs/en/development/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ use Cake\Error\Renderer\WebExceptionRenderer;

class AppExceptionRenderer extends WebExceptionRenderer
{
public function notFound($error)
public function notFound(NotFoundException $error): void
{
// Do something with NotFoundException objects.
}
Expand Down Expand Up @@ -358,10 +358,10 @@ use Cake\Core\Exception\CakeException;
class MissingWidgetException extends CakeException
{
// Context data is interpolated into this format string.
protected $_messageTemplate = 'Seems that %s is missing.';
protected string $_messageTemplate = 'Seems that %s is missing.';

// You can set a default exception code as well.
protected $_defaultCode = 404;
protected int $_defaultCode = 404;
}

throw new MissingWidgetException(['widget' => 'Pointy']);
Expand Down
2 changes: 1 addition & 1 deletion docs/en/development/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ use Cake\Http\Session\DatabaseSession;

class ComboSession extends DatabaseSession
{
protected $cacheKey;
protected string $cacheKey;

public function __construct()
{
Expand Down
Loading