kwn/number-to-words

View on GitHub
src/Language/Serbian/SerbianNounGenderInflector.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace NumberToWords\Language\Serbian;

class SerbianNounGenderInflector
{
    public function inflectNounByNumber(int $number, string $singular, string $plural, string $genitivePlural): string
    {
        $units = $number % 10;
        $tens = ((int) ($number / 10)) % 10;

        if ($units === 1 && $tens !== 1) {
            return $singular;
        }

        if ($tens === 1) {
            return $plural;
        }

        if ($units >= 2 && $units <= 4) {
            return $genitivePlural;
        }

        return $plural;
    }
}