CheckoutStep::nextstep()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 13
rs 10
1
<?php
2
3
namespace SilverShop\Checkout\Step;
4
5
use SilverShop\Extension\SteppedCheckoutExtension;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Core\Config\Configurable;
8
use SilverStripe\Core\Extension;
9
10
/**
11
 * Base class for building steps for checkout processing
12
 */
13
class CheckoutStep extends Extension
14
{
15
    use Configurable;
16
17
    /**
18
     * Get the next step action
19
     *
20
     * @return string|NULL
21
     */
22
    private function nextstep()
23
    {
24
        $steps = $this->owner->getSteps();
25
        $found = false;
26
        foreach ($steps as $step => $class) {
27
            //determine if this is the current step
28
            if (method_exists($this, $step)) {
29
                $found = true;
30
            } elseif ($found) {
31
                return $step;
32
            }
33
        }
34
        return null;
35
    }
36
37
    public function NextStepLink($nextstep = null)
38
    {
39
        if (!$nextstep) {
40
            $nextstep = $this->nextstep();
41
        }
42
        $anchor = Config::inst()->get(SteppedCheckoutExtension::class, 'continue_anchor');
43
        $anchor = $anchor ? '#' . $anchor : '';
44
        return $this->owner->Link($nextstep) . $anchor;
45
    }
46
}
47