Completed
Push — master ( ea5d12...b135b5 )
by Evgenii
04:00
created

Trader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 10 3
1
<?php
2
3
namespace Laratrade\Trader;
4
5
use BadFunctionCallException;
6
use Laratrade\Trader\Contracts\MagicCalls;
7
use Laratrade\Trader\Contracts\Trader as TraderContract;
8
9
/**
10
 * Class Trader
11
 * @package Laratrade\Trader
12
 */
13
class Trader implements TraderContract
14
{
15
    use MagicCalls;
16
17
    /**
18
     * The error messages.
19
     *
20
     * @var array
21
     */
22
    protected static $errors = [
23
        self::ERR_BAD_PARAM                 => 'Bad parameter',
24
        self::ERR_ALLOC_ERR                 => 'Allocation error',
25
        self::ERR_GROUP_NOT_FOUND           => 'Group not found',
26
        self::ERR_FUNC_NOT_FOUND            => 'Function not found',
27
        self::ERR_INVALID_HANDLE            => 'Invalid handle',
28
        self::ERR_INVALID_PARAM_HOLDER      => 'Invalid parameter holder',
29
        self::ERR_INVALID_PARAM_HOLDER_TYPE => 'Invalid parameter holder type',
30
        self::ERR_INVALID_PARAM_FUNCTION    => 'Invalid parameter function',
31
        self::ERR_INPUT_NOT_ALL_INITIALIZE  => 'Input not all initialized',
32
        self::ERR_OUTPUT_NOT_ALL_INITIALIZE => 'Output not all initialized',
33
        self::ERR_OUT_OF_RANGE_START_INDEX  => 'Out of range on start index',
34
        self::ERR_OUT_OF_RANGE_END_INDEX    => 'Out of range on end index',
35
        self::ERR_INVALID_LIST_TYPE         => 'Invalid list type',
36
        self::ERR_BAD_OBJECT                => 'Bad object',
37
        self::ERR_NOT_SUPPORTED             => 'Not supported',
38
        self::ERR_INTERNAL_ERROR            => 'Internal error',
39
        self::ERR_UNKNOWN_ERROR             => 'Unknown error',
40
    ];
41
42
    /**
43
     * @param string $name
44
     * @param array  $arguments
45
     *
46
     * @return mixed
47
     */
48 6
    public function __call(string $name, array $arguments)
49
    {
50 6
        $result = call_user_func_array('trader_' . $name, $arguments);
51
52 6
        if (false === $result && isset(static::$errors[trader_errno()])) {
53
            throw new BadFunctionCallException(static::$errors[trader_errno()]);
54
        }
55
56 6
        return $result;
57
    }
58
}
59