for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Install GitHub App
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <[email protected]>
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use function array_map;
use function is_scalar;
use function preg_match;
use function str_split;
/**
* Validates whether the input is a Polish VAT identification number (NIP).
* @see https://en.wikipedia.org/wiki/VAT_identification_number
* @author Henrique Moody <[email protected]>
* @author Tomasz Regdos <[email protected]>
final class Nip extends AbstractRule
{
* {@inheritDoc}
public function validate($input): bool
if (!is_scalar($input)) {
return false;
}
if (!preg_match('/^\d{10}$/', (string) $input)) {
$weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
$digits = array_map('intval', str_split($input));
$targetControlNumber = $digits[9];
$calculateControlNumber = 0;
for ($i = 0; $i < 9; ++$i) {
$calculateControlNumber += $digits[$i] * $weights[$i];
$calculateControlNumber = $calculateControlNumber % 11;
return $targetControlNumber == $calculateControlNumber;