CakePHP 5 で "finder with options array is deprecated" が出る場合の対応方法

CakePHP 5 では find() を従来通り下記のように書くと deprecated エラーが出ます。

src/Controller/ArticlesController.php
// deprecated エラーが出るコード
$list = $this->Articles->find('list', [
        'keyField' => 'id',
        'valueField' => 'title',
    ])
    ->toArray();
logs/debug.log
2023-09-29 00:00:00 debug: Since 5.0.0: Calling `findList` finder with options array is deprecated. finder with options array is deprecated.

原因は第二引数でオプションを配列で渡していることで、解決するためには下記のように PHP 8 の名前付き引数を使います

src/Controller/ArticlesController.php
$list = $this->Articles->find('list',
        keyField: 'id',
        valueField: 'title',
    )
    ->toArray();

また第1引数も名前付き引数にして、下記のように書くこともできます。

src/Controller/ArticlesController.php
$list = $this->Articles->find(
        type: 'list',
        keyField: 'id',
        valueField: 'title',
    )
    ->toArray();