ProductAmountOption   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setDiscountEndDateAttribute() 0 8 2
A getDiscountStartDateAttribute() 0 8 2
A setDiscountStartDateAttribute() 0 9 2
A product() 0 3 1
A getDiscountEndDateAttribute() 0 8 2
1
<?php 
2
3
namespace Hideyo\Ecommerce\Framework\Services\Product\Entity;
4
5
use Hideyo\Ecommerce\Framework\Services\BaseModel;
6
use Carbon\Carbon;
7
8
class ProductAmountOption extends BaseModel
9
{
10
    /**
11
     * The database table used by the model.
12
     *
13
     * @var string
14
     */    
15
    protected $table = 'product_amount_option';
16
17
    // Add the 'avatar' attachment to the fillable array so that it's mass-assignable on this model.
18
    protected $fillable = ['product_id',  'amount', 'discount_type', 'discount_value', 'discount_start_date', 'discount_end_date', 'modified_by_user_id'];
19
20
21
22
    public function setDiscountStartDateAttribute($value)
23
    {
24
        $this->attributes['discount_start_date'] = null;
25
26
        if ($value) {
27
            $date = explode('/', $value);
28
29
            $value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString();
0 ignored issues
show
Bug introduced by
$date[2] of type string is incompatible with the type integer|null expected by parameter $year of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $value = Carbon::createFromDate(/** @scrutinizer ignore-type */ $date[2], $date[1], $date[0])->toDateTimeString();
Loading history...
Bug introduced by
$date[1] of type string is incompatible with the type integer|null expected by parameter $month of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $value = Carbon::createFromDate($date[2], /** @scrutinizer ignore-type */ $date[1], $date[0])->toDateTimeString();
Loading history...
Bug introduced by
$date[0] of type string is incompatible with the type integer|null expected by parameter $day of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $value = Carbon::createFromDate($date[2], $date[1], /** @scrutinizer ignore-type */ $date[0])->toDateTimeString();
Loading history...
30
            $this->attributes['discount_start_date'] = $value;
31
        }
32
    }
33
34
    public function getDiscountStartDateAttribute($value)
35
    {
36
        if ($value) {
37
            $date = explode('-', $value);
38
            return $date[2].'/'.$date[1].'/'.$date[0];
39
        }
40
        
41
        return null;
42
    }
43
44
    public function setDiscountEndDateAttribute($value)
45
    {
46
        $this->attributes['discount_end_date'] = null;
47
48
        if ($value) {
49
            $date = explode('/', $value);
50
            $value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString();
0 ignored issues
show
Bug introduced by
$date[1] of type string is incompatible with the type integer|null expected by parameter $month of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $value = Carbon::createFromDate($date[2], /** @scrutinizer ignore-type */ $date[1], $date[0])->toDateTimeString();
Loading history...
Bug introduced by
$date[0] of type string is incompatible with the type integer|null expected by parameter $day of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $value = Carbon::createFromDate($date[2], $date[1], /** @scrutinizer ignore-type */ $date[0])->toDateTimeString();
Loading history...
Bug introduced by
$date[2] of type string is incompatible with the type integer|null expected by parameter $year of Carbon\Carbon::createFromDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $value = Carbon::createFromDate(/** @scrutinizer ignore-type */ $date[2], $date[1], $date[0])->toDateTimeString();
Loading history...
51
            $this->attributes['discount_end_date'] = $value;
52
        }
53
    }
54
55
    public function getDiscountEndDateAttribute($value)
56
    {
57
        if ($value) {
58
            $date = explode('-', $value);
59
            return $date[2].'/'.$date[1].'/'.$date[0];
60
        }
61
        
62
        return null;
63
    }
64
65
    public function product()
66
    {
67
        return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\Product\Entity\Product');
68
    }
69
}