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
4 changes: 2 additions & 2 deletions docs/en/development/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ use Cake\Event\EventInterface;

class ErrorController extends AppController
{
protected function missingWidget(MissingWidgetException $exception)
protected function missingWidget(MissingWidgetException $exception): void
{
// You can prepare additional template context or trap errors.
}
Expand Down Expand Up @@ -259,7 +259,7 @@ use Cake\Error\Renderer\WebExceptionRenderer;

class AppExceptionRenderer extends WebExceptionRenderer
{
public function missingWidget($error)
public function missingWidget(\Throwable $error): \Cake\Http\Response
{
$response = $this->controller->getResponse();

Expand Down
26 changes: 13 additions & 13 deletions docs/en/orm/database-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ class WidgetsTable extends Table
{
public function initialize(array $config): void
{
return parent::getSchema()->setColumnType('mutation', 'point_mutation');

parent::getSchema()->setColumnType('mutation', 'point_mutation');
}
}
```
Expand Down Expand Up @@ -844,30 +843,30 @@ namespace App\Database;
// Our value object is immutable.
class Point
{
protected $_lat;
protected $_long;
protected float|int $_lat;
protected float|int $_long;

// Factory method.
public static function parse($value)
public static function parse(mixed $value): static
{
// Parse the WKB data from MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
public function __construct(float|int $lat, float|int $long)
{
$this->_lat = $lat;
$this->_long = $long;
}

public function lat()
public function lat(): float|int
{
return $this->_lat;
}

public function long()
public function long(): float|int
{
return $this->_long;
}
Expand All @@ -889,12 +888,12 @@ use Cake\Database\Type\ExpressionTypeInterface;

class PointType extends BaseType implements ExpressionTypeInterface
{
public function toPHP($value, Driver $d): mixed
public function toPHP(mixed $value, Driver $driver): mixed
{
return $value === null ? null : Point::parse($value);
}

public function marshal($value): mixed
public function marshal(mixed $value): mixed
{
if (is_string($value)) {
$value = explode(',', $value);
Expand All @@ -906,21 +905,22 @@ class PointType extends BaseType implements ExpressionTypeInterface
return null;
}

public function toExpression($value): ExpressionInterface
public function toExpression(mixed $value): ExpressionInterface
{
if ($value instanceof Point) {
return new FunctionExpression(
'POINT',
[
$value->lat(),
$value->long()
$value->long(),
]
);
}
if (is_array($value)) {
return new FunctionExpression('POINT', [$value[0], $value[1]]);
}
// Handle other cases.

throw new \InvalidArgumentException('Cannot convert value to expression.');
}

public function toDatabase($value, Driver $driver): mixed
Expand Down
6 changes: 3 additions & 3 deletions docs/en/orm/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ use Cake\ORM\Entity;

class Article extends Entity
{
protected function _getTitle($title)
protected function _getTitle(string $title): string
{
return strtoupper($title);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ use Cake\Utility\Text;

class Article extends Entity
{
protected function _setTitle($title)
protected function _setTitle(string $title): string
{
$this->slug = Text::slug($title);

Expand Down Expand Up @@ -283,7 +283,7 @@ use Cake\ORM\Entity;

class User extends Entity
{
protected function _getFullName()
protected function _getFullName(): string
{
return $this->first_name . ' ' . $this->last_name;
}
Expand Down
6 changes: 3 additions & 3 deletions docs/en/orm/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ used. An example validator for our articles table would be:
``` php
class ArticlesTable extends Table
{
public function validationUpdate($validator)
public function validationUpdate(Validator $validator): Validator
{
$validator
->notEmptyString('title', __('You need to provide a title'))
Expand Down Expand Up @@ -682,7 +682,7 @@ In the above example, we'll use a 'custom' validator, which is defined using the
`validationCustomName()` method:

``` php
public function validationCustomName($validator)
public function validationCustomName(Validator $validator): Validator
{
$validator->add(
// ...
Expand All @@ -697,7 +697,7 @@ from any request:

``` php
// In src/Model/Table/UsersTable.php
public function validatePasswords($validator)
public function validatePasswords(Validator $validator): Validator
{
$validator->add('confirm_password', 'no-misspelling', [
'rule' => ['compareWith', 'password'],
Expand Down
2 changes: 1 addition & 1 deletion docs/en/views/helpers/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ do the following:
// src/Controller/ArticlesController.php:
public function edit($id = null)
{
if (empty($id)) {
if (!$id) {
throw new NotFoundException;
}
$article = $this->Articles->get($id);
Expand Down