Skip to content

Commit b045ce5

Browse files
committed
Cleaning up scaffholding, phpstan, readme updates
1 parent 6711baf commit b045ce5

File tree

10 files changed

+42
-115
lines changed

10 files changed

+42
-115
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,49 @@ Automatically encrypt and decrypt database table fields.
1414

1515
You can install the package via composer:
1616

17-
```bash
17+
``` bash
1818
composer require venturedrake/laravel-encryptable
1919
```
2020

2121
You can publish the config file with:
22-
```bash
22+
``` bash
2323
php artisan vendor:publish --provider="VentureDrake\LaravelEncryptable\LaravelEncryptableServiceProvider" --tag="config"
2424
```
2525

2626
## Usage
2727

28+
Add the trait to your model and your encryptable rules.
2829
``` php
29-
TBC
30+
<?php
31+
32+
namespace App;
33+
34+
use Illuminate\Database\Eloquent\Model;
35+
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
36+
37+
class Person extends Model
38+
{
39+
use LaravelEncryptableTrait;
40+
41+
/**
42+
* Laravel Encryptable Rules
43+
*
44+
* @var array
45+
*/
46+
protected $encryptable = [
47+
'first_name',
48+
'last_name',
49+
];
50+
51+
...
52+
}
3053
```
3154

55+
Now when you store, update or read from the model the first_name and last_name fields will automatically be encrypted and decrypted.
56+
3257
## Testing
3358

34-
``` bash
59+
```bash
3560
composer test
3661
```
3762

composer.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "^2.17",
2323
"orchestra/testbench": "^4.0",
24-
"phpunit/phpunit": "^8.0",
25-
"vimeo/psalm": "^3.11"
24+
"phpstan/phpstan": "^0.12.65",
25+
"phpunit/phpunit": "^8.0"
2626
},
2727
"autoload": {
2828
"psr-4": {
29-
"VentureDrake\\LaravelEncryptable\\": "src",
30-
"VentureDrake\\LaravelEncryptable\\Database\\Factories\\": "database/factories"
29+
"VentureDrake\\LaravelEncryptable\\": "src"
3130
}
3231
},
3332
"autoload-dev": {
@@ -36,10 +35,10 @@
3635
}
3736
},
3837
"scripts": {
39-
"psalm": "vendor/bin/psalm",
4038
"test": "vendor/bin/phpunit --colors=always",
4139
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
42-
"format": "vendor/bin/php-cs-fixer fix --allow-risky=no"
40+
"format": "vendor/bin/php-cs-fixer fix --allow-risky=no",
41+
"analyse": "vendor/bin/phpstan analyse -c phpstan.neon"
4342
},
4443
"config": {
4544
"sort-packages": true
@@ -48,10 +47,7 @@
4847
"laravel": {
4948
"providers": [
5049
"VentureDrake\\LaravelEncryptable\\LaravelEncryptableServiceProvider"
51-
],
52-
"aliases": {
53-
"LaravelEncryptable": "VentureDrake\\LaravelEncryptable\\Facades\\LaravelEncryptableFacade"
54-
}
50+
]
5551
}
5652
},
5753
"minimum-stability": "dev",

database/factories/ModelFactory.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

database/migrations/create_laravel_encryptable_table.php.stub

Lines changed: 0 additions & 19 deletions
This file was deleted.

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- config
5+
- src
6+
- tests

psalm.xml.dist

Lines changed: 0 additions & 16 deletions
This file was deleted.

resources/views/.gitkeep

Whitespace-only changes.

src/Facades/LaravelEncryptableFacade.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/LaravelEncryptableServiceProvider.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,15 @@ public function boot()
1313
$this->publishes([
1414
__DIR__ . '/../config/laravel-encryptable.php' => config_path('laravel-encryptable.php'),
1515
], 'config');
16-
17-
$this->publishes([
18-
__DIR__ . '/../resources/views' => base_path('resources/views/vendor/laravel-encryptable'),
19-
], 'views');
20-
21-
$migrationFileName = 'create_laravel_encryptable_table.php';
22-
if (! $this->migrationFileExists($migrationFileName)) {
23-
$this->publishes([
24-
__DIR__ . "/../database/migrations/{$migrationFileName}.stub" => database_path('migrations/' . date('Y_m_d_His', time()) . '_' . $migrationFileName),
25-
], 'migrations');
26-
}
27-
16+
2817
$this->commands([
2918
LaravelEncryptableCommand::class,
3019
]);
3120
}
32-
33-
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'laravel-encryptable');
3421
}
3522

3623
public function register()
3724
{
3825
$this->mergeConfigFrom(__DIR__ . '/../config/laravel-encryptable.php', 'laravel-encryptable');
3926
}
40-
41-
public static function migrationFileExists(string $migrationFileName): bool
42-
{
43-
$len = strlen($migrationFileName);
44-
foreach (glob(database_path("migrations/*.php")) as $filename) {
45-
if ((substr($filename, -$len) === $migrationFileName)) {
46-
return true;
47-
}
48-
}
49-
50-
return false;
51-
}
5227
}

tests/TestCase.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,5 @@ public function getEnvironmentSetUp($app)
3434
'database' => ':memory:',
3535
'prefix' => '',
3636
]);
37-
38-
/*
39-
include_once __DIR__.'/../database/migrations/create_laravel_encryptable_table.php.stub';
40-
(new \CreatePackageTable())->up();
41-
*/
4237
}
4338
}

0 commit comments

Comments
 (0)