Skip to content

Commit

Permalink
LINTER LINTER
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysideup committed Apr 2, 2021
1 parent 71e22be commit 355a25f
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/Model/CustomProductList.php
Expand Up @@ -118,6 +118,7 @@ public function getCMSFields()
GridFieldBasicPageRelationConfigNoAddExisting::create()
);
$currentProductsField->setDescription('Calculated products, based on the list of included product codes (see Main Tab).');

$fields->addFieldToTab(
'Root.Main',
$currentProductsField
Expand Down Expand Up @@ -199,7 +200,7 @@ public function getProductsFromInternalItemIDs()
return $className::get()->filter(['InternalItemID' => $this->getProductsAsArray()]);
}

public function onBeforeWrite()
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if ($this->Locked) {
Expand All @@ -215,12 +216,12 @@ public function onBeforeWrite()
// Ensure that this object has a non-conflicting Title value.
$count = 2;
while ($this->titleExists()) {
$this->Title = preg_replace('/-[0-9]+$/', null, $this->Title) . '-' . $count;
$count++;
$this->Title = preg_replace('#-\d+$#', null, $this->Title) . '-' . $count;
++$count;
}
}

public function onAfterWrite()
protected function onAfterWrite()
{
parent::onAfterWrite();
$this->ProductsToAdd()->removeAll();
Expand Down Expand Up @@ -266,7 +267,6 @@ protected function RemoveProductsFromString($products, $write = false)

/**
* add one product
* @param Product $product
* @param bool $write -should the dataobject be written?
*/
protected function AddProductToString(Product $product, $write = false)
Expand All @@ -275,7 +275,7 @@ protected function AddProductToString(Product $product, $write = false)
if (is_array($array) && in_array($product->InternalItemID, $array, true)) {
return;
}
array_push($array, $product->InternalItemID);
$array[] = $product->InternalItemID;
$this->setProductsFromArray($array, $write);
}

Expand All @@ -290,13 +290,12 @@ protected function AddProductCodeToString($internalItemID, $write = false)
if (is_array($array) && in_array($internalItemID, $array, true)) {
return;
}
array_push($array, $internalItemID);
$array[] = $internalItemID;
$this->setProductsFromArray($array, $write);
}

/**
* remove one product
* @param Product $product
* @param bool $write -should the dataobject be written?
*/
protected function RemoveProductFromString(Product $product, $write = false)
Expand Down Expand Up @@ -354,11 +353,7 @@ protected function generateTitle()
$list = $this->Products();
$title = $this->title;
if (! $title) {
if ($list->count()) {
$title = implode('; ', $list->column('Title'));
} else {
$title = $this->defaultTitle();
}
$title = $list->count() ? implode('; ', $list->column('Title')) : $this->defaultTitle();
}
$filter = URLSegmentFilter::create();
$title = $filter->filter($title);
Expand All @@ -381,10 +376,6 @@ protected function titleExists()
->filter(['Title' => $this->Title])
->exclude(['ID' => $this->ID])
->count();
if ($existingListsWithThisTitleCount) {
return true;
}

return false;
return (bool) $existingListsWithThisTitleCount;
}
}

0 comments on commit 355a25f

Please sign in to comment.