MonnifyOnFailureValidate::findOnFailureValidate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * Created By: Henry Ejemuta
4
 * Project: laravel-monnify
5
 * Class Name: MonnifyOnFailureValidate.php
6
 * Date Created: 7/15/20
7
 * Time Created: 8:06 AM
8
 */
9
10
namespace HenryEjemuta\LaravelMonnify\Classes;
11
12
13
class MonnifyOnFailureValidate
14
{
15
    private $onFailureValidate;
16
17
    private static $cache = [];
18
    private const BREAK = "BREAK";
19
    private const CONTINUE = "CONTINUE";
20
21
    /**
22
     * MonnifyOnFailureValidate constructor.
23
     * @param string $onFailureValidate
24
     */
25
    private function __construct(string $onFailureValidate)
26
    {
27
        $this->onFailureValidate = $onFailureValidate;
28
    }
29
30
    public static function BREAK(): MonnifyOnFailureValidate
31
    {
32
        if (!key_exists(self::BREAK, self::$cache))
33
            self::$cache[self::BREAK] = new MonnifyOnFailureValidate( self::BREAK);
34
        return self::$cache[self::BREAK];
35
    }
36
37
    public static function CONTINUE(): MonnifyOnFailureValidate
38
    {
39
        if (!key_exists(self::CONTINUE, self::$cache))
40
            self::$cache[self::CONTINUE] = new MonnifyOnFailureValidate( self::CONTINUE);
41
        return self::$cache[self::CONTINUE];
42
    }
43
44
    public static function findOnFailureValidate(string $onFailureValidate): MonnifyOnFailureValidate
45
    {
46
        switch (strtoupper($onFailureValidate)) {
47
            case self::BREAK:
48
                return self::BREAK();
49
            case self::CONTINUE:
50
                return self::CONTINUE();
51
            default:
52
                return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null returns the type null which is incompatible with the type-hinted return HenryEjemuta\LaravelMonn...onnifyOnFailureValidate.
Loading history...
53
        }
54
    }
55
56
    public function __toString(): string
57
    {
58
        return $this->onFailureValidate;
59
    }
60
61
}
62