Completed
Push — master ( 18bbe5...4b1809 )
by f
01:51
created

AdjectivePluralization::pluralize()   B

Complexity

Conditions 9
Paths 28

Size

Total Lines 26

Duplication

Lines 3
Ratio 11.54 %

Code Coverage

Tests 10
CRAP Score 11.9991

Importance

Changes 0
Metric Value
cc 9
nc 28
nop 4
dl 3
loc 26
ccs 10
cts 15
cp 0.6667
crap 11.9991
rs 8.0555
c 0
b 0
f 0
1
<?php
2
namespace morphos\Russian;
3
4
use morphos\BasePluralization;
5
use morphos\S;
6
7
class AdjectivePluralization extends BasePluralization implements Cases
8
{
9
    use RussianLanguage, CasesHelper;
10
11
    /**
12
     * @param      $adjective
13
     * @param int  $count
14
     * @param bool $animateness
15
     * @param null $case
16
     *
17
     * @return string|void
18
     * @throws \Exception
19
     */
20 1
    public static function pluralize($adjective, $count = 2, $animateness = false, $case = null)
21
    {
22
        // меняем местами аргументы, если они переданы в старом формате
23 1 View Code Duplication
        if (is_string($count) && is_numeric($adjective)) {
0 ignored issues
show
Duplication introduced by wapmorgan
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...
24
            list($count, $adjective) = [$adjective, $count];
25
        }
26
27 1
        if ($case !== null)
28
            $case = static::canonizeCase($case);
29
30 1
        if ($case === null) {
31 1
            switch (NounPluralization::getNumeralForm($count)) {
32 1
                case NounPluralization::ONE:
33 1
                    return $adjective;
34 1
                case NounPluralization::TWO_FOUR:
35
//                    return AdjectiveDeclension::getCase($adjective, static::RODIT, $animateness);
36 1
                case NounPluralization::FIVE_OTHER:
37 1
                    return AdjectivePluralization::getCase($adjective, static::RODIT, $animateness);
38
            }
39
        }
40
41
        if (NounPluralization::getNumeralForm($count) == NounPluralization::ONE)
42
            return AdjectiveDeclension::getCase($adjective, $case, $animateness);
43
        else
44
            return AdjectivePluralization::getCase($adjective, $case, $animateness);
45
    }
46
47
    /**
48
     * @param      $adjective
49
     * @param      $case
50
     * @param bool $animateness
51
     *
52
     * @return
53
     * @throws \Exception
54
     */
55 1
    public static function getCase($adjective, $case, $animateness = false)
56
    {
57 1
        $case = static::canonizeCase($case);
58 1
        $forms = static::getCases($adjective, $animateness);
59 1
        return $forms[$case];
60
    }
61
62
    /**
63
     * @param      $adjective
64
     * @param bool $animateness
65
     *
66
     * @return array|void
67
     */
68 1
    public static function getCases($adjective, $animateness = false)
69
    {
70 1
        $type = AdjectiveDeclension::getAdjectiveBaseType($adjective);
71 1
        $adjective = S::slice($adjective, 0, -2);
72
        switch ($type)
73
        {
74 1 View Code Duplication
            case AdjectiveDeclension::HARD_BASE:
0 ignored issues
show
Duplication introduced by wapmorgan
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...
75
                $cases = [
76 1
                    static::IMENIT => $adjective.'ые',
77 1
                    static::RODIT => $adjective.'ых',
78 1
                    static::DAT => $adjective.'ым',
79
                ];
80
81 1
                $cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness);
82
83 1
                $cases[static::TVORIT] = $adjective.'ыми';
84 1
                $cases[static::PREDLOJ] = $adjective.'ых';
85
86 1
                return $cases;
87
88
            case AdjectiveDeclension::SOFT_BASE:
89 View Code Duplication
            case AdjectiveDeclension::MIXED_BASE:
0 ignored issues
show
Duplication introduced by wapmorgan
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...
90
                $cases = [
91
                    static::IMENIT => $adjective.'ие',
92
                    static::RODIT => $adjective.'их',
93
                    static::DAT => $adjective.'им',
94
                ];
95
96
                $cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness);
97
98
                $cases[static::TVORIT] = $adjective.'ими';
99
                $cases[static::PREDLOJ] = $adjective.'их';
100
101
                return $cases;
102
        }
103
    }
104
}
105