<?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_89 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $laengeKtoNr = strlen((string)($pKtoNr * 1));
    if ($laengeKtoNr == 8 || $laengeKtoNr == 9) {
      return Pruefziffer_10::check($pKtoNr, $pBlz);
    } elseif ($laengeKtoNr == 7) {
      $gewichtung = array(0, 2, 3, 4, 5, 6, 7, 0, 0, 0);

      $ktoNr = \str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);
      $strZahl = strrev($ktoNr);

      $ary = PruefZiffHelpers::gewichtenQS($strZahl, $gewichtung);

      $rest = array_sum($ary) % 11;

      
      $result = ((11 - $rest) % 11) % 10;

      return ($result == $ktoNr[$pPruefZifferStelle]);
    } else {
      return true;
    }
  }
}