Completed
Push — master ( 4f1415...383c20 )
by Dmitry
05:05
created

FormulaExamplesProvider::growingDiscountFormulas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\providers;
4
5
use Yii;
6
7
/**
8
 * Class FormulaExamplesProvider
9
 *
10
 * @author Dmytro Naumenko <[email protected]>
11
 */
12
class FormulaExamplesProvider
13
{
14
    public function getGroups()
15
    {
16
        $result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Fixed discount'), $this->fixedDiscountFormulas());
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
17
        $result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Growing discount'), $this->growingDiscountFormulas());
18
        $result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Leasing'), $this->leasingFormulas());
19
20
        return $result;
21
    }
22
23
    private function fixedDiscountFormulas()
24
    {
25
        return [
26
            sprintf("discount.since('%s').fixed('10%%').reason('because')", date('m.Y')),
27
            sprintf("discount.since('%s').fixed('11 USD').reason('agreed')", date('m.Y')),
28
            sprintf("discount.fixed('20%%').till('%s').reason('loyalty')", date('m.Y', strtotime('+6 months'))),
29
        ];
30
    }
31
32
    private function growingDiscountFormulas()
33
    {
34
        return [
35
            sprintf("discount.since('%s').grows('10%%').every('month').max('100%%').reason('because')", date('m.Y')),
36
            sprintf("discount.since('%s').min('50 USD').grows('20 USD').every('2 months').max('80 USD')", date('m.Y')),
37
            sprintf("discount.since('%s').min('5%%').grows('1%%').every('1 months').max('25%%')", date('m.Y')),
38
        ];
39
    }
40
41
    private function leasingFormulas()
42
    {
43
        return [
44
            sprintf("leasing.since('%s').lasts('3 months').reason('TEST')", date('m.Y')),
45
        ];
46
    }
47
48
    private function groupOf($name, $formulas)
49
    {
50
        return ['name' => $name, 'formulas' => $formulas];
51
    }
52
}
53