Completed
Push — master ( f56bff...fdb40a )
by Andrii
02:24
created

CertificatePlan::getRawPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\plan;
12
13
use hiqdev\php\billing\customer\Customer;
14
use hiqdev\php\billing\plan\Plan;
15
use hiqdev\php\billing\price\EnumPrice;
16
use hiqdev\php\billing\target\Target;
17
use hiqdev\php\billing\type\Type;
18
use hiqdev\php\units\Unit;
19
use Money\Money;
20
21
class CertificatePlan extends Plan
22
{
23
    protected static $instance;
24
25
    public static function get()
26
    {
27
        if (static::$instance === null) {
28
            new static();
29
        }
30
31
        return static::$instance;
32
    }
33
34
    public function __construct()
35
    {
36
        if (static::$instance === null) {
37
            static::$instance = $this;
38
        }
39
        $this->seller   = new Customer(1, 'seller');
40
        $this->customer = new Customer(2, 'client', $this->seller);
0 ignored issues
show
Bug introduced by
The property customer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
        $this->purchase = new Type('certificate_purchase');
0 ignored issues
show
Bug introduced by
The property purchase does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
        $this->renewal  = new Type('certificate_renewal');
0 ignored issues
show
Bug introduced by
The property renewal does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        $this->rapidssl = new Target('certificate_type', 'rapidssl_standard');
0 ignored issues
show
Bug introduced by
The property rapidssl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
        $this->verisign = new Target('certificate_type', 'verisign_standard');
0 ignored issues
show
Bug introduced by
The property verisign does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
        $this->types = [
0 ignored issues
show
Bug introduced by
The property types does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
            'purchase'  => $this->purchase,
47
            'renewal'   => $this->renewal,
48
        ];
49
        $this->targets = [
0 ignored issues
show
Bug introduced by
The property targets does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
50
            'rapidssl'  => $this->rapidssl,
51
            'verisign'  => $this->verisign,
52
        ];
53
        $this->rawPrices = [
0 ignored issues
show
Bug introduced by
The property rawPrices does not seem to exist. Did you mean prices?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
54
            $this->getRawPriceKey($this->purchase, $this->rapidssl) => [
55
                1 => Money::USD(1129),
56
                2 => Money::USD(1219),
57
                3 => Money::USD(1309),
58
            ],
59
            $this->getRawPriceKey($this->renewal, $this->rapidssl) => [
60
                1 => Money::USD(1125),
61
                2 => Money::USD(1215),
62
                3 => Money::USD(1305),
63
            ],
64
            $this->getRawPriceKey($this->purchase, $this->verisign) => [
65
                1 => Money::USD(2129),
66
                2 => Money::USD(2219),
67
                3 => Money::USD(2309),
68
            ],
69
            $this->getRawPriceKey($this->renewal, $this->verisign) => [
70
                1 => Money::USD(2125),
71
                2 => Money::USD(2215),
72
                3 => Money::USD(2305),
73
            ],
74
        ];
75
        $prices = [];
76
        foreach ($this->types as $type) {
77
            foreach ($this->targets as $target) {
78
                $prices[] = new EnumPrice(null, $type, $target, Unit::year(), $this->getRawPrices($type, $target));
79
            }
80
        }
81
        parent::__construct(null, 'Test Certificate Plan', $this->seller, $prices);
82
    }
83
84
    public function getRawPrice($action)
85
    {
86
        $years = $action->getQuantity()->convert(Unit::year())->getQuantity();
87
        return $this->getRawPrices($action->getType(), $action->getTarget())[$years];
88
    }
89
90
    public function getRawPrices($type, $target)
91
    {
92
        return $this->rawPrices[$this->getRawPriceKey($type, $target)];
0 ignored issues
show
Bug introduced by
The property rawPrices does not seem to exist. Did you mean prices?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
93
    }
94
95
    public function getRawPriceKey($type, $target)
96
    {
97
        return $type->getName() . '-' . $target->getUniqId();
98
    }
99
}
100