Skip to content

Commit

Permalink
Minor updates as highlighted by Scrutinizer (#787)
Browse files Browse the repository at this point in the history
- OrderTotalCalculator.php: added missing public function declarations
- Used setField to apply values to fields in OrderProcessor.php, OrderActionsForm.php, Order.php & OrderStatusLog.php
- OrderProcessor.php: `Company` variable exists on the Address class (not Order)

Docs
- ShoppingCartController.php: added `string` to return type
- Product.php: added `false` as a possible return type to documentation of addLink, removeLink and removeallLink functions
- Variation.php: added `false` as a possible return type to the Link function
- CheckoutComponentConfig.php: corrected  docs for the getComponentByType function

Removed unused variables
- $page & $termsPage in PopulateShopTask.php
- $success in VariationForm.php
- $response in OrderStatusLogTest.php
- $filterperiod in ProductReport.php
- $record variable in imageByFilename & setParent functions in ProductBulkLoader.php
  • Loading branch information
AntonyThorpe authored Jul 13, 2023
1 parent d9d5d4b commit d8d585a
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/Admin/ProductBulkLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function processRecord($record, $columnMap, &$results, $preview = false)
}

// set image, based on filename
public function imageByFilename(&$obj, $val, $record)
public function imageByFilename(&$obj, $val)
{
$filename = trim(strtolower(Convert::raw2sql($val)));
$filenamedashes = str_replace(' ', '-', $filename);
Expand All @@ -165,7 +165,7 @@ public function imageByFilename(&$obj, $val, $record)
}

