Issues (116)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Russian/functions.php (1 issue)

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\Gender;
5
use morphos\S;
6
7
/**
8
 * Inflects the name in one case.
9
 * @param string $fullName        Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name
10
 * @param string $case            Case to inflect to.
11
 *                                Should be one of [[morphos\Cases]] or [[morphos\Russian\Cases]] constants.
12
 * @param null|string $gender     Gender of name owner. If null, auto detection will be used.
13
 *                                Should be one of [[morphos\Gender]] constants.
14
 * @return string|false           Returns string containing the inflection of name to a case.
15
 * @throws \Exception
16
 */
17
function inflectName($fullName, $case = null, $gender = null)
18
{
19 18
    if (in_array($case, [Gender::MALE, Gender::FEMALE, null], true)) {
20 10
        return $case === null ? getNameCases($fullName) : getNameCases($fullName, $case);
21
    }
22
23 8
    $fullName = normalizeFullName($fullName);
24 8
    $case = CasesHelper::canonizeCase($case);
25 8
    if ($gender === null) $gender = detectGender($fullName);
26
27 8
    $name = explode(' ', $fullName);
28
29 8
    switch (count($name)) {
30 8
        case 1:
31 1
            $name[0] = FirstNamesInflection::getCase($name[0], $case, $gender);
32 1
            break;
33
34 7 View Code Duplication
        case 2:
35 1
            $name[0] = LastNamesInflection::getCase($name[0], $case, $gender);
36 1
            $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender);
37 1
            break;
38
39 6 View Code Duplication
        case 3:
40 5
            $name[0] = LastNamesInflection::getCase($name[0], $case, $gender);
41 5
            $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender);
42 5
            $name[2] = MiddleNamesInflection::getCase($name[2], $case, $gender);
43 5
            break;
44
45
        default:
46 1
            return false;
47
    }
48
49 7
    return implode(' ', $name);
50
}
51
52
/**
53
 * Inflects the name to all cases.
54
 * @param string      $fullName Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name
55
 * @param null|string $gender   Gender of name owner. If null, auto detection will be used.
56
 *                              Should be one of [[morphos\Gender]] constants.
57
 * @return string[]|false          Returns an array with name inflected to all cases.
58
 */
59
function getNameCases($fullName, $gender = null)
60
{
61 11
    $fullName = normalizeFullName($fullName);
62 11
    if ($gender === null) $gender = detectGender($fullName);
63
64 11
    $name = explode(' ', $fullName);
65
66 11
    switch (count($name)) {
67 11
        case 1:
68 1
            $name[0] = FirstNamesInflection::getCases($name[0], $gender);
69 1
            break;
70
71 10 View Code Duplication
        case 2:
72 1
            $name[0] = LastNamesInflection::getCases($name[0], $gender);
73 1
            $name[1] = FirstNamesInflection::getCases($name[1], $gender);
74 1
            break;
75
76 9 View Code Duplication
        case 3:
77 8
            $name[0] = LastNamesInflection::getCases($name[0], $gender);
78 8
            $name[1] = FirstNamesInflection::getCases($name[1], $gender);
79 8
            $name[2] = MiddleNamesInflection::getCases($name[2], $gender);
80 8
            break;
81
82
        default:
83 1
            return false;
84
    }
85
86 10
    return CasesHelper::composeCasesFromWords($name);
87
}
88
89
/**
90
 * Guesses the gender of name owner.
91
 * @param string $fullName Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name
92
 * @return null|string     Null if not detected. One of [[morphos\Gender]] constants.
93
 */
94
function detectGender($fullName)
95
{
96 2
    $gender = null;
0 ignored issues
show
$gender is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97 2
    $name = explode(' ', S::lower($fullName));
98 2
    $nameCount = count($name);
99 2
    if ($nameCount > 3) {
100 1
        return null;
101
    }
102
103 1
    if ($nameCount === 1)
104 1
        return FirstNamesInflection::detectGender($name[0]);
105 1
    else if ($nameCount === 2)
106 1
        return LastNamesInflection::detectGender($name[0])
107 1
            ?: FirstNamesInflection::detectGender($name[1]);
108
    else
109 1
        return MiddleNamesInflection::detectGender($name[2])
110
            ?: (LastNamesInflection::detectGender($name[0])
111 1
                ?: FirstNamesInflection::detectGender($name[1]));
112
}
113
114
/**
115
 * Normalizes a full name. Swaps name parts to make "L F" or "L M F" scheme.
116
 * @param string $name Input name
117
 * @return string      Normalized name
118
 */
119
function normalizeFullName($name)
120
{
121 18
    $name = preg_replace('~[ ]{2,}~', '', trim($name));
122 18
    return $name;
123
}
124
125
/**
126
 * Генерация строки с числом и существительным, в правильной форме для сочетания с числом (кол-вом предметов).
127
 *
128
 * @param int    $count       Количество предметов
129
 * @param string $word        Название предмета ИЛИ "прилагатально предмет". Может включать в себя несколько
130
 *                            прилагательных перед существительным.
131
 *                            Например: "сообщение", "новое сообщение", "небольшая лампа".
132
 * @param bool   $animateness Признак одушевленности
133
 * @param string $case        Род существительного (по умолчанию именительный для 1 предмета и родительный для
134
 *                            нескольких)
135
 *
136
 * @return string Строка в формате "ЧИСЛО [СУЩ в правильной форме]"
137
 * @throws \Exception
138
 */
139
function pluralize($count, $word, $animateness = false, $case = null)
140
{
141
    // меняем местами аргументы, если они переданы в старом формате
142
    // @phpstan-ignore-next-line
143 18 View Code Duplication
    if (is_string($count) && is_numeric($word)) {
144 1
        list($count, $word) = [$word, $count];
145
    }
146
147 18
    if (strpos($word, ' ') !== false) {
148 1
        $words = explode(' ', $word);
149 1
        $noun = array_pop($words);
150
151 1
        foreach ($words as $i => $word) {
152 1
            if (in_array($word, RussianLanguage::$unions, true))
153
                $words[$i] = $word;
154
            else
155 1
                $words[$i] = AdjectivePluralization::pluralize($word, $count, $animateness, $case);
156
        }
157
158 1
        return $count.' '.implode(' ', $words).' '.NounPluralization::pluralize($count, $noun, $animateness, $case);
159
    }
160
161 18
    return $count.' '.NounPluralization::pluralize($word, $count, $animateness, $case);
162
}
163