Passed
Push — master ( 3a71d4...9cbcb0 )
by Xu
06:28
created

GatewayTrait::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link http://www.tintsoft.com/
4
 * @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
5
 * @license http://www.tintsoft.com/license/
6
 */
7
8
namespace yuncms\payment\traits;
9
10
use yii\helpers\Inflector;
11
use yuncms\helpers\StringHelper;
12
13
/**
14
 * Trait GatewayTrait
15
 * @package yuncms\payment\traits
16
 */
17
trait GatewayTrait
18
{
19
    /**
20
     * @var string gateway service id.
21
     * This value mainly used as HTTP request parameter.
22
     */
23
    private $_id;
24
25
    /**
26
     * @var string auth service name.
27
     * This value may be used in database records, CSS files and so on.
28
     */
29
    private $_name;
30
31
    /**
32
     * @var string auth service title to display in views.
33
     */
34
    private $_title;
35
36
    /**
37
     * @param string $id service id.
38
     */
39
    public function setId($id)
40
    {
41
        $this->_id = $id;
42
    }
43
44
    /**
45
     * @return string service id
46
     */
47
    public function getId()
48
    {
49
        if (empty($this->_id)) {
50
            $this->_id = $this->getName();
51
        }
52
        return $this->_id;
53
    }
54
55
    /**
56
     * @param string $name service name.
57
     */
58
    public function setName($name)
59
    {
60
        $this->_name = $name;
61
    }
62
63
    /**
64
     * @return string service name.
65
     */
66
    public function getName()
67
    {
68
        if ($this->_name === null) {
69
            $this->_name = $this->defaultName();
70
        }
71
        return $this->_name;
72
    }
73
74
    /**
75
     * @param string $title service title.
76
     */
77
    public function setTitle($title)
78
    {
79
        $this->_title = $title;
80
    }
81
82
    /**
83
     * @return string service title.
84
     */
85
    public function getTitle()
86
    {
87
        if ($this->_title === null) {
88
            $this->_title = $this->defaultTitle();
89
        }
90
        return $this->_title;
91
    }
92
93
    /**
94
     * Generates service name.
95
     * @return string service name.
96
     */
97
    protected function defaultName()
98
    {
99
        return Inflector::camel2id(StringHelper::basename(get_class($this)));
100
    }
101
102
    /**
103
     * Generates service title.
104
     * @return string service title.
105
     */
106
    protected function defaultTitle()
107
    {
108
        return StringHelper::basename(get_class($this));
109
    }
110
}