CurrentOrdersReport   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 60
loc 60
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getReportField() 44 44 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * An extension to {@link SSReport} that allows a user
4
 * to view all Order instances that are "current",
5
 * {@link CurrentOrdersReport->getReportField()} has
6
 * the detail on the logic for what "Current" means.
7
 *
8
 *
9
 * @authors: Silverstripe, Jeremy, Nicolaas
10
 *
11
 * @package: ecommerce
12
 * @sub-package: reports
13
 *
14
 **/
15
16 View Code Duplication
class CurrentOrdersReport extends SS_Report
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    protected $title = 'Current Orders';
19
20
    protected $description = 'This shows all orders that are not paid or cancelled.';
21
22
    /**
23
     * Return a {@link ComplexTableField} that shows
24
     * all Order instances that are current.
25
     *
26
     * "Current" means all Orders that don't have a
27
     * Status property of "Complete" or "Cancelled".
28
     *
29
     * @return ComplexTableField
30
     */
31
    public function getReportField()
32
    {
33
        // Get the fields used for the table columns
34
        $fields = Order::get_summary_fields();
35
36
        // Add some fields specific to this report
37
        $fields['Invoice'] = '';
38
        $fields['Print'] = '';
39
40
        $table = new TableListField(
41
            'Orders',
42
            'Order',
43
            $fields
44
        );
45
46
        // Customise the SQL query for Order, because we don't want it querying
47
        // all the fields. Invoice and Printed are dummy fields that just have some
48
        // text in them, which would be automatically queried if we didn't specify
49
        // a custom query.
50
        $query = singleton('Order')->buildSQL("\"Order\".\"Status\" NOT IN ('Complete', 'Cancelled')", '"Order"."Created" DESC');
51
        $query->groupby[] = '"Order"."Created"';
52
        $table->setCustomQuery($query);
53
54
        // Set the links to the Invoice and Print fields allowing a user to view
55
        // another template for viewing an Order instance
56
        $table->setFieldFormatting(array(
57
            'Invoice' => '<a href=\"OrderReport_Popup/invoice/$ID\">Invoice</a>',
58
            'Print' => '<a target=\"_blank\" href=\"OrderReport_Popup/index/$ID?print=1\">Print</a>'
59
        ));
60
61
        $table->setFieldCasting(array(
62
            'Created' => 'Date',
63
            'Total' => 'Currency->Nice'
64
        ));
65
66
        $table->setPermissions(array(
67
            'edit',
68
            'show',
69
            'export',
70
            'delete',
71
        ));
72
73
        return $table;
74
    }
75
}
76