@@ -48,7 +48,7 @@ |
||
48 | 48 | */ |
49 | 49 | public function decryptAttribute($value) |
50 | 50 | { |
51 | - return $value ? $this->encrypter()->decrypt($value) : ''; |
|
51 | + return $value ? $this->encrypter()->decrypt($value) : ''; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | public function encrypter() |
14 | 14 | { |
15 | - if(! $this->encrypter){ |
|
15 | + if (!$this->encrypter) { |
|
16 | 16 | $this->encrypter = new Encrypter(); |
17 | 17 | } |
18 | 18 | return $this->encrypter; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function encryptable($key) |
34 | 34 | { |
35 | - if(self::$enableEncryption){ |
|
35 | + if (self::$enableEncryption) { |
|
36 | 36 | return in_array($key, $this->encryptable); |
37 | 37 | } |
38 | 38 | return false; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function decrypt($value) |
25 | 25 | { |
26 | - $value = str_replace("{$this->getPrefix()}_",'',$value); |
|
26 | + $value = str_replace("{$this->getPrefix()}_", '', $value); |
|
27 | 27 | |
28 | 28 | return openssl_decrypt($value, $this->method, $this->getKey(), 0, $iv = ''); |
29 | 29 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public function getKey() |
37 | 37 | { |
38 | 38 | if ($this->key === null) { |
39 | - if(! Config::get('encrypt.key')) throw new \Exception('The .env value ENCRYPT_KEY has to be set'); |
|
39 | + if (!Config::get('encrypt.key')) throw new \Exception('The .env value ENCRYPT_KEY has to be set'); |
|
40 | 40 | $this->key = substr(hash('sha256', Config::get('encrypt.key')), 0, 16); |
41 | 41 | } |
42 | 42 | return $this->key; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function getPrefix() |
49 | 49 | { |
50 | - if(! $this->prefix){ |
|
50 | + if (!$this->prefix) { |
|
51 | 51 | $this->prefix = Config::get('encrypt.prefix'); |
52 | 52 | } |
53 | 53 | return $this->prefix; |
@@ -36,7 +36,9 @@ |
||
36 | 36 | public function getKey() |
37 | 37 | { |
38 | 38 | if ($this->key === null) { |
39 | - if(! Config::get('encrypt.key')) throw new \Exception('The .env value ENCRYPT_KEY has to be set'); |
|
39 | + if(! Config::get('encrypt.key')) { |
|
40 | + throw new \Exception('The .env value ENCRYPT_KEY has to be set'); |
|
41 | + } |
|
40 | 42 | $this->key = substr(hash('sha256', Config::get('encrypt.key')), 0, 16); |
41 | 43 | } |
42 | 44 | return $this->key; |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | $total = $this->model->where('encrypted', 1)->count(); |
43 | 43 | $this->model::$enableEncryption = false; |
44 | 44 | |
45 | - if($total > 0){ |
|
46 | - $this->comment($total.' records will be decrypted'); |
|
45 | + if ($total > 0) { |
|
46 | + $this->comment($total . ' records will be decrypted'); |
|
47 | 47 | $bar = $this->output->createProgressBar($total); |
48 | 48 | $bar->setFormat('%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); |
49 | 49 | |
50 | - $records = $this->model->orderBy('id', 'asc')->where('encrypted', 1)->get(); |
|
50 | + $records = $this->model->orderBy('id', 'asc')->where('encrypted', 1)->get(); |
|
51 | 51 | foreach ($records as $record) { |
52 | 52 | $record->timestamps = false; |
53 | 53 | $attributes = $this->getDecryptedAttributes($record); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | private function getDecryptedAttributes($record) |
66 | 66 | { |
67 | - $encryptedFields = ['encrypted' => 0 ]; |
|
67 | + $encryptedFields = ['encrypted' => 0]; |
|
68 | 68 | |
69 | 69 | foreach ($this->attributes as $attribute) { |
70 | 70 | $raw = $record->{$attribute}; |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | private function validateHasEncryptedColumn($model) |
81 | 81 | { |
82 | 82 | $table = $model->getTable(); |
83 | - if (! Schema::hasColumn($table, 'encrypted')) { |
|
83 | + if (!Schema::hasColumn($table, 'encrypted')) { |
|
84 | 84 | $this->comment('Creating encrypted column'); |
85 | - Schema::table($table, function (Blueprint $table) { |
|
85 | + Schema::table($table, function(Blueprint $table) { |
|
86 | 86 | $table->tinyInteger('encrypted')->default(0); |
87 | 87 | }); |
88 | 88 | } |
@@ -95,8 +95,9 @@ |
||
95 | 95 | */ |
96 | 96 | public function guardClass($class) |
97 | 97 | { |
98 | - if (!class_exists($class)) |
|
99 | - throw new \Exception("Class {$class} does not exists"); |
|
98 | + if (!class_exists($class)) { |
|
99 | + throw new \Exception("Class {$class} does not exists"); |
|
100 | + } |
|
100 | 101 | $model = new $class(); |
101 | 102 | $this->validateHasEncryptedColumn($model); |
102 | 103 | return $model; |
@@ -49,22 +49,22 @@ |
||
49 | 49 | { |
50 | 50 | $encrypter = new Encrypter(); |
51 | 51 | |
52 | - $countRecords = function ($table, $column, $value) use ($encrypter) { |
|
52 | + $countRecords = function($table, $column, $value) use ($encrypter) { |
|
53 | 53 | $value = $encrypter->encrypt(strtolower($value)); |
54 | 54 | return DB::table($table)->where($column, $value)->count(); |
55 | 55 | }; |
56 | 56 | |
57 | - Validator::extend('exists_encrypted', function ($attribute, $value, $parameters, $validator) use($countRecords) { |
|
57 | + Validator::extend('exists_encrypted', function($attribute, $value, $parameters, $validator) use($countRecords) { |
|
58 | 58 | $table = $parameters[0]; |
59 | 59 | $column = $parameters[1]; |
60 | 60 | |
61 | - return $countRecords($table,$column,$value) > 0; |
|
61 | + return $countRecords($table, $column, $value) > 0; |
|
62 | 62 | }); |
63 | 63 | |
64 | - Validator::extend('unique_encrypted', function ($attribute, $value, $parameters, $validator) use($countRecords) { |
|
64 | + Validator::extend('unique_encrypted', function($attribute, $value, $parameters, $validator) use($countRecords) { |
|
65 | 65 | $table = $parameters[0]; |
66 | 66 | $column = $parameters[1]; |
67 | - return $countRecords($table,$column,$value) == 0; |
|
67 | + return $countRecords($table, $column, $value) == 0; |
|
68 | 68 | }); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | \ No newline at end of file |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | $total = $this->model->where('encrypted', 0)->count(); |
43 | 43 | $this->model::$enableEncryption = false; |
44 | 44 | |
45 | - if($total > 0){ |
|
46 | - $this->comment($total.' records will be encrypted'); |
|
45 | + if ($total > 0) { |
|
46 | + $this->comment($total . ' records will be encrypted'); |
|
47 | 47 | $bar = $this->output->createProgressBar($total); |
48 | 48 | $bar->setFormat('%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); |
49 | 49 | |
50 | - $records = $this->model->orderBy('id', 'asc')->where('encrypted', 0)->get(); |
|
50 | + $records = $this->model->orderBy('id', 'asc')->where('encrypted', 0)->get(); |
|
51 | 51 | foreach ($records as $record) { |
52 | 52 | $record->timestamps = false; |
53 | 53 | $attributes = $this->getEncryptedAttributes($record); |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | private function validateHasEncryptedColumn($model) |
79 | 79 | { |
80 | 80 | $table = $model->getTable(); |
81 | - if (! Schema::hasColumn($table, 'encrypted')) { |
|
81 | + if (!Schema::hasColumn($table, 'encrypted')) { |
|
82 | 82 | $this->comment('Creating encrypted column'); |
83 | - Schema::table($table, function (Blueprint $table) { |
|
83 | + Schema::table($table, function(Blueprint $table) { |
|
84 | 84 | $table->tinyInteger('encrypted')->default(0); |
85 | 85 | }); |
86 | 86 | } |
@@ -93,8 +93,9 @@ |
||
93 | 93 | */ |
94 | 94 | public function guardClass($class) |
95 | 95 | { |
96 | - if (!class_exists($class)) |
|
97 | - throw new \Exception("Class {$class} does not exists"); |
|
96 | + if (!class_exists($class)) { |
|
97 | + throw new \Exception("Class {$class} does not exists"); |
|
98 | + } |
|
98 | 99 | $model = new $class(); |
99 | 100 | $this->validateHasEncryptedColumn($model); |
100 | 101 | return $model; |