Completed
Push — master ( b5bb9d...38f7c0 )
by f
02:02
created

src/Russian/MiddleNamesInflection.php (8 issues)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

Upgrade to new PHP Analysis Engine

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
It seems like $name defined by \morphos\S::lower($name) on line 19 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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 boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\Russian\FirstNamesInflection::isMutable() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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 boolean; however, morphos\Russian\FirstNamesInflection::getCases() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
92
    }
93
}
94