Passed
Push — master ( 871603...972dd8 )
by Mārtiņš
02:12
created

_dnc()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 5
crap 2
1
<?php
2
3
use Printful\GettextCms\MessageManager;
4
5 1
if (!function_exists('_n')) {
6
    /**
7
     * Plural translation from default domain
8
     *
9
     * @param string $singular Original string in singular form
10
     * @param string $plural Original string in plural form
11
     * @param string $n Value number
12
     * @return string
13
     */
14
    function _n($singular, $plural, $n)
15
    {
16 1
        return ngettext($singular, $plural, $n);
0 ignored issues
show
Bug introduced by
$n of type string is incompatible with the type integer expected by parameter $n of ngettext(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
        return ngettext($singular, $plural, /** @scrutinizer ignore-type */ $n);
Loading history...
17
    }
18
}
19
20 1
if (!function_exists('_nc')) {
21
    /**
22
     * Translation with context from default domain
23
     *
24
     * @param string $context Free form string, but should use a know list of keywords.
25
     * @param string $singular Original string to be translated
26
     * @param string $plural
27
     * @param int $n
28
     * @return string
29
     */
30
    function _nc($context, $singular, $plural, $n)
31
    {
32 1
        $singular = "{$context}\004{$singular}";
33 1
        $translation = ngettext($singular, $plural, $n);
34
35 1
        return $translation === $singular ? $singular : $translation;
36
    }
37
}
38
39
40 1
if (!function_exists('_c')) {
41
    /**
42
     * Translation with context from default domain
43
     *
44
     * @param string $context Free form string, but should use a know list of keywords.
45
     * @param string $message Original string to be translated
46
     * @return string
47
     */
48
    function _c($context, $message)
49
    {
50 1
        $contextString = "{$context}\004{$message}";
51 1
        $translation = _($contextString);
52
53 1
        return $translation === $contextString ? $message : $translation;
54
    }
55
}
56
57
58 1
if (!function_exists('_dc')) {
59
    /**
60
     * Translation with domain and context
61
     *
62
     * @param string $domain Name of the domain
63
     * @param string $context Free form string, custom string type/category
64
     * @param string $message Original string
65
     * @return string
66
     */
67
    function _dc($domain, $context, $message)
68
    {
69 1
        $domain = MessageManager::getInstance()->getRevisionedDomain($domain);
70 1
        $contextString = "{$context}\004{$message}";
71 1
        $translation = dgettext($domain, $contextString);
72
73 1
        return $translation === $contextString ? $message : $translation;
74
    }
75
}
76
77
78 1
if (!function_exists('_d')) {
79
    /**
80
     * Translation with domain
81
     *
82
     * @param string $domain Name of the domain
83
     * @param string $message Original string
84
     * @return string
85
     */
86
    function _d($domain, $message)
87
    {
88 1
        $domain = MessageManager::getInstance()->getRevisionedDomain($domain);
89
90 1
        return dgettext($domain, $message);
91
    }
92
}
93
94
95 1
if (!function_exists('_dn')) {
96
    /**
97
     * Plural domain translation
98
     *
99
     * @param string $domain Name of the domain
100
     * @param string $singular Original string in singular form
101
     * @param string $plural Original string in plural form
102
     * @param string $n Value number
103
     * @return string
104
     */
105
    function _dn($domain, $singular, $plural, $n)
106
    {
107 1
        $domain = MessageManager::getInstance()->getRevisionedDomain($domain);
108
109 1
        return dngettext($domain, $singular, $plural, $n);
0 ignored issues
show
Bug introduced by
$n of type string is incompatible with the type integer expected by parameter $n of dngettext(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        return dngettext($domain, $singular, $plural, /** @scrutinizer ignore-type */ $n);
Loading history...
110
    }
111
}
112
113
114 1
if (!function_exists('_dnc')) {
115
    /**
116
     * Plural translation with domain and context
117
     *
118
     * @param string $domain Name of the domain
119
     * @param string $context
120
     * @param string $singular Original string in singular form
121
     * @param string $plural Original string in plural form
122
     * @param int $n Value number
123
     * @return string
124
     */
125
    function _dnc($domain, $context, $singular, $plural, $n)
126
    {
127 1
        $domain = MessageManager::getInstance()->getRevisionedDomain($domain);
128 1
        $message = "{$context}\004{$singular}";
129 1
        $translation = dngettext($domain, $message, $plural, $n);
130
131 1
        return $translation === $message ? $singular : $translation;
132
    }
133
}