Completed
Pull Request — master (#329)
by Carlos
02:50
created

Order::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
/**
13
 * Order.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\Payment;
22
23
use EasyWeChat\Support\Attribute;
24
25
/**
26
 * Class Order.
27
 */
28
class Order extends Attribute
29
{
30
    const JSAPI = 'JSAPI';
31
    const NATIVE = 'NATIVE';
32
    const APP = 'APP';
33
    const MICROPAY = 'MICROPAY';
34
35
    protected $attributes = [
36
        'body',
37
        'detail',
38
        'attach',
39
        'out_trade_no',
40
        'fee_type',
41
        'total_fee',
42
        'spbill_create_ip',
43
        'time_start',
44
        'time_expire',
45
        'goods_tag',
46
        'notify_url',
47
        'trade_type',
48
        'product_id',
49
        'limit_pay',
50
        'openid',
51
        'sub_openid',
52
        'auth_code',
53
    ];
54
55
    /**
56
     * Constructor.
57
     *
58
     * @param array $attributes
59
     */
60 2
    public function __construct(array $attributes)
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
61
    {
62 2
        parent::__construct($attributes);
63
64 2
        $this->with('spbill_create_ip', $_SERVER['SERVER_ADDR']);
65 2
    }
66
}
67