Completed
Push — master ( b90e1d...11acf7 )
by Nelson
05:52
created

functions.php ➔ msg()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 10
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Global functions definition for NML.
7
 *
8
 * Copyright © 2016-2017 Nelson Martell (http://nelson6e65.github.io)
9
 *
10
 * Licensed under The MIT License (MIT)
11
 * For full copyright and license information, please see the LICENSE
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright 2016-2017 Nelson Martell
15
 * @link      http://nelson6e65.github.io/php_nml/
16
 * @since     v0.6.0
17
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
18
 * */
19
20
namespace NelsonMartell;
21
22
use NelsonMartell\Extensions\Text;
23
24
/**
25
 * Busca un mensaje único traducido en el dominio 'nml'.
26
 * El mensaje puede contener cadenas de formato.
27
 *
28
 * @param string      $message Mensaje con formato que se va a buscar.
29
 * @param array|mixed $args    Un objeto, una lista de objetos o múltiples
30
 *   argumentos que se van a incluir en las cadenas de formato del mensaje.
31
 *
32
 * @return string
33
 * @since v0.6.0
34
 * @see \dgettext()
35
 * */
36 View Code Duplication
function msg($message, $args = null)
0 ignored issues
show
Duplication introduced by
This function 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...
37
{
38 47
    $translated = \dgettext(NML_GETTEXT_DOMAIN, $message);
39
40 47
    if (\func_num_args() > 2) {
41 3
        $args = \array_slice(func_get_args(), 1);
42 3
    }
43
44 47
    return Text::format($translated, $args);
45
}
46
47
48
/**
49
 * Busca un mensaje único, en singular y plural, traducido en el dominio 'nml'.
50
 * El mensaje puede contener cadenas de formato.
51
 *
52
 * @param string      $singular Mensaje con formato que se va a buscar cuando $n
53
 *   es uno (1).
54
 * @param string      $plural   Mensaje con formato que se va a buscar cuando $n
55
 *   es distinto a (1).
56
 * @param int         $n        Cantidad
57
 * @param array|mixed $args     Un objeto, una lista de objetos o múltiples
58
 *   argumentos que se van a incluir en las cadenas de formato del mensaje.
59
 *
60
 * @return string
61
 * @since v0.6.0
62
 * @see \dngettext()
63
 * */
64 View Code Duplication
function nmsg($singular, $plural, $n, $args = null)
0 ignored issues
show
Duplication introduced by
This function 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...
Comprehensibility introduced by
Avoid variables with short names like $n. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
65
{
66
    $translated = \dngettext(NML_GETTEXT_DOMAIN, $singular, $plural, $n);
67
68
    if (\func_num_args() > 4) {
69
        $args = \array_slice(func_get_args(), 3);
70
    }
71
72
    return Text::format($translated, $args);
73
}
74
75
76
/**
77
 * Obtiene el tipo del objeto especificado.
78
 * Es un alias para el constructor de la clase Type.
79
 *
80
 * @param mixed $obj Objeto al cual se le extraerá su tipo.
81
 *
82
 * @return Type
83
 * @since v0.6.0
84
 * */
85
function typeof($obj)
86
{
87 217
    return new Type($obj);
88
}
89