ResponseCodes::getMessage()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 8.439
c 0
b 0
f 0
cc 6
eloc 12
nc 5
nop 2
crap 6
1
<?php
2
3
/**
4
 * Copyright (c) 2014, Gustavo Henrique Mascarenhas Machado
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are met:
9
 *
10
 * * Redistributions of source code must retain the above copyright notice, this
11
 *   list of conditions and the following disclaimer.
12
 *
13
 * * Redistributions in binary form must reproduce the above copyright notice,
14
 *   this list of conditions and the following disclaimer in the documentation
15
 *   and/or other materials provided with the distribution.
16
 *
17
 * * Neither the name of CorreiosAPI nor the names of its
18
 *   contributors may be used to endorse or promote products derived from
19
 *   this software without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
 */
32
33
namespace CorreiosAPI\Tracker;
34
35
class ResponseCodes
36
{
37
  /**
38
   * Readable messages for the packages codes/statuses
39
   * @var array
40
   */
41
  protected static $responseCodes = [
42
      0  => 'Postado'
43
    , 1  => 'Entregue'
44
    , 2  => 'Destinatário ausente'
45
    , 3  => 'Não procurado'
46
    , 4  => 'Recusado'
47
    , 5  => 'Em devolução'
48
    , 6  => 'Destinatário desconhecido no endereço'
49
    , 7  => 'Endereço insuficiente para entrega'
50
    , 8  => 'Não existe o número indicado'
51
    , 9  => 'Extraviado'
52
    , 10 => 'Destinatário mudou-se'
53
    , 11 => 'Outros'
54
    , 12 => 'Refugado'
55
    , 14 => 'Aguardando retirada'
56
    , 15 => 'Conferido'
57
    , 16 => 'Conferido'
58
    , 17 => 'Conferido'
59
    , 18 => 'Conferido'
60
    , 19 => 'Endereço incorreto'
61
    , 20 => 'Destinatário ausente'
62
    , 21 => 'Destinatário ausente'
63
    , 22 => 'Reintegrado'
64
    , 23 => 'Distribuído ao remetente'
65
    , 24 => 'Disponível em caixa postal'
66
    , 25 => 'Empresa sem expediente'
67
    , 26 => 'Não procurado'
68
    , 27 => 'Pedido não solicitado'
69
    , 28 => 'Mercadoria avariada'
70
    , 31 => 'Extraviado'
71
    , 32 => 'Entrega programada'
72
    , 33 => 'Documentação não fornecida pelo destinatário'
73
    , 34 => 'Logradouro com numeração irregular - Em pesquisa'
74
    , 35 => 'Logística reversa simultânea'
75
    , 36 => 'Logística reversa simultânea'
76
    , 40 => 'Devolvido ao remetente'
77
    , 41 => 'Aguardando parte do lote'
78
    , 42 => 'Devolvido ao remetente'
79
    , 43 => 'Objeto apreendido por autoridade competente'
80
    , 44 => 'Falta documento para liberação para retirada interna'
81
    , 45 => 'Resíduo de mesa'
82
    , 46 => 'Entrega não efetuada'
83
    , 47 => 'Erro de lançamento'
84
    , 50 => 'Roubo a carteiro'
85
    , 51 => 'Roubo a veículo'
86
    , 52 => 'Roubo a unidade'
87
    , 54 => 'Aguardando pagamento de ICMS de importação'
88
    , 55 => 'Solicitada revisão do tributo'
89
    , 56 => 'Declaração aduaneira ausente ou incorreta'
90
    , 57 => 'Revisão de tributo concluída - Objeto liberado'
91
    , 58 => 'Revisão de tributo concluída - Tributo alterado'
92
    , 59 => 'Revisão de tributo concluída - Tributo mantido'
93
    , 66 => 'Área com distribuição sujeita a prazo diferenciado'
94
    , 69 => 'Objeto com atraso na entrega'
95
    , 'CAR' => 'Conferido'
96
    , 'CD'  => 'Conferido'
97
    , 'CMR' => 'Conferido'
98
    , 'CO'  => 'Conferido'
99
    , 'CUN' => 'Conferido'
100
    , 'DO'  => 'Encaminhado'
101
    , 'EST' => 'Estornado'
102
    , 'FC'  => [
103
          1 => 'Devolvido a pedido do cliente'
104
        , 2 => 'Com entrega agendada'
105
        , 3 => 'Mal encaminhado'
106
        , 4 => 'Mal endereçado'
107
        , 5 => 'Reintegrado'
108
        , 6 => 'Restrição lançamento externo'
109
        , 7 => 'Empresa sem expediente'
110
      ]
111
    , 'IDC' => 'Indenizado'
112
    , 'IE'  => 'Irregularidade na expedição'
113
    , 'IT'  => 'Passagem interna'
114
    , 'LDI' => [
115
          1 => 'Aguardando retirada'
116
        , 2 => 'Caixa postal'
117
        , 8 => 'Fiscalização'
118
      ]
119
    , 'OEC' => 'Saiu para entrega'
120
    , 'PMT' => 'Partiu em meio de transporte'
121
    , 'PO'  => 'Postado'
122
    , 'RO'  => [
123
          1  => 'Encaminhado'
124
        , 99 => 'Encaminhado (estornado)'
125
      ]
126
    , 'TR'  => 'Trânsito'
127
  ];
128
129
  /**
130
   * Returns a readable message of the current package status
131
   * @param  string $code   The status code (2-3 letters code)
132
   * @param  string $status The status number (1-2 digits)
133
   * @return string
134
   */
135 5
  public static function getMessage($code, $status)
136
  {
137 5
    $code   = strval($code);
138 5
    $status = intval($status);
139
140 5
    if (array_key_exists($code, self::$responseCodes)) {
141
      // Returns $responseCodes[$code][$status]
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
142 3
      if (is_array(self::$responseCodes[$code]) && array_key_exists($status, self::$responseCodes[$code])) {
143 1
        return self::$responseCodes[$code][$status];
144
      }
145
146
      // Returns $responseCodes[$code] if it's a string, otherwise implodes it and returns
147 2
      if (is_array(self::$responseCodes[$code])) {
148 1
        return implode(' - ', self::$responseCodes[$code]);
149
      }
150
151 1
      return self::$responseCodes[$code];
152
    }
153
154
    // Returns by status if there is no code
155 2
    if (isset(self::$responseCodes[$status])) {
156 1
      return self::$responseCodes[$status];
157
    }
158
159 1
    return "Desconhecido ({$code}-{$status})";
160
  }
161
}
162
163