These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace morphos\Russian; |
||
3 | |||
4 | use morphos\S; |
||
5 | |||
6 | /** |
||
7 | * Rules are from http://surnameonline.ru/patronymic.html |
||
8 | */ |
||
9 | class MiddleNamesInflection extends \morphos\NamesInflection implements Cases |
||
10 | { |
||
11 | use RussianLanguage, CasesHelper; |
||
12 | |||
13 | /** |
||
14 | * @param $name |
||
15 | * @return null|string |
||
16 | */ |
||
17 | 5 | public static function detectGender($name) |
|
18 | { |
||
19 | 5 | $name = S::lower($name); |
|
20 | 5 | if (S::slice($name, -2) == 'ич') { |
|
0 ignored issues
–
show
|
|||
21 | 3 | return self::MALE; |
|
22 | 3 | } elseif (S::slice($name, -2) == 'на') { |
|
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 19 can also be of type false ; however, morphos\S::slice() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
23 | 3 | return self::FEMALE; |
|
24 | } |
||
25 | |||
26 | return null; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param $name |
||
31 | * @param null $gender |
||
32 | * @return bool |
||
33 | */ |
||
34 | 2 | public static function isMutable($name, $gender = null) |
|
35 | { |
||
36 | 2 | $name = S::lower($name); |
|
37 | 2 | View Code Duplication | if (in_array(S::slice($name, -2), ['ич', 'на'], true)) { |
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 36 can also be of type false ; however, morphos\S::slice() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
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...
|
|||
38 | 2 | return true; |
|
39 | } |
||
40 | |||
41 | // it's foreign middle name, inflect it as a first name |
||
42 | return FirstNamesInflection::isMutable($name, $gender); |
||
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 36 can also be of type false ; however, morphos\Russian\FirstNamesInflection::isMutable() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param $name |
||
47 | * @param $case |
||
48 | * @param null $gender |
||
49 | * @return mixed |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | 9 | public static function getCase($name, $case, $gender = null) |
|
53 | { |
||
54 | 9 | $case = self::canonizeCase($case); |
|
55 | 9 | $forms = self::getCases($name, $gender); |
|
56 | 9 | return $forms[$case]; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $name |
||
61 | * @param null $gender |
||
62 | * @return array |
||
63 | */ |
||
64 | 21 | public static function getCases($name, $gender = null) |
|
65 | { |
||
66 | 21 | $name = S::lower($name); |
|
67 | 21 | if (S::slice($name, -2) == 'ич') { |
|
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 66 can also be of type false ; however, morphos\S::slice() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
68 | // man rules |
||
69 | 8 | $name = S::name($name); |
|
70 | return array( |
||
71 | 8 | Cases::IMENIT => $name, |
|
72 | 8 | Cases::RODIT => $name.'а', |
|
73 | 8 | Cases::DAT => $name.'у', |
|
74 | 8 | Cases::VINIT => $name.'а', |
|
75 | 8 | Cases::TVORIT => $name.'ем', |
|
76 | 8 | Cases::PREDLOJ => $name.'е', |
|
77 | ); |
||
78 | 13 | View Code Duplication | } elseif (S::slice($name, -2) == 'на') { |
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 66 can also be of type false ; however, morphos\S::slice() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
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...
|
|||
79 | 11 | $prefix = S::name(S::slice($name, 0, -1)); |
|
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 66 can also be of type false ; however, morphos\S::slice() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
80 | return array( |
||
81 | 11 | Cases::IMENIT => $prefix.'а', |
|
82 | 11 | Cases::RODIT => $prefix.'ы', |
|
83 | 11 | Cases::DAT => $prefix.'е', |
|
84 | 11 | Cases::VINIT => $prefix.'у', |
|
85 | 11 | Cases::TVORIT => $prefix.'ой', |
|
86 | 11 | Cases::PREDLOJ => $prefix.'е', |
|
87 | ); |
||
88 | } |
||
89 | |||
90 | // inflect other middle names (foreign) as first names |
||
91 | 2 | return FirstNamesInflection::getCases($name, $gender); |
|
0 ignored issues
–
show
It seems like
$name defined by \morphos\S::lower($name) on line 66 can also be of type false ; however, morphos\Russian\FirstNamesInflection::getCases() does only seem to accept string , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
92 | } |
||
93 | } |
||
94 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.