phpcakephpphpdocscrutinizer

CakePHP 3 - How to do document useImmutable() method in bootstrap.php


We use scrutinizer to inspect our code. Here is one "bug" related to phpdoc:

<?php
 *
 * @method \Cake\Database\Type\DateTimeType[] useImmutable()
 */
Type::build('time')->useImmutable();

Error message:

The method useImmutable() does not exist on Cake\Database\Type. It seems like you code against a sub-type of Cake\Database\Type such as Cake\Database\Type\DateTimeType.


Solution

  • Create a variable and typehint it:

    /** @var \Cake\Database\Type\DateTimeType $time */
    $time = Type::build('time');
    $time->useImmutable();