public static function isValidNip($nip)
    {
        $nip = preg_replace('/[\D]/', '', $nip);

        $invalidNips = [
            '1234567890',
            '0000000000',
        ];

        if (!preg_match('/^[\d]{10}$/', $nip) || in_array($nip, $invalidNips, true)) {
            return false;
        }

        $sum = 0;
        $weights = [
            6,
            5,
            7,
            2,
            3,
            4,
            5,
            6,
            7,
        ];

        for ($i = 0; $i < 9; ++$i) {
            $sum += $weights[$i] * $nip[$i];
        }

        $modulo = $sum % 11;
        $numberControl = (10 === $modulo) ? 0 : $modulo;

        return $numberControl === (int)$nip[9];
    }