Skip to content

Commit

Permalink
ECS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Dec 28, 2023
1 parent 56f8a01 commit 26066cb
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 47 deletions.
23 changes: 11 additions & 12 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use studioespresso\exporter\models\ExportableCategoryModel;
use studioespresso\exporter\models\ExportableEntryModel;
use studioespresso\exporter\models\ExportableFormieSubmissionModel;
use studioespresso\exporter\models\ExportableFreeformSubmissionModel;
use studioespresso\exporter\models\Settings;
use studioespresso\exporter\records\ExportRecord;
use studioespresso\exporter\services\ExportQueryService;
Expand Down Expand Up @@ -80,7 +79,7 @@ public function init(): void
}

// Defer most setup tasks until Craft is fully initialized
Craft::$app->onInit(function () {
Craft::$app->onInit(function() {
Sprig::bootstrap();
$this->registerElementTypes();
$this->attachEventHandlers();
Expand Down Expand Up @@ -142,7 +141,7 @@ public function getCpNavItem(): array
private function registerElementTypes(): void
{
Event::on(Elements::class, Elements::EVENT_REGISTER_ELEMENT_TYPES,
function (RegisterComponentTypesEvent $event) {
function(RegisterComponentTypesEvent $event) {
$event->types[] = ExportElement::class;
});
}
Expand All @@ -152,7 +151,7 @@ private function registerCpRoutes(): void
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
function(RegisterUrlRulesEvent $event) {
$event->rules['exporter'] = ['template' => 'exporter/_index'];
$event->rules['exporter/create'] = 'exporter/element/edit';
$event->rules['exporter/<elementId:\\d+>/<step:\\d+>'] = 'exporter/element/edit';
Expand All @@ -167,7 +166,7 @@ private function registerSupportedElementTypes()
Event::on(
ElementTypeHelper::class,
ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES,
function (RegisterExportableElementTypes $event) {
function(RegisterExportableElementTypes $event) {
$entryModel = new ExportableEntryModel();
$categoryModel = new ExportableCategoryModel();
$event->elementTypes = array_merge($event->elementTypes, [
Expand All @@ -182,7 +181,7 @@ private function registerFieldParsers()
Event::on(
FieldTypeHelper::class,
FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES,
function (RegisterExportableFieldTypes $event) {
function(RegisterExportableFieldTypes $event) {
if (Craft::$app->getPlugins()->isPluginEnabled('ckeditor')) {
$event->fieldTypes[PlainTextParser::class][] = \craft\ckeditor\Field::class; // @phpstan-ignore-line
}
Expand All @@ -208,7 +207,7 @@ private function attachEventHandlers(): void
Event::on(
Gc::class,
Gc::EVENT_RUN,
function (Event $event) {
function(Event $event) {
// Delete `elements` table rows without peers in our custom products table
Craft::$app->getGc()->deletePartialElements(
ExportElement::class,
Expand All @@ -228,7 +227,7 @@ function (Event $event) {
Event::on(
CraftVariable::class,
CraftVariable::EVENT_DEFINE_BEHAVIORS,
function (DefineBehaviorsEvent $e) {
function(DefineBehaviorsEvent $e) {
$e->sender->attachBehaviors([
CraftVariableBehavior::class,
]);
Expand All @@ -238,7 +237,7 @@ function (DefineBehaviorsEvent $e) {
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
function(Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('exporter', ExporterVariable::class);
Expand All @@ -248,7 +247,7 @@ function (Event $event) {

private function registerUserPermissions()
{
Event::on(UserPermissions::class, UserPermissions::EVENT_REGISTER_PERMISSIONS, function (RegisterUserPermissionsEvent $event) {
Event::on(UserPermissions::class, UserPermissions::EVENT_REGISTER_PERMISSIONS, function(RegisterUserPermissionsEvent $event) {
$event->permissions[] = [
'heading' => Craft::t('exporter', 'Exporter'),
'permissions' => [
Expand All @@ -266,10 +265,10 @@ private function registerFormie()
Event::on(
ElementTypeHelper::class,
ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES,
function (RegisterExportableElementTypes $event) {
function(RegisterExportableElementTypes $event) {
$model = new ExportableFormieSubmissionModel();
$event->elementTypes = array_merge($event->elementTypes, [
\verbb\formie\elements\Submission::class => $model
\verbb\formie\elements\Submission::class => $model,
]);
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/ElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function actionRunExport()
if ($export->getErrors()) {
Craft::$app->getUrlManager()->setRouteParams([
"export" => $export,
"errors" => $export->getErrors()
"errors" => $export->getErrors(),
]);
return null;
}
Expand All @@ -70,7 +70,7 @@ public function actionRunExport()
'fields' => $export->getFields(),
'attributes' => $export->getAttributes(),
'runSettings' => $export->getRunSettings(),
'fileName' => $fileName
'fileName' => $fileName,
]));

$url = UrlHelper::cpUrl("exporter/{$export->id}/watch", ['fileName' => $fileName]);
Expand Down Expand Up @@ -172,7 +172,7 @@ public function actionStep1()
if ($export->getErrors()) {
Craft::$app->getUrlManager()->setRouteParams([
"export" => $export,
"errors" => $export->getErrors()
"errors" => $export->getErrors(),
]);
return null;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public function actionStep2()
if ($export->getErrors()) {
Craft::$app->getUrlManager()->setRouteParams([
"export" => $export,
"errors" => $export->getErrors()
"errors" => $export->getErrors(),
]);
return null;
}
Expand All @@ -228,7 +228,7 @@ public function actionStep3()
if ($export->getErrors()) {
Craft::$app->getUrlManager()->setRouteParams([
"export" => $export,
"errors" => $export->getErrors()
"errors" => $export->getErrors(),
]);
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions src/elements/ExportElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ public function scenarios()
*/
public function validate($attributeNames = null, $clearErrors = true): bool
{
if($this->scenario == 'step1') {
if ($this->scenario == 'step1') {
$settings = $this->getSettings();
if(!$settings['group']) {
if (!$settings['group']) {
$this->addError("group", "Group cannot be blank");
}

}
return parent::validate();
}
Expand Down
7 changes: 2 additions & 5 deletions src/fields/MultiOptionsFieldParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace studioespresso\exporter\fields;

use Craft;


class MultiOptionsFieldParser extends OptionsFieldParser
{
public function getValue($element, $field)
{
$selected = [];
$property = $field['property'] ?? 'value';

foreach($element->getFieldValue($field['handle'])->getOptions() as $option) {
if($option->selected) {
foreach ($element->getFieldValue($field['handle'])->getOptions() as $option) {
if ($option->selected) {
$selected[] = $option->$property;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/fields/OptionsFieldParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Craft;


class OptionsFieldParser extends BaseFieldParser
{
public function getValue($element, $field)
Expand All @@ -17,7 +16,7 @@ public function getOptions(): array
{
return [
'label' => 'Label',
'value' => 'Value'
'value' => 'Value',
];
}

Expand All @@ -29,7 +28,6 @@ public function getOptionType(): string|bool
public function getOptionLabel(): string|bool
{
return Craft::t('exporter', 'Select field property');

}

public function getOptionDescription(): string|bool
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ElementTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getElementTypesOnly(): array

$types = [];
foreach ($this->getAvailableElementTypes() as $model) {
if(!$model->validate()) {
if (!$model->validate()) {
\Craft::error("ExportableElementTypeModel is not configured correctly", Exporter::class);
continue;
}
Expand Down
1 change: 0 additions & 1 deletion src/helpers/FieldTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use studioespresso\exporter\events\RegisterExportableFieldTypes;
use studioespresso\exporter\fields\BaseFieldParser;
use studioespresso\exporter\fields\DateTimeParser;
use studioespresso\exporter\fields\LightswitchParser;
use studioespresso\exporter\fields\MoneyFieldParser;
use studioespresso\exporter\fields\MultiOptionsFieldParser;
use studioespresso\exporter\fields\OptionsFieldParser;
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/ExportBatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function execute($queue): void
if ($file) {
// Once the file has been generated, deliver the file according to the selected method
if (Exporter::getInstance()->mail->send($this->export, $file)) {
// unlink($file);
// unlink($file);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/models/ExportableCategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function getGroup(): array

public function getSubGroup(): bool|array
{
return false;
return false;
}

}
}
3 changes: 1 addition & 2 deletions src/models/ExportableElementTypeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ abstract class ExportableElementTypeModel extends Model
abstract public function getGroup(): bool|array;

abstract public function getSubGroup(): bool|array;

}
}
3 changes: 1 addition & 2 deletions src/models/ExportableEntryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ public function getSubGroup(): array
'function' => 'getEntryTypesBySectionId',
];
}

}
}
4 changes: 2 additions & 2 deletions src/models/ExportableFormieSubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function getGroup(): array

public function getSubGroup(): bool|array
{
return false;
return false;
}
}
}
6 changes: 2 additions & 4 deletions src/models/ExportableFreeformSubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Solspace\Freeform\Elements\Submission;
use Solspace\Freeform\Freeform;
use verbb\formie\Formie;

class ExportableFreeformSubmissionModel extends ExportableElementTypeModel
{
Expand All @@ -24,7 +23,6 @@ public function getGroup(): array

public function getSubGroup(): bool|array
{
return false;
return false;
}

}
}
4 changes: 1 addition & 3 deletions src/services/ExportQueryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function getFields(ExportElement $export, Element $element): array
$data = [];
$layout = $element->getFieldLayout();
foreach ($export->getFields() as $field) {


if(!$field['handle']) {
if (!$field['handle']) {
continue;
}

Expand Down

0 comments on commit 26066cb

Please sign in to comment.