Completed
Push — master ( 254668...40c8ec )
by
unknown
02:38
created

Deal   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 190
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createInstance() 0 10 2
C setValues() 0 22 7
1
<?php
2
3
namespace Padosoft\AffiliateNetwork;
4
5
/**
6
 * Class Deal
7
 * @package Padosoft\AffiliateNetwork
8
 */
9
class Deal
10
{
11
    /**
12
     * @var int
13
     */
14
    public $merchant_ID = 0;
15
16
    /**
17
     * @var string
18
     */
19
    public $merchant_name = '';
20
21
    /**
22
     * @var int
23
     */
24
    public $network_ID = 0;
25
26
    /**
27
     * @var int
28
     */
29
    public $type = 0;
30
31
    /**
32
     * @var string
33
     */
34
    public $code = '';
35
36
    /**
37
     * @var string
38
     */
39
    public $url = '';
40
41
    /**
42
     * @var \DateTime
43
     */
44
    public $start_date;
45
46
    /**
47
     * @var \DateTime
48
     */
49
    public $end_date;
50
51
    /**
52
     * @var \DateTime
53
     */
54
    public $update_date;
55
56
    /**
57
     * @var \DateTime
58
     */
59
    public $publish_start_date;
60
61
    /**
62
     * @var \DateTime
63
     */
64
    public $publish_end_date;
65
66
    /**
67
     * @var integer
68
     */
69
    public $deal_ID = 0;
70
71
    /**
72
     * @var string
73
     */
74
    public $currency_initial  = '';
75
76
    /**
77
     * @var string
78
     */
79
    public $language = '';
80
81
    /**
82
     * @var string
83
     */
84
    public $logo_path = '';
85
86
    /**
87
     * @var string
88
     */
89
    public $name = '';
90
91
    /**
92
     * @var string
93
     */
94
    public $short_description = '';
95
96
    /**
97
     * @var string
98
     */
99
    public $description = '';
100
101
    /**
102
     * @var string
103
     */
104
    public $information = '';
105
106
    /**
107
     * @var string
108
     */
109
    public $deal_type = '';
110
111
    /**
112
     * @var string
113
     */
114
    public $default_track_uri = '';
115
116
    /**
117
     * @var string
118
     */
119
    public $discount_amount='';
120
121
    /**
122
     * @var boolean
123
     */
124
    public $is_percentage = false;
125
126
    /**
127
     * @var boolean
128
     */
129
    public $is_exclusive = false;
130
131
    /**
132
     * @var boolean
133
     */
134
    public $is_site_specific = false;
135
136
    /**
137
     * @var string
138
     */
139
    public $landing_url = '';
140
141
    /**
142
     * @var string
143
     */
144
    public $ppv = '';
145
146
    /**
147
     * @var string
148
     */
149
    public $ppc = '';
150
151
    public function __construct() {
152
        $this->publish_end_date = $this->publish_start_date = $this->update_date = $this->end_date = $this->start_date = \DateTime::createFromFormat('Y-m-d','2000-01-01 00:00:00');
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFor... '2000-01-01 00:00:00') can also be of type false. However, the property $start_date is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Documentation Bug introduced by
It seems like $this->start_date = \Dat... '2000-01-01 00:00:00') can also be of type false. However, the property $end_date is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Documentation Bug introduced by
It seems like $this->end_date = $this-... '2000-01-01 00:00:00') can also be of type false. However, the property $update_date is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Documentation Bug introduced by
It seems like $this->update_date = $th... '2000-01-01 00:00:00') can also be of type false. However, the property $publish_start_date is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Documentation Bug introduced by
It seems like $this->publish_start_dat... '2000-01-01 00:00:00') can also be of type false. However, the property $publish_end_date is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
153
    }
154
155
    /**
156
     * @method createInstance
157
     * @return obj istance
158
     */
159
    public static function createInstance()
160
    {
161
        $obj = null;
162
        try {
163
            $obj = new Deal();
164
        } catch (\Exception $e) {
165
            throw new \Exception('Error creating instance Deal - ' . $e->getMessage());
166
        }
167
        return $obj;
168
    }
169
170
    /**
171
     * Move data from array to class by associative array source => destination
172
     * (skip invalid or empty fields)
173
     * @param array $source
174
     * @param array $association
175
     */
176
    public function setValues(array $source, array $association) {
177
        foreach ($association as $src => $dest) {
178
            if (array_key_exists($src, $source) && isset($this->$dest)) {
179
                if (strpos($dest, 'date') !== false) {
180
                    // Try to convert any date
181
                    $date = \DateTime::createFromFormat(\DateTime::ISO8601, $source[$src]);
182
                    if ($date === false) {
183
                        $date = \DateTime::createFromFormat("Y-m-d\TH:i:s.uO", $source[$src]);
184
                    }
185
                    if ($date !== false) {
186
                        $this->$dest = $date;
187
                    }
188
                }
189
                else {
190
                    $this->$dest = $source[$src];
191
                }
192
            }
193
            else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
194
                // Missing field .. ignore
195
            }
196
        }
197
    }
198
}
199