// find product group parent (ie Cateogry)
public function setParent(&$obj, $val, $record)
public function setParent(&$obj, $val)
{
$title = strtolower(Convert::raw2sql($val));
if ($title) {
Expand Down
8 changes: 4 additions & 4 deletions src/Cart/OrderTotalCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OrderTotalCalculator
*/
protected $order;

function __construct(Order $order)
public function __construct(Order $order)
{
$this->order = $order;
}
Expand All @@ -45,19 +45,19 @@ function __construct(Order $order)
* @throws Exception
* @throws \Psr\Container\NotFoundExceptionInterface
*/
function calculate()
public function calculate()
{
$runningtotal = $this->order->SubTotal();
$sort = 1;
$existingmodifiers = $this->order->Modifiers();

$modifierclasses = Order::config()->modifiers;

//check if modifiers are even in use
if (!is_array($modifierclasses) || empty($modifierclasses)) {
return $runningtotal;
}

$modifierclasses = array_unique($modifierclasses);

if (DB::get_conn()->supportsTransactions()) {
Expand Down
10 changes: 5 additions & 5 deletions src/Cart/ShoppingCartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected function buyableFromRequest()
*
* @param HTTPRequest $request
*
* @return HTTPResponse
* @return string|HTTPResponse
* @throws \SilverStripe\Control\HTTPResponse_Exception
*/
public function add($request)
Expand All @@ -216,7 +216,7 @@ public function add($request)
*
* @param HTTPRequest $request
*
* @return HTTPResponse
* @return string|HTTPResponse
* @throws \SilverStripe\Control\HTTPResponse_Exception
*/
public function remove($request)
Expand All @@ -235,7 +235,7 @@ public function remove($request)
*
* @param HTTPRequest $request
*
* @return HTTPResponse
* @return string|HTTPResponse
* @throws \SilverStripe\Control\HTTPResponse_Exception
*/
public function removeall($request)
Expand All @@ -254,7 +254,7 @@ public function removeall($request)
*
* @param HTTPRequest $request
*
* @return HTTPResponse
* @return string|HTTPResponse
* @throws \SilverStripe\Control\HTTPResponse_Exception
*/
public function setquantity($request)
Expand All @@ -275,7 +275,7 @@ public function setquantity($request)
*
* @param HTTPRequest $request
*
* @return HTTPResponse
* @return string|HTTPResponse
*/
public function clear($request)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Checkout/CheckoutComponentConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getComponents()
/**
* Returns the first available component with the given class or interface.
*
* @param String ClassName
* @param string $type ClassName
*
* @return CheckoutComponent
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Checkout/OrderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function getGatewayData($customData)
'firstName' => $this->order->FirstName,
'lastName' => $this->order->Surname,
'email' => $this->order->Email,
'company' => $this->order->Company,
'company' => $billing->Company,
'billingAddress1' => $billing->Address,
'billingAddress2' => $billing->AddressLine2,
'billingCity' => $billing->City,
Expand Down Expand Up @@ -231,7 +231,7 @@ public function completePayment()
|| ($this->order->GrandTotal() == 0 && Order::config()->allow_zero_order_total)
) {
//set order as paid
$this->order->Status = 'Paid';
$this->order->setField('Status', 'Paid');
$this->order->write();
}
}
Expand Down Expand Up @@ -287,13 +287,13 @@ public function placeOrder()

//update status
if ($this->order->TotalOutstanding(false)) {
$this->order->Status = 'Unpaid';
$this->order->setField('Status', 'Unpaid');
} else {
$this->order->Status = 'Paid';
$this->order->setField('Status', 'Paid');
}

if (!$this->order->Placed) {
$this->order->Placed = DBDatetime::now()->Rfc2822(); //record placed order datetime
$this->order->setField('Placed', DBDatetime::now()->Rfc2822()); //record placed order datetime
if ($request = Controller::curr()->getRequest()) {
$this->order->IPAddress = $request->getIP(); //record client IP
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/OrderActionsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function docancel($data, $form)
if (self::config()->allow_cancelling
&& $this->order->canCancel()
) {
$this->order->Status = 'MemberCancelled';
$this->order->setField('Status', 'MemberCancelled');
$this->order->write();

if (self::config()->email_notification) {
Expand Down
1 change: 0 additions & 1 deletion src/Forms/VariationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function addtocart($data, $form)
// if we are in just doing a validation step then check
if ($this->getRequest()->requestVar('ValidateVariant')) {
$message = '';
$success = false;

try {
$success = $variation->canPurchase(null, $data['Quantity']);
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ protected function statusTransition($fromStatus, $toStatus)
$this->extend('onStatusChange', $fromStatus, $toStatus);

if ($toStatus == 'Paid' && !$this->Paid) {
$this->Paid = DBDatetime::now()->Rfc2822();
$this->setField('Paid', DBDatetime::now()->Rfc2822());
foreach ($this->Items() as $item) {
$item->onPayment();
}
Expand All @@ -847,7 +847,7 @@ protected function statusTransition($fromStatus, $toStatus)

if (!$this->ReceiptSent) {
OrderEmailNotifier::create($this)->sendReceipt();
$this->ReceiptSent = DBDatetime::now()->Rfc2822();
$this->setField('ReceiptSent', DBDatetime::now()->Rfc2822());
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/Model/OrderStatusLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ protected function updateWithLastInfo()
->first();

if ($latestLog) {
$this->DispatchedBy = $latestLog->DispatchedBy;
$this->DispatchedOn = $latestLog->DispatchedOn;
$this->DispatchTicket = $latestLog->DispatchTicket;
$this->PaymentCode = $latestLog->PaymentCode;
$this->PaymentOK = $latestLog->PaymentOK;
$this->SentToCustomer = $latestLog->SentToCustomer;
$this->VisibleToCustomer = $latestLog->VisibleToCustomer;
$this->setField('DispatchedBy', $latestLog->DispatchedBy);
$this->setField('DispatchedOn', $latestLog->DispatchedOn);
$this->setField('DispatchTicket', $latestLog->DispatchTicket);
$this->setField('PaymentCode', $latestLog->PaymentCode);
$this->setField('PaymentOK', $latestLog->PaymentOK);
$this->setField('SentToCustomer', $latestLog->SentToCustomer);
$this->setField('VisibleToCustomer', $latestLog->VisibleToCustomer);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Variation/Variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function addLink()
*
* @param $action string
*
* @return string
* @return string|false
*/
public function Link($action = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Page/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public function Image()
/**
* Link to add this product to cart.
*
* @return string link
* @return string|false link
*/
public function addLink()
{
Expand All @@ -477,7 +477,7 @@ public function addLink()
/**
* Link to remove one of this product from cart.
*
* @return string link
* @return string|false link
*/
public function removeLink()
{
Expand All @@ -487,7 +487,7 @@ public function removeLink()
/**
* Link to remove all of this product from cart.
*
* @return string link
* @return string|false link
*/
public function removeallLink()
{
Expand Down
1 change: 0 additions & 1 deletion src/Reports/ProductReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function query($params)
$query->setFrom('"' . $table . '"');

$whereClue = '1';
$filterperiod = $this->periodfield;
if ($start && $end) {
$whereClue = sprintf(
'DATE("o"."Placed") BETWEEN DATE(\'%s\') AND DATE(\'%s\')',
Expand Down
6 changes: 3 additions & 3 deletions src/Tasks/PopulateShopTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function run($request)
}

//cart page
if (!$page = CartPage::get()->first()) {
if (!CartPage::get()->first()) {
$fixture = YamlFixture::create($fixtureDir . '/pages/Cart.yml');
$fixture->writeInto($factory);
$page = $factory->get(CartPage::class, 'cart');
Expand All @@ -100,7 +100,7 @@ public function run($request)
}

//checkout page
if (!$page = CheckoutPage::get()->first()) {
if (!CheckoutPage::get()->first()) {
$fixture = YamlFixture::create($fixtureDir . '/pages/Checkout.yml');
$fixture->writeInto($factory);
$page = $factory->get(CheckoutPage::class, 'checkout');
Expand All @@ -122,7 +122,7 @@ public function run($request)
}

//terms page
if (!$termsPage = Page::get()->filter('URLSegment', 'terms-and-conditions')->first()) {
if (!Page::get()->filter('URLSegment', 'terms-and-conditions')->first()) {
$fixture = YamlFixture::create($fixtureDir . '/pages/TermsConditions.yml');
$fixture->writeInto($factory);
$page = $factory->get('Page', 'termsconditions');
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Model/OrderStatusLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testOrderStatusLogItemsWithMember()
);

$processor = OrderProcessor::create($order);
$response = $processor->makePayment("Manual", []);
$processor->makePayment("Manual", []);
$order->Status = "Paid";
$order->write();

Expand Down Expand Up @@ -280,7 +280,7 @@ public function testOrderPlacedByGuest()
);

$processor_guest = OrderProcessor::create($order);
$response = $processor_guest->makePayment("Manual", []);
$processor_guest->makePayment("Manual", []);
$order->Status = "Paid";
$order->write();

Expand Down

0 comments on commit d8d585a

Please sign in to comment.