Search code examples
phpcakephpphpdoc

CakePHP: How to update the Models PHPDocs?


I have a huge project with 100+ tables in my database. Over the years, we add some new columns in some tables, but we forgot to reflect this on Models phpDocs. Those phpdocs were initially generate by cake bake model in the beginning of our project.

Example:

<?php

namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * Pessoa Entity
 *
 * @property int $id
 * @property string $numero_documento_principal
 * @property string $nome
 * @property string $tipo_pessoa
 * @property string $cidade_natural
 * @property string $nacionalidade
 * @property string $estado_natural
 * @property \Cake\I18n\Time $data_obito
 * @property string $sexo
 * @property string $nome_genitor
 * @property string $nome_genitora
 * @property \Cake\I18n\Time $data_nascimento
 *
 * @property \App\Model\Entity\EnderecoPessoa[] $endereco_pessoa
 * @property \App\Model\Entity\Parte[] $parte
 */
class Pessoa extends Entity {}

Those docs are very important nowadays thanks auto-complete features used in VSCode and similars IDEs.

The problem is: if we try to generate by bake again, all custom code will be replaced by the original bake generated one. Is there a away to avoid this and update only the phpDocs part?


Solution

  • Put your code in a version control system and revert the changes that you do not need after baking, or use dereuromark/cakephp-ide-helper, which can update annotations.

    Alternatively check if the upcoming (partially) non-destructive baking functionality works for your needs.