Skip to content

Commit

Permalink
Merge pull request #943 from CakeDC/feature/named-arguments
Browse files Browse the repository at this point in the history
Use named arguments
  • Loading branch information
LordSimal committed Sep 17, 2023
2 parents a683d7d + 1c6def1 commit d0dd499
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 42 deletions.
2 changes: 1 addition & 1 deletion templates/bake/element/Controller/add.twig
Expand Up @@ -37,7 +37,7 @@
{%- for assoc in associations %}
{%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %}
{%- set otherPlural = otherName|variable %}
${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', ['limit' => 200])->all();
${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', limit: 200)->all();
{{- "\n" }}
{%- set compact = compact|merge(["'#{otherPlural}'"]) %}
{% endfor %}
Expand Down
6 changes: 2 additions & 4 deletions templates/bake/element/Controller/edit.twig
Expand Up @@ -25,9 +25,7 @@
*/
public function edit($id = null)
{
${{ singularName }} = $this->{{ currentModelName }}->get($id, [
'contain' => {{ Bake.exportArray(belongsToMany)|raw }},
]);
${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }});
if ($this->request->is(['patch', 'post', 'put'])) {
${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->request->getData());
if ($this->{{ currentModelName }}->save(${{ singularName }})) {
Expand All @@ -40,7 +38,7 @@
{% for assoc in belongsTo|merge(belongsToMany) %}
{%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %}
{%- set otherPlural = otherName|variable %}
${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', ['limit' => 200])->all();
${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', limit: 200)->all();
{{- "\n" }}
{%- set compact = compact|merge(["'#{otherPlural}'"]) %}
{% endfor %}
Expand Down
5 changes: 1 addition & 4 deletions templates/bake/element/Controller/view.twig
Expand Up @@ -26,9 +26,6 @@
*/
public function view($id = null)
{
${{ singularName }} = $this->{{ currentModelName }}->get($id, [
'contain' => {{ Bake.exportArray(allAssociations)|raw }},
]);

${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(allAssociations)|raw }});
$this->set(compact('{{ singularName }}'));
}
17 changes: 6 additions & 11 deletions tests/comparisons/Controller/testBakeActions.php
Expand Up @@ -49,10 +49,7 @@ public function index()
*/
public function view($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeUsers', 'BakeTags', 'BakeComments'],
]);

$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']);
$this->set(compact('bakeArticle'));
}

Expand All @@ -73,8 +70,8 @@ public function add()
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand All @@ -87,9 +84,7 @@ public function add()
*/
public function edit($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeTags'],
]);
$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']);
if ($this->request->is(['patch', 'post', 'put'])) {
$bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->getData());
if ($this->BakeArticles->save($bakeArticle)) {
Expand All @@ -99,8 +94,8 @@ public function edit($id = null)
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand Down
17 changes: 6 additions & 11 deletions tests/comparisons/Controller/testBakeActionsContent.php
Expand Up @@ -33,10 +33,7 @@ public function index()
*/
public function view($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeUsers', 'BakeTags', 'BakeComments'],
]);

$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']);
$this->set(compact('bakeArticle'));
}

Expand All @@ -57,8 +54,8 @@ public function add()
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand All @@ -71,9 +68,7 @@ public function add()
*/
public function edit($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeTags'],
]);
$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']);
if ($this->request->is(['patch', 'post', 'put'])) {
$bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->getData());
if ($this->BakeArticles->save($bakeArticle)) {
Expand All @@ -83,8 +78,8 @@ public function edit($id = null)
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand Down
17 changes: 6 additions & 11 deletions tests/comparisons/Controller/testBakeWithPlugin.php
Expand Up @@ -35,10 +35,7 @@ public function index()
*/
public function view($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeUsers', 'BakeTags', 'BakeComments'],
]);

$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']);
$this->set(compact('bakeArticle'));
}

Expand All @@ -59,8 +56,8 @@ public function add()
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand All @@ -73,9 +70,7 @@ public function add()
*/
public function edit($id = null)
{
$bakeArticle = $this->BakeArticles->get($id, [
'contain' => ['BakeTags'],
]);
$bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']);
if ($this->request->is(['patch', 'post', 'put'])) {
$bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->getData());
if ($this->BakeArticles->save($bakeArticle)) {
Expand All @@ -85,8 +80,8 @@ public function edit($id = null)
}
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', ['limit' => 200])->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', ['limit' => 200])->all();
$bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all();
$bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all();
$this->set(compact('bakeArticle', 'bakeUsers', 'bakeTags'));
}

Expand Down

0 comments on commit d0dd499

Please sign in to comment.