Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
frknasir authored and actions-user committed Mar 19, 2022
1 parent 20790d4 commit 2f6ee21
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Actions/SaveSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SaveSettings implements SavesSettings
{
/**
* Save the settings.
*
*
* @param \StarfolkSoftware\Kalibrant\Settings $settings
* @param array $data
* @return void
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/SavesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ interface SavesSettings
{
/**
* Save the settings.
*
*
* @param \StarfolkSoftware\Kalibrant\Settings $settings
* @param array $data
* @return void
*/
public function __invoke(Settings $settings, array $data): void;
}
}
8 changes: 4 additions & 4 deletions src/HasSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Illuminate\Contracts\Database\Eloquent\Builder;

trait HasSettings
trait HasSettings
{
/**
* Get all of the model's settings.
*
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function settings()
Expand All @@ -18,7 +18,7 @@ public function settings()

/**
* Retrieves a group of settings.
*
*
* @param string $group
* @return \StarfolkSoftware\Kalibrant\Settings
*/
Expand All @@ -36,7 +36,7 @@ public function settingsForGroup(string $group)
/**
* Scope a query to only include settings for the given setable type
* of the model.
*
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $setableType
* @return void
Expand Down
10 changes: 6 additions & 4 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace StarfolkSoftware\Kalibrant\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
}
4 changes: 2 additions & 2 deletions src/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SettingsController extends Controller
{
/**
* Updates the settings.
*
*
* @param \StarfolkSoftware\Kalibrant\Actions\SaveSettings $saveSettings
* @param string $group
* @param mixed $id
Expand Down Expand Up @@ -40,4 +40,4 @@ public function update(SaveSettings $saveSettings, string $group, $id)

return Redirect::back();
}
}
}
12 changes: 6 additions & 6 deletions src/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Setting extends Model

/**
* Determines if migrations should be run.
*
*
* @var bool
*/
public static $shouldRunMigrations = true;
Expand All @@ -46,17 +46,17 @@ public function setable()

/**
* Get attributes in group
*
*
* @param string $setableType
* @param int $setableId
* @param string $group
*
*
* @return array
*/
public static function attributesInGroup(string $setableType, int $setableId, string $group)
{
$setable = (new $setableType)::find($setableId);
$setable = (new $setableType())::find($setableId);

return $setable->settings()
->whereGroup($group)
->get(['key', 'value'])
Expand All @@ -67,7 +67,7 @@ public static function attributesInGroup(string $setableType, int $setableId, st

/**
* Ignores migrations.
*
*
* @return void
*/
public static function ignoreMigrations()
Expand Down
32 changes: 16 additions & 16 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class Settings implements JsonSerializable

/**
* The route to redirect to after update.
*
*
* @var mixed
*/
public $redirectRoute;
Expand All @@ -36,8 +36,8 @@ abstract class Settings implements JsonSerializable
public function __construct()
{
$attributes = Setting::attributesInGroup(
static::setableType(),
static::setableId(),
static::setableType(),
static::setableId(),
static::group()
);

Expand All @@ -51,45 +51,45 @@ public function __construct()
}

$this->resolver = new OptionsResolver();

$this->configureAttributes($this->resolver);

$this->attributes = $this->resolver->resolve($this->attributes);
}

/**
* Configures the settings attributes
*
*
* @param OptionsResolver $resolver
*
*
* @return void
*/
abstract public function configureAttributes(OptionsResolver $resolver);

/**
* Returns the setable type
*
*
* @return string
*/
abstract public static function setableType();

/**
* Returns the setable id
*
*
* @return int
*/
abstract public function setableId();

/**
* Returns the settings group
*
*
* @return string
*/
abstract public static function group();

/**
* Validation rules.
*
*
* @return array
*/
public function rules(): array
Expand All @@ -99,7 +99,7 @@ public function rules(): array

/**
* Returns resolver.
*
*
* @return \Symfony\Component\OptionsResolver\OptionsResolver
*/
public function getResolver(): OptionsResolver
Expand Down Expand Up @@ -237,23 +237,23 @@ public function __unset($key)
*/
public static function __callStatic($method, $parameters)
{
$instance = new static;
$instance = new static();

return call_user_func_array([$instance, $method], $parameters);
}

/**
* Updates settings
*
*
* @return void
*/
public function save()
{
collect($this->attributes)->each(function ($attribute, $key) {
Setting::updateOrCreate(
[
'setable_type' => static::setableType(),
'setable_id' => static::setableId(),
'setable_type' => static::setableType(),
'setable_id' => static::setableId(),
'group' => static::group(),
'key' => $key,
],
Expand All @@ -264,7 +264,7 @@ public function save()

/**
* To array.
*
*
* @return array
*/
public function toArray()
Expand Down
17 changes: 8 additions & 9 deletions tests/Mocks/TestSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSettings extends Settings
{
/**
* The route to redirect to after update.
*
*
* @var mixed
*/
public $redirectRoute = null;
Expand All @@ -22,16 +22,15 @@ class TestSettings extends Settings
*/
public function __construct(
protected $id
)
{
) {
parent::__construct();
}

/**
* Configure the settings attributes
*
*
* @param OptionsResolver $resolver
*
*
* @return void
*/
public function configureAttributes(OptionsResolver $resolver)
Expand All @@ -50,7 +49,7 @@ public function configureAttributes(OptionsResolver $resolver)

/**
* Returns the setable type
*
*
* @return string
*/
public static function setableType()
Expand All @@ -60,7 +59,7 @@ public static function setableType()

/**
* Returns the setable id
*
*
* @return int
*/
public function setableId()
Expand All @@ -70,11 +69,11 @@ public function setableId()

/**
* Return the settings group
*
*
* @return string
*/
public static function group()
{
return 'test-settings';
}
}
}
17 changes: 8 additions & 9 deletions tests/Mocks/TestSettingsWithRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSettingsWithRedirect extends Settings
{
/**
* The route to redirect to after update.
*
*
* @var mixed
*/
public $redirectRoute = 'settings.show';
Expand All @@ -22,16 +22,15 @@ class TestSettingsWithRedirect extends Settings
*/
public function __construct(
protected $id
)
{
) {
parent::__construct();
}

/**
* Configure the settings attributes
*
*
* @param OptionsResolver $resolver
*
*
* @return void
*/
public function configureAttributes(OptionsResolver $resolver)
Expand All @@ -50,7 +49,7 @@ public function configureAttributes(OptionsResolver $resolver)

/**
* Returns the setable type
*
*
* @return string
*/
public static function setableType()
Expand All @@ -60,7 +59,7 @@ public static function setableType()

/**
* Returns the setable id
*
*
* @return int
*/
public function setableId()
Expand All @@ -70,11 +69,11 @@ public function setableId()

/**
* Return the settings group
*
*
* @return string
*/
public static function group()
{
return 'test-settings-with-redirect';
}
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class TestUser extends User
use HasSettings;

protected $table = 'users';
}
}
1 change: 0 additions & 1 deletion tests/SettingsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use StarfolkSoftware\Kalibrant\Tests\Mocks\TestSettings;
use StarfolkSoftware\Kalibrant\Tests\Mocks\TestUser;

it('can retrieve a model\'s settings', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function createUser()
TestUser::forceCreate([
'name' => 'Faruk Nasir',
'email' => '[email protected]',
'password' => 'test'
'password' => 'test',
]);
}
}

0 comments on commit 2f6ee21

Please sign in to comment.