Failed Conditions
Branch feature/refactoring-samurai (8cc7c1)
by Giuliano
03:49
created

BaseException::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Maestriam\Samurai\Exceptions;
4
5
use Exception;
6
7
abstract class BaseException extends Exception
8
{
9
    /**
10
     * Inicia os atributos de acordo com o código de erro
11
     *
12
     * @param  string $code
13
     * @return void
14
     */
15
    public function initialize(string ...$params)
16
    {
17
        $this->setCode()->setMessage($params);
18
    }
19
20
    /**
21
     * Define qual será o número do código de retorno
22
     *
23
     * @param  integer $code
24
     * @return BaseException
25
     */
26
    protected function setCode() : BaseException
27
    {
28
        $this->code = $this->getErrorCode();
29
30
        return $this;
31
    }
32
33
    /**
34
     * Define a mensagem de texto que será enviado para o cliente
35
     *
36
     * @param  string $theme
37
     * @param  string $name
38
     * @return BaseException
39
     */
40
    protected function setMessage(array $params = []) : BaseException
41
    {
42
        $message = $this->getErrorMessage();
43
44
        $this->message = vsprintf($message, $params);
45
46
        return $this;
47
    }
48
49
    /**
50
     * Retorna a código de erro que será enviada ao cliente.  
51
     *
52
     * @return string
53
     */
54
    abstract public function getErrorCode() : string;
55
56
    
57
    /**
58
     * Retorna a mensagem de erro que será enviada ao cliente.  
59
     *
60
     * @return string
61
     */
62
    abstract public function getErrorMessage() : string;
63
}
64