Skip to content

Commit

Permalink
refactor: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 24, 2024
1 parent 3d53b1d commit c58a13d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/CantoDamAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class CantoDamAssets extends Plugin
{
use ServicesTrait;

public static ?CantoDamAssets $plugin = null;
public string $schemaVersion = '1.0.1';
public bool $hasCpSettings = true;

public static ?CantoDamAssets $plugin = null;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -93,7 +92,7 @@ static function(RegisterComponentTypesEvent $event) {
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function(RegisterUserPermissionsEvent $event) {
static function(RegisterUserPermissionsEvent $event) {
$event->permissions[] = [
"heading" => "Canto DAM Assets Picker Extraordinaire",
"permissions" => [
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/SyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class SyncController extends Controller
{
public $defaultAction = 'index';
protected array|int|bool $allowAnonymous = self::ALLOW_ANONYMOUS_LIVE;
public $enableCsrfValidation = false;
protected array|int|bool $allowAnonymous = self::ALLOW_ANONYMOUS_LIVE;

public function beforeAction($action): bool
{
Expand Down
14 changes: 7 additions & 7 deletions src/fields/CantoDamAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ public function attributeLabels(): array
]);
}

protected function defineRules(): array
{
return array_merge(parent::defineRules(), [
// ...
]);
}

public function getSettingsHtml(): ?string
{
return Craft::$app->getView()->renderTemplate('_canto-dam-assets/_components/fieldtypes/CantoDamAsset_settings.twig',
Expand Down Expand Up @@ -159,6 +152,13 @@ public function modifyElementsQuery(ElementQueryInterface $query, mixed $value):
// Protected Methods
// =========================================================================

protected function defineRules(): array
{
return array_merge(parent::defineRules(), [
// ...
]);
}

protected function searchKeywords(mixed $value, ElementInterface $element): string
{
/* @var CantoFieldData $value */
Expand Down
8 changes: 5 additions & 3 deletions src/lib/laravel/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace lsst\cantodamassets\lib\laravel;

use Closure;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection as LaravelCollection;

class Collection extends LaravelCollection
Expand All @@ -10,7 +12,7 @@ class Collection extends LaravelCollection
* Filter items by the given key value pair.
*
* @param string $key
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @param Arrayable|iterable $values
* @param bool $strict
* @return static
*/
Expand All @@ -32,7 +34,7 @@ public function whereIn($key, $values, $strict = false)
* Filter items by the given key value pair.
*
* @param string $key
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @param Arrayable|iterable $values
* @param bool $strict
* @return static
*/
Expand All @@ -56,7 +58,7 @@ public function whereNotIn($key, $values, $strict = false)
* @param callable|string $key
* @param string|null $operator
* @param mixed $value
* @return \Closure
* @return Closure
*/
protected function operatorForWhere($key, $operator = null, $value = null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/migrations/m231108_024521_change_to_json_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use lsst\cantodamassets\fields\CantoDamAsset;
use lsst\cantodamassets\lib\laravel\Collection;
use verbb\supertable\fields\SuperTableField;
use yii\db\Exception;
use yii\db\Schema;

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ private function changeToJsonColumn(string $table, array $fields): void
* @param $type
* @param $using
* @return void
* @throws \yii\db\Exception
* @throws Exception
*/
private function alterColumnUsingPgsql($table, $column, $type, $using): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/services/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Exception\GuzzleException;
use lsst\cantodamassets\CantoDamAssets;
use lsst\cantodamassets\models\CantoFieldData;
use Throwable;
use yii\base\Component;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ public function getAuthToken(): ?string
// Get auth token
try {
$response = $client->post($authEndpoint);
} catch (\Throwable $e) {
} catch (Throwable $e) {
Craft::error("An exception occurred in getAuthToken()", __METHOD__);

return $e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion src/variables/CantoVariable.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace lsst\cantodamassets\variables;

use nystudio107\pluginvite\variables\ViteVariableInterface;
use nystudio107\pluginvite\variables\ViteVariableTrait;

Expand Down

0 comments on commit c58a13d

Please sign in to comment.