ComponentFactory::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 22
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 28
rs 9.568
1
<?php
2
/**
3
 * Instant Analytics plugin for Craft CMS
4
 *
5
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
6
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 2 should be the @author tag
Loading history...
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
7
 * @link      http://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @copyright tag
Loading history...
8
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
The tag in position 4 should be the @link tag
Loading history...
9
 * @since     1.0.0
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\instantanalyticsGa4\ga4;
13
14
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddPaymentInfoEvent;
15
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddShippingInfoEvent;
16
use Br33f\Ga4\MeasurementProtocol\Dto\Event\AddToCartEvent;
17
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
18
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BeginCheckoutEvent;
19
use Br33f\Ga4\MeasurementProtocol\Dto\Event\LoginEvent;
20
use Br33f\Ga4\MeasurementProtocol\Dto\Event\PurchaseEvent;
21
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RefundEvent;
22
use Br33f\Ga4\MeasurementProtocol\Dto\Event\RemoveFromCartEvent;
23
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SearchEvent;
24
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SelectItemEvent;
25
use Br33f\Ga4\MeasurementProtocol\Dto\Event\SignUpEvent;
26
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewCartEvent;
27
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemEvent;
28
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewItemListEvent;
29
use Br33f\Ga4\MeasurementProtocol\Dto\Event\ViewSearchResultsEvent;
30
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\ItemParameter;
31
use Craft;
32
use nystudio107\instantanalyticsGa4\ga4\events\PageViewEvent;
33
34
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
36
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
37
 * @since     1.2.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
38
 *
39
 * @method ItemParameter ItemParameter()
40
 * @method AddPaymentInfoEvent AddPaymentInfoEvent()
41
 * @method AddToCartEvent AddToCartEvent()
42
 * @method AddShippingInfoEvent AddShippingInfoEvent()
43
 * @method BaseEvent BaseEvent()
44
 * @method BeginCheckoutEvent BeginCheckoutEvent()
45
 * @method LoginEvent LoginEvent()
46
 * @method PageViewEvent PageViewEvent()
47
 * @method PurchaseEvent PurchaseEvent()
48
 * @method RefundEvent RefundEvent()
49
 * @method RemoveFromCartEvent RemoveFromCartEvent()
50
 * @method SearchEvent SearchEvent()
51
 * @method SelectItemEvent SelectItemEvent()
52
 * @method SignUpEvent SignUpEvent()
53
 * @method ViewCartEvent ViewCartEvent()
54
 * @method ViewItemEvent ViewItemEvent()
55
 * @method ViewItemListEvent ViewItemListEvent()
56
 * @method ViewSearchResultsEvent ViewSearchResultsEvent()
57
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
58
class ComponentFactory
59
{
60
    public function __call(string $componentName, $args)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __call()
Loading history...
61
    {
62
        $componentMap = [
63
            'ItemParameter' => ItemParameter::class,
64
            'AddPaymentInfoEvent' => AddPaymentInfoEvent::class,
65
            'AddShippingInfoEvent' => AddShippingInfoEvent::class,
66
            'AddToCartEvent' => AddToCartEvent::class,
67
            'BaseEvent' => BaseEvent::class,
68
            'BeginCheckoutEvent' => BeginCheckoutEvent::class,
69
            'LoginEvent' => LoginEvent::class,
70
            'PageViewEvent' => PageViewEvent::class,
71
            'PurchaseEvent' => PurchaseEvent::class,
72
            'RefundEvent' => RefundEvent::class,
73
            'RemoveFromCartEvent' => RemoveFromCartEvent::class,
74
            'SearchEvent' => SearchEvent::class,
75
            'SelectItemEvent' => SelectItemEvent::class,
76
            'SignUpEvent' => SignUpEvent::class,
77
            'ViewCartEvent' => ViewCartEvent::class,
78
            'ViewItemEvent' => ViewItemEvent::class,
79
            'ViewItemListEvent' => ViewItemListEvent::class,
80
            'ViewSearchResultsEvent' => ViewSearchResultsEvent::class,
81
        ];
82
83
        if (!array_key_exists($componentName, $componentMap)) {
84
            throw new \InvalidArgumentException(Craft::t('instant-analytics-ga4', 'Unknown event type - ' . $componentName));
85
        }
86
        
87
        return new $componentMap[$componentName]();
88
    }
89
}
90