LineItemExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 25
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDownloadLink() 0 13 4
1
<?php
2
3
namespace SilverCommerce\DownloadableProducts;
4
5
use SilverStripe\ORM\DataExtension;
6
use SilverCommerce\OrdersAdmin\Model\Invoice;
7
8
class LineItemExtension extends DataExtension
9
{
10
11
    private static $casting = [
0 ignored issues
show
introduced by
The private property $casting is not used, and could be removed.
Loading history...
12
        "DownloadLink" => "Varchar"
13
    ];
14
15
    /**
16
     * Generate a link which can be used to download this product.
17
     * 
18
     * @return string
19
     */
20
    public function getDownloadLink()
21
    {
22
        $invoice = $this->getOwner()->Parent();
23
        $match = $this->getOwner()->match();
24
25
        if ($match && method_exists($match, "getDownloadLink") && $invoice->isPaid()) {
26
            return $match->getDownloadLink(
27
                $invoice->ID,
28
                $invoice->AccessKey
29
            );
30
        }
31
32
        return "";
33
    }
34
}
35