Completed
Push — master ( c6b5de...db50e7 )
by Dmitry
04:45
created

src/providers/FormulaExamplesProvider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\providers;
12
13
use Yii;
14
15
/**
16
 * Class FormulaExamplesProvider.
17
 *
18
 * @author Dmytro Naumenko <[email protected]>
19
 */
20
class FormulaExamplesProvider
21
{
22
    public function getGroups()
23
    {
24
        $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...
25
        $result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Growing discount'), $this->growingDiscountFormulas());
26
        $result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Leasing'), $this->leasingFormulas());
27
28
        return $result;
29
    }
30
31
    private function fixedDiscountFormulas()
32
    {
33
        return [
34
            sprintf("discount.fixed('10%%').since('%s').reason('because')", date('m.Y')),
35
            sprintf("discount.fixed('11 USD').since('%s').reason('agreed')", date('m.Y')),
36
            sprintf("discount.fixed('20%%').till('%s').reason('loyalty')", date('m.Y', strtotime('+6 months'))),
37
            sprintf("discount.fixed('5 tb').since('%s').reason('bonus')", date('m.Y')) => Yii::t('hipanel.finance.price', 'Applicable for overuse prices. The example will compensate up to 5 TB of overuse as discount. Make sure to use appropriate unit, such as <code>items</code>, <code>gbps</code> or <code>hours</code>.'),
38
            sprintf("discount.fixed('5 tb').as('deposit,compensation').since('%s').reason('bonus')", date('m.Y')) => Yii::t('hipanel.finance.price', 'Applicable for overuse prices. Will compensate up to 5 TB of overuse as a separate Compensation bill. You can use any other bill type in option <code>.as()</code>, such as <code>deposit,creditnote</code> or <code>correction,positive</code>.'),
39
        ];
40
    }
41
42
    private function growingDiscountFormulas()
43
    {
44
        return [
45
            sprintf("discount.since('%s').grows('10pp').every('month').reason('because')", date('m.Y')) => Yii::t('hipanel.finance.price', '<code>10pp</code> means "10 percent points". A percent point is the arithmetic difference of two percentages. For example, moving up from 40% to 50% is a 10 percentage point increase, but is an actual 25% percent increase in what is being measured.'),
46
            sprintf("discount.since('%s').grows('10%%').every('month').max('100%%').reason('because')", date('m.Y')),
47
            sprintf("discount.since('%s').grows('20 USD').every('2 months').min('30 USD').max('80 USD')", date('m.Y')),
48
            sprintf("discount.since('%s').grows('1%%').every('1 months').min('5%%').max('25%%')", date('m.Y')),
49
        ];
50
    }
51
52
    private function leasingFormulas()
53
    {
54
        return [
55
            sprintf("leasing.since('%s').lasts('3 months').reason('TEST')", date('m.Y')),
56
        ];
57
    }
58
59
    private function groupOf($name, $formulas)
60
    {
61
        return ['name' => $name, 'formulas' => $formulas];
62
    }
63
}
64