title: Cakephp Best Practices
body: <p>I have a question about best practices in CakePHP!</p>
  
  <p>Let's imagine the following situation:</p>
  
  <p>In a Receipt Model i have the code:</p>
  
  <pre><code>public function beforeValidate()
      {
          $this-&gt;data[$this-&gt;name]["client_id"] = CakeSession::read("Auth.User.id");
          $this-&gt;data[$this-&gt;name]["date"] = date('Y-m-d H:i:s');
  
          $receipt    = $this-&gt;data[$this-&gt;name]["receipt"];
          $cod_filial     = substr($receipt, 0, 3);
          $qtdade_cupom   = substr($receipt, 12, 2);
          $tipo_pagamento = substr($receipt, 14, 1);
  
          $this-&gt;data[$this-&gt;name]["cod"] = $cod_filial;
          $this-&gt;data[$this-&gt;name]["quantity"] = $qtdade_cupom;
          $this-&gt;data[$this-&gt;name]["payment_type"] = $tipo_pagamento;
          $this-&gt;data[$this-&gt;name]["is_valid"] = null;
  
  
          return true;
      }
  </code></pre>
  
  <p>I have to do a lot of verifications with the variables $qtdade_cupom, $cod_filial like check the valid digit.</p>
  
  <p>Where do I do the maths??</p>
  
  <p>I create a method inside the model like</p>
  
  <pre><code>public function checkDigits()
  </code></pre>
  
  <p>OR</p>
  
  <p>I create a Behaviour to do this?</p>
  
  <p>OR</p>
  
  <p>Other solution??</p>