SerialManager   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 52
c 2
b 0
f 1
dl 0
loc 106
rs 10
wmc 16

9 Methods

Rating   Name   Duplication   Size   Complexity  
A disabled() 0 8 2
A disableSN() 0 3 1
A enableSN() 0 3 1
A expired() 0 13 3
A renewSN() 0 16 2
A exists() 0 8 2
A checkAvaibility() 0 7 2
A insertToTable() 0 3 1
A createLicense() 0 16 2
1
<?php
2
/* 
3
	Author: Irfa Ardiansyah <[email protected]>
4
*/
5
namespace Irfa\AppLicenseServer\Core;
6
7
use Illuminate\Support\Str;
8
use Irfa\AppLicenseServer\Models\LicenseSerial;
9
10
class SerialManager extends SerialGenerator
11
{
12
    private $generated_serial;
0 ignored issues
show
introduced by
The private property $generated_serial is not used, and could be removed.
Loading history...
13
    private $name;
14
    private $domain;
15
    private $phone_number;
16
    private $address;
17
    private $serial;
18
    private $expired;
19
    private $status;
20
21
22
    protected function expired($sn)
23
    {
24
        $exp = LicenseSerial::where('serial',$sn)->first();
25
        if(empty($exp))
26
        {
27
            return true;
28
        } else{
29
            if($exp->expired > strtotime(date('Y-m-d')))
30
            {
31
                return false;
32
            }
33
34
            return true;
35
        }
36
    } 
37
38
    protected function disabled($sn)
39
    {
40
        $disabled = LicenseSerial::where('serial',$sn)->first();
41
        if($disabled->status==1)
42
        {
43
            return true;
44
        } 
45
            return false;
46
        
47
    }
48
49
    protected function exists($sn)
50
    {
51
        $exp = LicenseSerial::where('serial',$sn)->count();
52
        if(empty($exp))
53
        {
54
            return false;
55
        } 
56
            return true;
57
    }
58
59
    protected function createLicense($params, $expired)
60
    {
61
        $sn =  $this->generateSerial();
62
        $expired = strtotime($expired);
63
        if($this->checkAvaibility($sn))
64
        {
65
            $this->name = $params['name'];
66
            $this->domain = $params['domain'];
67
            $this->phone_number = $params['phone_number'];
68
            $this->address = $params['address'];
69
            $this->serial =$sn;
70
            $this->expired = $expired;
71
72
            return $this->insertToTable();
73
        } else{
74
            return $this->createLicense($params);
0 ignored issues
show
Bug introduced by
The call to Irfa\AppLicenseServer\Co...anager::createLicense() has too few arguments starting with expired. ( Ignorable by Annotation )

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

74
            return $this->/** @scrutinizer ignore-call */ createLicense($params);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
75
        }
76
    }
77
    private function checkAvaibility($sn)
78
    {
79
        if(LicenseSerial::where('serial',$sn)->count() == 0)
80
        {
81
            return true;
82
        } 
83
            return false;
84
    }
85
    private function insertToTable()
86
    {
87
        return LicenseSerial::create(['name'=>$this->name,'domain'=>$this->domain,'phone_number'=>$this->phone_number,'address'=>$this->address,'serial'=>$this->serial,'expired'=>$this->expired]);
88
    }
89
90
    protected function disableSN($sn)
91
    {
92
         return LicenseSerial::where('serial',$sn)->update(['status'=>1]);
93
    }
94
95
    protected function enableSN($sn)
96
    {
97
         return LicenseSerial::where('serial',$sn)->update(['status'=>0]);
98
    }
99
100
    protected function renewSN($sn,$days)
101
    {
102
        if($this->exists($sn))
103
        {
104
            $days = strtotime($days);
105
            $sn = LicenseSerial::where('serial',$sn);
106
            $sn->update(['expired' =>  $days]);
107
108
            $return = $sn->first();
109
            $return['message'] = "Renew serial number succesfully";
110
            $return['expired'] = date("Y-m-d, H:m:s",$days);
111
            return $return;
112
113
        }
114
        $return['message'] = "Renew serial number Failed because serial number not exists.";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$return was never initialized. Although not strictly required by PHP, it is generally a good practice to add $return = array(); before regardless.
Loading history...
115
         return $return;
116
    }
117
}
118