Exemplo n.º 1
0
 /**
  * Valida o código de barras.
  * @param mixed $value
  * @return boolean
  */
 public function validate($input)
 {
     $input = new StringHelper($input);
     $digitoCean = 0;
     $indiceInicial = 0;
     $digitoCalculo = 0;
     $digitoCalculado = 0;
     $tamCean = $input->length;
     $ceanSemDigito = new StringHelper();
     if (!in_array($tamCean, array(8, 12, 13, 14, 18))) {
         return false;
     }
     $digitoCean = (int) $input->right(1, 1)->getValue();
     $ceanSemDigito->setValue($input->left(0, $input->length - 1)->getValue());
     $indiceInicial = $this->p->count() - $ceanSemDigito->length;
     for ($i = 0; $i < $ceanSemDigito->length; $i++) {
         $digitoCalculo += (int) $ceanSemDigito->substring($i, 1)->getValue() * $this->p->offsetGet($indiceInicial++);
     }
     if ($digitoCalculo % 10 == 0) {
         $digitoCalculado = 0;
     } else {
         $divTemp = (int) ceil($digitoCalculo / 10.0) * 10;
         $digitoCalculado = $divTemp - $digitoCalculo;
     }
     if ($digitoCalculado === $digitoCean) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Verifica se os parâmetros da configuração obrigatória estão definidos.
  * @param array $parameters
  * @throws \RuntimeException 
  */
 protected function validateParameters($parameters = array())
 {
     if (\Sped\Commons\StringHelper::isNullOrEmpty($parameters['name'])) {
         throw new \RuntimeException("The method name can't be a null or empty");
     }
     if (\Sped\Commons\StringHelper::isNullOrEmpty($parameters['type'])) {
         throw new \RuntimeException("The method type can't be a null or empty");
     }
 }