<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */
class Pruefziffer_B6 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $ktoNr = \str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);

    $teilKtoNr = substr($ktoNr, 0, 5);
    if ($ktoNr[0] > 0 || ($teilKtoNr >= 2691 && $teilKtoNr <= 2699)) {
      $result = self::variante1($ktoNr);
    } else {
      $result = self::variante2($ktoNr, $pBlz);
    }

    return $result;
  }

  private static function variante1($pKtoNr)
  {
    $gewichtung = array(0, 2, 3, 4, 5, 6, 7, 8, 9, 3);

    return Pruefziffer_20::check($pKtoNr, null, $gewichtung, 9);
  }

  private static function variante2($pKtoNr, $pBlz)
  {
    $gewichtung = array(2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4);

    return Pruefziffer_53::check($pKtoNr, $pBlz, $gewichtung, 2);
  }
}