Completed
Push — 2.1.x ( 7ab7e8 )
by f
23:20
created

LastNamesDeclension   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 130
Duplicated Lines 41.54 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 54
loc 130
rs 10
c 0
b 0
f 0
wmc 22
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
B hasForms() 0 20 9
C getForms() 44 94 10
A getForm() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace morphos\Russian;
3
4
/**
5
 * Rules are from http://gramma.ru/SPR/?id=2.8
6
 */
7
class LastNamesDeclension extends \morphos\NamesDeclension implements Cases {
8
    use RussianLanguage;
9
10
    public function hasForms($name, $gender) {
11
        $name = lower($name);
12
        if ($gender == self::MAN) {
13
            if (in_array(slice($name, -2), array('ов', 'ев', 'ин', 'ын')) || in_array(slice($name, -4), array('ский', 'ской', 'цкий', 'цкой')))
14
                return true;
15
            if (in_array(upper(slice($name, -1)), RussianLanguage::$consonants))
16
                return true;
17
18
            if (slice($name, -1) == 'ь')
19
                return true;
20
        } else {
21
            if (in_array(slice($name, -3), array('ова', 'ева', 'ина', 'ына')) || in_array(slice($name, -4), array('ская')))
22
                return true;
23
        }
24
25
        if (in_array(slice($name, -1), array('а', 'я')))
26
            return true;
27
28
        return false;
29
    }
30
31
    public function getForms($name, $gender) {
32
        $name = lower($name);
33
        if ($gender == self::MAN) {
34
            if (in_array(slice($name, -2), array('ов', 'ев', 'ин', 'ын'))) {
35
                $prefix = name($name);
36
                return array(
37
                    self::IMENIT_1 => $prefix,
38
                    self::RODIT_2 => $prefix.'а',
39
                    self::DAT_3 => $prefix.'у',
40
                    self::VINIT_4 => $prefix.'а',
41
                    self::TVORIT_5 => $prefix.'ым',
42
                    self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'е'
43
                );
44
            }
45
46 View Code Duplication
            if (in_array(slice($name, -4), array('ский', 'ской', 'цкий', 'цкой'))) {
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...
47
                $prefix = name(slice($name, 0, -2));
48
                return array(
49
                    self::IMENIT_1 => name($name),
50
                    self::RODIT_2 => $prefix.'ого',
51
                    self::DAT_3 => $prefix.'ому',
52
                    self::VINIT_4 => $prefix.'ого',
53
                    self::TVORIT_5 => $prefix.'им',
54
                    self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'ом'
55
                );
56
            }
57
        } else {
58 View Code Duplication
            if (in_array(slice($name, -3), array('ова', 'ева', 'ина', 'ына'))) {
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...
59
                $prefix = name(slice($name, 0, -1));
60
                return array(
61
                    self::IMENIT_1 => name($name),
62
                    self::RODIT_2 => $prefix.'ой',
63
                    self::DAT_3 => $prefix.'ой',
64
                    self::VINIT_4 => $prefix.'у',
65
                    self::TVORIT_5 => $prefix.'ой',
66
                    self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'ой'
67
                );
68
            }
69
70 View Code Duplication
            if (in_array(slice($name, -4), array('ская'))) {
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...
71
                $prefix = name(slice($name, 0, -2));
72
                return array(
73
                    self::IMENIT_1 => name($name),
74
                    self::RODIT_2 => $prefix.'ой',
75
                    self::DAT_3 => $prefix.'ой',
76
                    self::VINIT_4 => $prefix.'ую',
77
                    self::TVORIT_5 => $prefix.'ой',
78
                    self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'ой'
79
                );
80
            }
81
        }
82
83
        if (slice($name, -1) == 'я') {
84
            $prefix = name(slice($name, 0, -1));
85
            return array(
86
                self::IMENIT_1 => name($name),
87
                self::RODIT_2 => $prefix.'и',
88
                self::DAT_3 => $prefix.'е',
89
                self::VINIT_4 => $prefix.'ю',
90
                self::TVORIT_5 => $prefix.'ей',
91
                self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'е'
92
            );
93
        } else if (slice($name, -1) == 'а') {
94
            $prefix = name(slice($name, 0, -1));
95
            return array(
96
                self::IMENIT_1 => name($name),
97
                self::RODIT_2 => $prefix.'ы',
98
                self::DAT_3 => $prefix.'е',
99
                self::VINIT_4 => $prefix.'у',
100
                self::TVORIT_5 => $prefix.'ой',
101
                self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'е'
102
            );
103
        } else if (in_array(upper(slice($name, -1)), RussianLanguage::$consonants)) {
104
            $prefix = name($name);
105
            return array(
106
                self::IMENIT_1 => name($name),
107
                self::RODIT_2 => $prefix.'а',
108
                self::DAT_3 => $prefix.'у',
109
                self::VINIT_4 => $prefix.'а',
110
                self::TVORIT_5 => $prefix.'ом',
111
                self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'е'
112
            );
113 View Code Duplication
        } else if (slice($name, -1) == 'ь') {
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...
114
            $prefix = name(slice($name, 0, -1));
115
            return array(
116
                self::IMENIT_1 => name($name),
117
                self::RODIT_2 => $prefix.'я',
118
                self::DAT_3 => $prefix.'ю',
119
                self::VINIT_4 => $prefix.'я',
120
                self::TVORIT_5 => $prefix.'ем',
121
                self::PREDLOJ_6 => $this->choosePrepositionByFirstLetter($prefix, 'об', 'о').' '.$prefix.'е'
122
            );
123
        }
124
    }
125
126 View Code Duplication
    public function getForm($name, $form, $gender) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
127
        $forms = $this->getForms($name, $gender);
128
        if ($forms !== false)
129
            if (isset($forms[$form]))
130
                return $forms[$form];
131
            else
132
                return false;
133
        else
134
            return false;
135
    }
136
}
137