irfaardy /
app-license-server
| 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
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
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
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
|
|||||
| 115 | return $return; |
||||
| 116 | } |
||||
| 117 | } |
||||
| 118 |