makeInsecureEmailChangeStrategy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Factory;
13
14
use Da\User\Contracts\MailChangeStrategyInterface;
15
use Da\User\Form\SettingsForm;
16
use Da\User\Strategy\DefaultEmailChangeStrategy;
17
use Da\User\Strategy\InsecureEmailChangeStrategy;
18
use Da\User\Strategy\SecureEmailChangeStrategy;
19
use Exception;
20
use Yii;
21
use yii\base\InvalidParamException;
22
23
class EmailChangeStrategyFactory
24
{
25
    protected static $map = [
26
        MailChangeStrategyInterface::TYPE_INSECURE => InsecureEmailChangeStrategy::class,
27
        MailChangeStrategyInterface::TYPE_DEFAULT => DefaultEmailChangeStrategy::class,
28
        MailChangeStrategyInterface::TYPE_SECURE => SecureEmailChangeStrategy::class,
29
    ];
30
31
    /**
32
     * @param $strategy
33
     * @param SettingsForm $form
34
     *
35
     * @throws Exception
36
     * @return MailChangeStrategyInterface
37
     *
38
     */
39 1
    public static function makeByStrategyType($strategy, SettingsForm $form)
40
    {
41 1
        if (array_key_exists($strategy, static::$map)) {
42 1
            return Yii::$container->get(static::$map[$strategy], [$form]);
43
        }
44
45
        throw new InvalidParamException('Unknown strategy type');
0 ignored issues
show
Deprecated Code introduced by
The class yii\base\InvalidParamException has been deprecated with message: since 2.0.14. Use [[InvalidArgumentException]] instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46
    }
47
48
    /**
49
     * @param SettingsForm $form
50
     *
51
     * @return DefaultEmailChangeStrategy
52
     */
53
    public static function makeDefaultEmailChangeStrategy(SettingsForm $form)
54
    {
55
        return Yii::$container->get(static::$map[MailChangeStrategyInterface::TYPE_DEFAULT], [$form]);
56
    }
57
58
    /**
59
     * @param SettingsForm $form
60
     *
61
     * @return InsecureEmailChangeStrategy
62
     */
63
    public static function makeInsecureEmailChangeStrategy(SettingsForm $form)
64
    {
65
        return Yii::$container->get(static::$map[MailChangeStrategyInterface::TYPE_INSECURE], [$form]);
66
    }
67
68
    /**
69
     * @param SettingsForm $form
70
     *
71
     * @return SecureEmailChangeStrategy
72
     */
73
    public static function makeSecureEmailChangeStrategy(SettingsForm $form)
74
    {
75
        return Yii::$container->get(static::$map[MailChangeStrategyInterface::TYPE_SECURE], [$form]);
76
    }
77
}
78