<?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_B8 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $ktoNr = \str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);

    $result = self::variante1($ktoNr);
    if (!$result) {
      $result = self::variante2($ktoNr);
    }
    if (!$result) {
      $result = self::variante3($ktoNr);
    }

    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);
  }

  private static function variante2($pKtoNr)
  {
    return Pruefziffer_29::check($pKtoNr, null);
  }

  private static function variante3($pKtoNr)
  {
    if (($pKtoNr >= 5100000000 && $pKtoNr <= 5999999999) || ($pKtoNr >= 9010000000 && $pKtoNr <= 9109999999)) {
      return true;
    } else {
      return false;
    }
  }
}