Completed
Push — master ( a2c643...e562f7 )
by Nelson
04:00
created

functions.php ➔ msg()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 3
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     0.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    Lista de objetos que se van a incluir en las cadenas de formato del mensaje.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
30
 *
31
 * @return string
32
 * @since 0.6.0
33
 * @see \dgettext()
34
 * */
35
function msg($message, ...$args)
36
{
37 63
    $translated = \dgettext(NML_GETTEXT_DOMAIN, $message);
38
39 63
    $data = $args;
40
41 63
    if (count($args) === 1 && is_array($args[0])) {
42 55
        $data = $args[0];
43
    }
44
45 63
    return Text::format($translated, $data);
46
}
47
48
49
/**
50
 * Busca un mensaje único, en singular y plural, traducido en el dominio 'nml'.
51
 * El mensaje puede contener cadenas de formato.
52
 *
53
 * @param string      $singular Mensaje con formato que se va a buscar cuando $n
54
 *   es uno (1).
55
 * @param string      $plural   Mensaje con formato que se va a buscar cuando $n
56
 *   es distinto a (1).
57
 * @param int         $n        Cantidad
58
 * @param array|mixed $args     Lista de objetos que se van a incluir en las cadenas de formato del mensaje.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 108 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
 *
60
 * @return string
61
 * @since 0.6.0
62
 * @see \dngettext()
63
 * */
64
function nmsg($singular, $plural, $n, ...$args)
65
{
66
    $translated = \dngettext(NML_GETTEXT_DOMAIN, $singular, $plural, $n);
67
68
    $data = $args;
69
70
    if (count($args) === 1 && is_array($args[0])) {
71
        $data = $args[0];
72
    }
73
74
    return Text::format($translated, $data);
75
}
76
77
78
/**
79
 * Obtiene el tipo del objeto especificado.
80
 * Es un alias para el constructor de la clase Type.
81
 *
82
 * @param mixed $obj Objeto al cual se le extraerá su tipo.
83
 *
84
 * @return Type
85
 * @since 0.6.0
86
 * */
87
function typeof($obj)
88
{
89 279
    return new Type($obj);
90
}
91