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)) { |
|
|
|
|
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
|
7 |
|
public static function getCases($adjective, $animateness = false) |
69
|
|
|
{ |
70
|
7 |
|
$type = AdjectiveDeclension::getAdjectiveBaseType($adjective); |
71
|
7 |
|
$adjective = S::slice($adjective, 0, -2); |
72
|
|
|
switch ($type) |
73
|
|
|
{ |
74
|
7 |
View Code Duplication |
case AdjectiveDeclension::HARD_BASE: |
|
|
|
|
75
|
|
|
$cases = [ |
76
|
3 |
|
static::IMENIT => $adjective.'ые', |
77
|
3 |
|
static::RODIT => $adjective.'ых', |
78
|
3 |
|
static::DAT => $adjective.'ым', |
79
|
|
|
]; |
80
|
|
|
|
81
|
3 |
|
$cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness); |
82
|
|
|
|
83
|
3 |
|
$cases[static::TVORIT] = $adjective.'ыми'; |
84
|
3 |
|
$cases[static::PREDLOJ] = $adjective.'ых'; |
85
|
|
|
|
86
|
3 |
|
return $cases; |
87
|
|
|
|
88
|
4 |
|
case AdjectiveDeclension::SOFT_BASE: |
89
|
3 |
View Code Duplication |
case AdjectiveDeclension::MIXED_BASE: |
|
|
|
|
90
|
|
|
$cases = [ |
91
|
4 |
|
static::IMENIT => $adjective.'ие', |
92
|
4 |
|
static::RODIT => $adjective.'их', |
93
|
4 |
|
static::DAT => $adjective.'им', |
94
|
|
|
]; |
95
|
|
|
|
96
|
4 |
|
$cases[static::VINIT] = static::getVinitCaseByAnimateness($cases, $animateness); |
97
|
|
|
|
98
|
4 |
|
$cases[static::TVORIT] = $adjective.'ими'; |
99
|
4 |
|
$cases[static::PREDLOJ] = $adjective.'их'; |
100
|
|
|
|
101
|
4 |
|
return $cases; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.