Skip to content

Commit 1980a53

Browse files
committed
refactor: ECS code cleanup
1 parent 994e536 commit 1980a53

File tree

11 files changed

+42
-46
lines changed

11 files changed

+42
-46
lines changed

src/Units.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010

1111
namespace nystudio107\units;
1212

13-
use nystudio107\units\fields\Units as UnitsField;
14-
use nystudio107\units\helpers\ClassHelper;
15-
use nystudio107\units\models\Settings;
16-
use nystudio107\units\variables\UnitsVariable;
17-
1813
use Craft;
1914
use craft\base\Plugin;
2015
use craft\events\PluginEvent;
2116
use craft\events\RegisterComponentTypesEvent;
17+
2218
use craft\services\Fields;
2319
use craft\services\Plugins;
2420
use craft\web\twig\variables\CraftVariable;
25-
26-
use yii\base\Event;
21+
use nystudio107\units\fields\Units as UnitsField;
22+
use nystudio107\units\helpers\ClassHelper;
23+
use nystudio107\units\models\Settings;
24+
use nystudio107\units\variables\UnitsVariable;
2725

2826
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
2927

28+
use yii\base\Event;
29+
3030
/**
3131
* Class Units
3232
*
@@ -71,7 +71,7 @@ public function init()
7171
Event::on(
7272
Fields::class,
7373
Fields::EVENT_REGISTER_FIELD_TYPES,
74-
function (RegisterComponentTypesEvent $event) {
74+
function(RegisterComponentTypesEvent $event) {
7575
$event->types[] = UnitsField::class;
7676
}
7777
);
@@ -80,7 +80,7 @@ function (RegisterComponentTypesEvent $event) {
8080
Event::on(
8181
CraftVariable::class,
8282
CraftVariable::EVENT_INIT,
83-
function (Event $event) {
83+
function(Event $event) {
8484
/** @var CraftVariable $variable */
8585
$variable = $event->sender;
8686
$variable->set('units', self::$variable);
@@ -90,7 +90,7 @@ function (Event $event) {
9090
Event::on(
9191
Plugins::class,
9292
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
93-
function (PluginEvent $event) {
93+
function(PluginEvent $event) {
9494
if ($event->plugin === $this) {
9595
}
9696
}
@@ -99,11 +99,11 @@ function (PluginEvent $event) {
9999
Event::on(
100100
UnitsField::class,
101101
'craftQlGetFieldSchema',
102-
function ($event) {
102+
function($event) {
103103
$field = $event->sender;
104104

105105
if (!$field instanceof UnitsField) {
106-
return;
106+
return;
107107
}
108108

109109
$object = $event->schema->createObjectType(ucfirst($field->handle) . 'Units');

src/assetbundles/units/UnitsAsset.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace nystudio107\units\assetbundles\units;
1212

13-
use Craft;
1413
use craft\web\AssetBundle;
1514
use craft\web\assets\cp\CpAsset;
1615

src/assetbundles/unitsfield/UnitsFieldAsset.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace nystudio107\units\assetbundles\unitsfield;
1212

13-
use Craft;
1413
use craft\web\AssetBundle;
1514
use craft\web\assets\cp\CpAsset;
1615

src/controllers/UnitsController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace nystudio107\units\controllers;
1212

13-
use nystudio107\units\Units;
14-
1513
use craft\web\Controller;
1614

15+
use nystudio107\units\Units;
16+
1717
use yii\web\Response;
1818

1919
/**

src/fields/Units.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@
1111

1212
namespace nystudio107\units\fields;
1313

14-
use nystudio107\units\assetbundles\unitsfield\UnitsFieldAsset;
15-
16-
use nystudio107\units\helpers\ClassHelper;
17-
use nystudio107\units\models\Settings;
18-
use nystudio107\units\models\UnitsData;
19-
use nystudio107\units\Units as UnitsPlugin;
20-
use nystudio107\units\validators\EmbeddedUnitsDataValidator;
21-
2214
use Craft;
15+
2316
use craft\base\ElementInterface;
2417
use craft\base\Field;
2518
use craft\base\PreviewableFieldInterface;
2619
use craft\helpers\Json;
2720
use craft\i18n\Locale;
2821

29-
use yii\base\InvalidConfigException;
22+
use nystudio107\units\assetbundles\unitsfield\UnitsFieldAsset;
23+
use nystudio107\units\helpers\ClassHelper;
24+
use nystudio107\units\models\Settings;
25+
use nystudio107\units\models\UnitsData;
26+
use nystudio107\units\Units as UnitsPlugin;
27+
use nystudio107\units\validators\EmbeddedUnitsDataValidator;
3028

31-
use PhpUnitsOfMeasure\AbstractPhysicalQuantity;
3229
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
3330

31+
use yii\base\InvalidConfigException;
32+
3433
/**
3534
* @author nystudio107
3635
* @package Units
@@ -178,7 +177,7 @@ public function normalizeValue($value, ElementInterface $element = null)
178177
if (!$unitsData->validate()) {
179178
Craft::error(
180179
Craft::t('units', 'UnitsData failed validation: ')
181-
.print_r($unitsData->getErrors(), true),
180+
. print_r($unitsData->getErrors(), true),
182181
__METHOD__
183182
);
184183
}
@@ -235,7 +234,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
235234
'prefix' => Craft::$app->getView()->namespaceInputId(''),
236235
];
237236
$jsonVars = Json::encode($jsonVars);
238-
Craft::$app->getView()->registerJs("$('#{$namespacedId}-field').UnitsUnits(".$jsonVars.");");
237+
Craft::$app->getView()->registerJs("$('#{$namespacedId}-field').UnitsUnits(" . $jsonVars . ");");
239238

240239
// Render the input template
241240
return Craft::$app->getView()->renderTemplate(

src/helpers/ClassHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ public static function getClassesInNamespace(string $className): array
5252

5353
return $result;
5454
}
55-
}
55+
}

src/models/Settings.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace nystudio107\units\models;
1212

13-
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
14-
1513
use craft\base\Model;
1614

15+
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
16+
1717
/**
1818
* @author nystudio107
1919
* @package Units
@@ -77,7 +77,7 @@ public function rules(): array
7777
['defaultUnitsClass', 'string'],
7878
['defaultUnitsClass', 'default', 'value' => Length::class],
7979
['defaultValue', 'number'],
80-
['defaultValue', 'default', 'value' => 0.0],
80+
['defaultValue', 'default', 'value' => 0.0],
8181
['defaultUnits', 'string'],
8282
['defaultUnits', 'default', 'value' => 'ft'],
8383
['defaultChangeableUnits', 'boolean'],
@@ -87,7 +87,7 @@ public function rules(): array
8787
['defaultMax'],
8888
'compare',
8989
'compareAttribute' => 'defaultMin',
90-
'operator' => '>='
90+
'operator' => '>=',
9191
],
9292
['defaultMin', 'default', 'value' => 0],
9393
['defaultMax', 'default', 'value' => null],

src/models/UnitsData.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
namespace nystudio107\units\models;
1313

14-
use nystudio107\units\Units;
15-
1614
use craft\base\Model;
1715

18-
use yii\base\InvalidArgumentException;
16+
use nystudio107\units\Units;
1917

20-
use PhpUnitsOfMeasure\UnitOfMeasure;
21-
use PhpUnitsOfMeasure\UnitOfMeasureInterface;
2218
use PhpUnitsOfMeasure\AbstractPhysicalQuantity;
19+
2320
use PhpUnitsOfMeasure\PhysicalQuantityInterface;
21+
use PhpUnitsOfMeasure\UnitOfMeasure;
22+
use PhpUnitsOfMeasure\UnitOfMeasureInterface;
23+
use yii\base\InvalidArgumentException;
2424

2525
/**
2626
* @author nystudio107

src/translations/en/units.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
'UnitsData failed validation: ' => 'UnitsData failed validation: ',
3535
'Default Decimal Points' => 'Default Decimal Points',
3636
'Default Units' => 'Default Units',
37-
'Default settings for newly created Units fields' => 'Default settings for newly created Units fields'
37+
'Default settings for newly created Units fields' => 'Default settings for newly created Units fields',
3838
];

src/validators/EmbeddedUnitsDataValidator.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace nystudio107\units\validators;
1313

14-
use nystudio107\units\models\UnitsData;
15-
1614
use Craft;
1715

16+
use nystudio107\units\models\UnitsData;
17+
1818
use yii\base\Model;
19-
use yii\validators\Validator;
2019
use yii\validators\NumberValidator;
20+
use yii\validators\Validator;
2121

2222
/**
2323
* @author nystudio107
@@ -105,7 +105,7 @@ protected function normalizeMinMax(UnitsData $unitsData)
105105
{
106106
$config = [
107107
'unitsClass' => $unitsData->unitsClass,
108-
'units' => $this->units
108+
'units' => $this->units,
109109
];
110110
// Normalize the min
111111
if (!empty($this->min)) {

src/variables/UnitsVariable.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use nystudio107\units\models\UnitsData;
1515

1616
use PhpUnitsOfMeasure\AbstractPhysicalQuantity;
17-
use PhpUnitsOfMeasure\PhysicalQuantityInterface;
1817
use PhpUnitsOfMeasure\PhysicalQuantity\Acceleration;
1918
use PhpUnitsOfMeasure\PhysicalQuantity\Angle;
2019
use PhpUnitsOfMeasure\PhysicalQuantity\Area;
@@ -87,7 +86,7 @@ public function __call($method, $args): UnitsData
8786
if (isset($this->unitsClassMap[$unitsClassKey])) {
8887
list($value, $units) = $args;
8988
$config = [
90-
'unitsClass' =>$this->unitsClassMap[$unitsClassKey],
89+
'unitsClass' => $this->unitsClassMap[$unitsClassKey],
9190
'value' => $value,
9291
'units' => $units,
9392
];
@@ -109,7 +108,7 @@ public function fraction(float $value): string
109108
{
110109
list($whole, $decimal) = $this->float2parts($value);
111110

112-
return $whole.' '.$this->float2ratio($decimal);
111+
return $whole . ' ' . $this->float2ratio($decimal);
113112
}
114113

115114
/**

0 commit comments

Comments
 (0)