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
7 changes: 3 additions & 4 deletions docs/en/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,9 @@ the controller's default one:
``` php
// In a controller method.
$recentArticles = $this->fetchTable('Articles')->find('all',
limit: 5,
order: 'Articles.created DESC',
)
->all();
limit: 5,
order: 'Articles.created DESC',
)->all();
```

### fetchModel()
Expand Down
42 changes: 21 additions & 21 deletions docs/en/core-libraries/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1245,40 +1245,40 @@ imagine a lengthy closure like this one:

``` php
$collection
->map(function ($row, $key) {
if (!empty($row['items'])) {
$row['total'] = collection($row['items'])->sumOf('price');
}
->map(function ($row, $key) {
if (!empty($row['items'])) {
$row['total'] = collection($row['items'])->sumOf('price');
}

if (!empty($row['total'])) {
$row['tax_amount'] = $row['total'] * 0.25;
}
if (!empty($row['total'])) {
$row['tax_amount'] = $row['total'] * 0.25;
}

// More code here...
// More code here...

return $modifiedRow;
});
return $modifiedRow;
});
```

This can be refactored by creating another class:

``` php
class TotalOrderCalculator
{
public function __invoke($row, $key)
{
if (!empty($row['items'])) {
$row['total'] = collection($row['items'])->sumOf('price');
}
public function __invoke($row, $key)
{
if (!empty($row['items'])) {
$row['total'] = collection($row['items'])->sumOf('price');
}

if (!empty($row['total'])) {
$row['tax_amount'] = $row['total'] * 0.25;
}
if (!empty($row['total'])) {
$row['tax_amount'] = $row['total'] * 0.25;
}

// More code here...
// More code here...

return $modifiedRow;
}
return $modifiedRow;
}
}

// Use the logic in your map() call
Expand Down
24 changes: 12 additions & 12 deletions docs/en/core-libraries/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ application. Mailer views can also use layouts and elements just like normal vie
``` php
$mailer = new Mailer();
$mailer
->setEmailFormat('html')
->setTo('bob@example.com')
->setFrom('app@domain.com')
->viewBuilder()
->setTemplate('welcome')
->setLayout('fancy');
->setEmailFormat('html')
->setTo('bob@example.com')
->setFrom('app@domain.com')
->viewBuilder()
->setTemplate('welcome')
->setLayout('fancy');

$mailer->deliver();
```
Expand All @@ -175,12 +175,12 @@ send multipart templated email messages as well:
``` php
$mailer = new Mailer();
$mailer
->setEmailFormat('both')
->setTo('bob@example.com')
->setFrom('app@domain.com')
->viewBuilder()
->setTemplate('welcome')
->setLayout('fancy');
->setEmailFormat('both')
->setTo('bob@example.com')
->setFrom('app@domain.com')
->viewBuilder()
->setTemplate('welcome')
->setLayout('fancy');

$mailer->deliver();
```
Expand Down
16 changes: 8 additions & 8 deletions docs/en/orm/associations.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ArticlesTable extends Table
public function initialize(array $config): void
{
$this->belongsTo('Authors', [
'className' => 'Publishing.Authors',
])
'className' => 'Publishing.Authors',
])
->setForeignKey('author_id')
->setProperty('author');
}
Expand Down Expand Up @@ -81,8 +81,8 @@ class ArticlesTable extends Table
->setFinder('approved');

$this->hasMany('UnapprovedComments', [
'className' => 'Comments',
])
'className' => 'Comments',
])
->setFinder('unapproved')
->setProperty('unapproved_comments');
}
Expand Down Expand Up @@ -195,15 +195,15 @@ class UsersTable extends Table
public function initialize(array $config): void
{
$this->hasOne('HomeAddresses', [
'className' => 'Addresses',
])
'className' => 'Addresses',
])
->setProperty('home_address')
->setConditions(['HomeAddresses.label' => 'Home'])
->setDependent(true);

$this->hasOne('WorkAddresses', [
'className' => 'Addresses',
])
'className' => 'Addresses',
])
->setProperty('work_address')
->setConditions(['WorkAddresses.label' => 'Work'])
->setDependent(true);
Expand Down
10 changes: 5 additions & 5 deletions docs/en/orm/retrieving-data-and-resultsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ the Author entity.
``` php
// In your finders/controller:
$query = $articles->find('list',
keyField: 'id',
valueField: function ($article) {
return $article->author->get('label');
}
)
keyField: 'id',
valueField: function ($article) {
return $article->author->get('label');
},
)
->contain('Authors');
```

Expand Down