Passed
Push — 1.0 ( 550c2d...ebbabc )
by Morven
08:49
created

LineItemExtension::getDownloadLink()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
c 0
b 0
f 0
rs 10
cc 4
nc 2
nop 0
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