Completed
Push — master ( 89efb3...3f845f )
by Evgenii
03:40
created

HandlesErrors   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleErrors() 0 7 2
1
<?php
2
3
namespace Laratrade\Trader\Concerns;
4
5
use BadFunctionCallException;
6
7
trait HandlesErrors
8
{
9
    /**
10
     * The error messages.
11
     *
12
     * @var array
13
     */
14
    protected static $errors = [
15
        self::ERR_LIB_NOT_INITIALIZE        => 'Library not initialized',
16
        self::ERR_BAD_PARAM                 => 'Bad parameter',
17
        self::ERR_ALLOC_ERR                 => 'Allocation error',
18
        self::ERR_GROUP_NOT_FOUND           => 'Group not found',
19
        self::ERR_FUNC_NOT_FOUND            => 'Function not found',
20
        self::ERR_INVALID_HANDLE            => 'Invalid handle',
21
        self::ERR_INVALID_PARAM_HOLDER      => 'Invalid parameter holder',
22
        self::ERR_INVALID_PARAM_HOLDER_TYPE => 'Invalid parameter holder type',
23
        self::ERR_INVALID_PARAM_FUNCTION    => 'Invalid parameter function',
24
        self::ERR_INPUT_NOT_ALL_INITIALIZE  => 'Input not all initialized',
25
        self::ERR_OUTPUT_NOT_ALL_INITIALIZE => 'Output not all initialized',
26
        self::ERR_OUT_OF_RANGE_START_INDEX  => 'Out of range on start index',
27
        self::ERR_OUT_OF_RANGE_END_INDEX    => 'Out of range on end index',
28
        self::ERR_INVALID_LIST_TYPE         => 'Invalid list type',
29
        self::ERR_BAD_OBJECT                => 'Bad object',
30
        self::ERR_NOT_SUPPORTED             => 'Not supported',
31
        self::ERR_INTERNAL_ERROR            => 'Internal error',
32
        self::ERR_UNKNOWN_ERROR             => 'Unknown error',
33
    ];
34
35
    /**
36
     * Handle errors.
37
     */
38 6
    public function handleErrors()
39
    {
40 6
        $errorCode = trader_errno();
41 6
        if (isset(static::$errors[$errorCode])) {
42
            throw new BadFunctionCallException(static::$errors[$errorCode]);
43
        }
44 6
    }
45
}
46