AdjectivePluralization::getCase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace morphos\Russian;
3
4
use morphos\BasePluralization;
5
use morphos\S;
6
use RuntimeException;
7
8
class AdjectivePluralization extends BasePluralization implements Cases
9
{
10
    use RussianLanguage, CasesHelper;
11
12
    /**
13
     * @param string $adjective
14
     * @param int  $count
15
     * @param bool $animateness
16
     * @param string|null $case
17
     *
18
     * @return string|void
19
     * @throws \Exception
20
     */
21 1
    public static function pluralize($adjective, $count = 2, $animateness = false, $case = null)
22
    {
23
        // меняем местами аргументы, если они переданы в старом формате
24
        // @phpstan-ignore-next-line
25 1 View Code Duplication
        if (is_string($count) && is_numeric($adjective)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            list($count, $adjective) = [$adjective, $count];
27
        }
28
29 1
        if ($case !== null)
30
            $case = static::canonizeCase($case);
31
32 1
        if ($case === null) {
33 1
            switch (NounPluralization::getNumeralForm($count)) {
34 1
                case NounPluralization::ONE:
35 1
                    return $adjective;
36 1
                case NounPluralization::TWO_FOUR:
37
//                    return AdjectiveDeclension::getCase($adjective, static::RODIT, $animateness);
38 1
                case NounPluralization::FIVE_OTHER:
39 1
                    return AdjectivePluralization::getCase($adjective, static::RODIT, $animateness);
40
            }
41
        }
42
43
        if (NounPluralization::getNumeralForm($count) == NounPluralization::ONE)
44
            return AdjectiveDeclension::getCase($adjective, $case, $animateness);
45
        else
46
            return AdjectivePluralization::getCase($adjective, $case, $animateness);
47
    }
48
49
    /**
50
     * @param string $adjective
51
     * @param string $case
52
     * @param bool $animateness
53
     *
54
     * @return string
55
     * @throws \Exception
56
     */
57 1
    public static function getCase($adjective, $case, $animateness = false)
58
    {
59 1
        $case = static::canonizeCase($case);
60 1
        $forms = static::getCases($adjective, $animateness);
61 1
        return $forms[$case];
62
    }
63
64
    /**
65
     * @param string $adjective
66
     * @param bool $animateness
67
     *
68
     * @return string[]
69
     * @phpstan-return array<string, string>
70
     */
71 7
    public static function getCases($adjective, $animateness = false)
72
    {
73 7
        $type = AdjectiveDeclension::getAdjectiveBaseType($adjective);
74 7
        $adjective = S::slice($adjective, 0, -2);
75
        switch ($type)
76
        {
77 7 View Code Duplication
            case AdjectiveDeclension::HARD_BASE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
                $cases = [
79 3
                    static::IMENIT => $adjective.'ые',
80 3
                    static::RODIT => $adjective.'ых',
81 3
                    static::DAT => $adjective.'ым',
82
                ];
83
84 3
                $cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness);
85
86 3
                $cases[static::TVORIT] = $adjective.'ыми';
87 3
                $cases[static::PREDLOJ] = $adjective.'ых';
88
89 3
                return $cases;
90
91 4
            case AdjectiveDeclension::SOFT_BASE:
92 3 View Code Duplication
            case AdjectiveDeclension::MIXED_BASE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
                $cases = [
94 4
                    static::IMENIT => $adjective.'ие',
95 4
                    static::RODIT => $adjective.'их',
96 4
                    static::DAT => $adjective.'им',
97
                ];
98
99 4
                $cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness);
100
101 4
                $cases[static::TVORIT] = $adjective.'ими';
102 4
                $cases[static::PREDLOJ] = $adjective.'их';
103
104 4
                return $cases;
105
        }
106
107
        throw new RuntimeException('Unreachable');
108
    }
109
}
110