Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 893b995

Browse files
authored
Merge pull request #1 from bavix/dev
global upgrade v2.0
2 parents c081848 + 41a7304 commit 893b995

File tree

14 files changed

+183
-30
lines changed

14 files changed

+183
-30
lines changed

.codeclimate.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exclude_patterns:
2+
- "config/"
3+
- "database/"
4+
- "docs/"
5+
- "resources/"
6+
- "tests/"

.scrutinizer.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
build:
2-
32
environment:
43
php:
54
version: 7.2
5+
pecl_extensions:
6+
- memcached
7+
memcached: true
68

79
nodes:
810
analysis:
911
project_setup:
1012
override: true
1113
tests:
1214
override:
13-
- php-scrutinizer-run
14-
-
15-
command: 'vendor/bin/phpunit --coverage-clover=some-file'
16-
coverage:
17-
file: 'some-file'
18-
format: 'clover'
15+
- php-scrutinizer-run
16+
- command: 'vendor/bin/phpunit --dump-xdebug-filter xdebug-filter.php'
17+
-
18+
command: 'vendor/bin/phpunit --prepend xdebug-filter.php --coverage-clover=some-file'
19+
coverage:
20+
file: 'some-file'
21+
format: 'clover'
1922

2023
filter:
21-
excluded_paths: [tests/*, database/*, config/*]
24+
excluded_paths: [docs/*, resources/*, tests/*, database/*, config/*]
2225

2326
checks:
2427

@@ -38,3 +41,11 @@ checks:
3841
fix_line_ending: true
3942
fix_identation_4spaces: true
4043
fix_doc_comments: true
44+
45+
coding_style:
46+
php:
47+
spaces:
48+
before_parentheses:
49+
closure_definition: true
50+
other:
51+
after_type_cast: false

.travis.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
language: php
22
php:
3-
- '7.1'
43
- '7.2'
54
- '7.3'
65
- '7.4snapshot'
76
- 'nightly'
87

8+
services:
9+
- memcached
10+
911
matrix:
1012
allow_failures:
1113
- php: '7.4snapshot'
1214
- php: 'nightly'
1315

1416
before_script:
15-
- "composer install"
17+
- pecl install pcov
18+
- phpenv config-rm xdebug.ini || echo "xdebug not available"
19+
- bash <(curl -s https://raw.githubusercontent.com/php-cache/cache/master/build/php/7.2/Memcached.sh)
20+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
21+
- chmod +x ./cc-test-reporter
22+
- if [ $(phpenv version-name) = "7.3" ]; then ./cc-test-reporter before-build; fi
23+
- composer install
24+
25+
script:
26+
- ./vendor/bin/phpunit --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml
27+
- ./vendor/bin/infection --coverage=build --min-msi=60 -j$(nproc)
28+
29+
after_success:
30+
- if [ $(phpenv version-name) = "7.3" ]; then ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT; fi
31+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![Code Coverage](https://scrutinizer-ci.com/g/bavix/laravel-settings/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/bavix/laravel-settings/?branch=master)
33
[![Build Status](https://scrutinizer-ci.com/g/bavix/laravel-settings/badges/build.png?b=master)](https://scrutinizer-ci.com/g/bavix/laravel-settings/build-status/master)
44
[![Code Intelligence Status](https://scrutinizer-ci.com/g/bavix/laravel-settings/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)
5+
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/bavix/laravel-settings/master)](https://packagist.org/packages/bavix/laravel-settings)
56

67
[![Package Rank](https://phppackages.org/p/bavix/laravel-settings/badge/rank.svg)](https://packagist.org/packages/bavix/laravel-settings)
78
[![Latest Stable Version](https://poser.pugx.org/bavix/laravel-settings/v/stable)](https://packagist.org/packages/bavix/laravel-settings)
@@ -14,10 +15,40 @@ laravel-settings - Keep user settings easy.
1415
* **Vendor**: bavix
1516
* **Package**: laravel-settings
1617
* **Version**: [![Latest Stable Version](https://poser.pugx.org/bavix/laravel-settings/v/stable)](https://packagist.org/packages/bavix/laravel-settings)
17-
* **PHP Version**: 7.1+
18+
* **PHP Version**: 7.2+
1819
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.0`
1920
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-settings`
2021

22+
### Usage
23+
Add the `HasSettings`, `HasSetSettings`, `HasGetSettings` trait and `Settingable` interface to model.
24+
```php
25+
use Bavix\Settings\Traits\HasSettings;
26+
use Bavix\Settings\Traits\HasSetSettings;
27+
use Bavix\Settings\Traits\HasGetSettings;
28+
use Bavix\Settings\Interfaces\Settingable;
29+
30+
class User extends Model implements Settingable
31+
{
32+
use HasGetSettings, HasSetSettings, HasSettings;
33+
}
34+
```
35+
36+
Checking user settings.
37+
38+
```php
39+
$user = User::first();
40+
$user->getSetting('notify'); // null
41+
$user->getSettingBool('notify'); // null
42+
$user->getSettingBool('notify', false); // bool(false)
43+
```
44+
45+
Let's save the settings.
46+
47+
```php
48+
(bool)$user->setSettingBool('notify', false); // bool(true)
49+
$user->getSettingBool('notify', false); // bool(false)
50+
```
51+
2152
---
2253
Supported by
2354

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^7.1",
25+
"php": "^7.2",
2626
"illuminate/database": "^5.5|^6.0"
2727
},
2828
"require-dev": {
29-
"orchestra/testbench": "^3.7",
29+
"infection/infection": "^0.14",
30+
"orchestra/testbench": "^4.2",
3031
"phpstan/phpstan": "^0.11",
31-
"phpunit/phpunit": "^7.5|^8.2"
32+
"phpunit/phpunit": "^8.4"
3233
},
3334
"autoload": {
3435
"psr-4": {

infection.json.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"timeout": 10,
3+
"source": {
4+
"directories": [
5+
"src"
6+
]
7+
},
8+
"logs": {
9+
"text": "build/infection.log",
10+
"badge": {
11+
"branch": "master"
12+
}
13+
},
14+
"mutators": {
15+
"@default": true
16+
}
17+
}

src/Interfaces/Settingable.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bavix\Settings\Interfaces;
4+
5+
use Bavix\Settings\Models\Setting;
6+
use Illuminate\Database\Eloquent\Collection;
7+
use Illuminate\Database\Eloquent\Relations\MorphMany;
8+
9+
/**
10+
* Interface Settingable
11+
* @package Bavix\Settings\Interfaces
12+
* @property-read Setting[]|Collection $settings
13+
*/
14+
interface Settingable
15+
{
16+
/**
17+
* @return MorphMany
18+
*/
19+
public function settings(): MorphMany;
20+
}

src/Models/Setting.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Eloquent\Relations\MorphTo;
77

8+
/**
9+
* Class Setting
10+
* @package Bavix\Settings\Models
11+
* @property string $key
12+
* @property string $cast
13+
* @property mixed $value
14+
*/
815
class Setting extends Model
916
{
1017

src/Services/ReadableService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Bavix\Settings\Services;
44

55
use Bavix\Settings\Models\Setting;
6-
use Illuminate\Database\Eloquent\Model;
6+
use Bavix\Settings\Interfaces\Settingable as Model;
77

88
class ReadableService
99
{

src/Services/SettingService.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Bavix\Settings\Models\Setting;
66
use Bavix\Settings\Traits\HasSettings;
77
use Illuminate\Database\Eloquent\Collection;
8-
use Illuminate\Database\Eloquent\Model;
8+
use Bavix\Settings\Interfaces\Settingable as Model;
99

1010
class SettingService
1111
{
@@ -47,13 +47,9 @@ public function delete(Model $model, string $key): bool
4747
->getSetting($model, $key);
4848

4949
if ($setting) {
50-
/**
51-
* @var Collection $collection
52-
*/
53-
$collection = $model->settings;
54-
foreach ($collection as $index => $item) {
50+
foreach ($model->settings as $index => $item) {
5551
if ($item === $setting) {
56-
$collection->forget($index);
52+
$model->settings->forget($index);
5753
break;
5854
}
5955
}

0 commit comments

Comments
 (0)