Completed
Push — master ( 94d3aa...1e9c69 )
by Iman
05:12
created

TemplateNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 21
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 14 3
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils\Normalizers;
4
5
class TemplateNormalizer
6
{
7
    /**
8
     * Figures out which template to render.
9
     * @param object $widget
10
     * @return null
11
     */
12 16
    public function normalize($widget)
13
    {
14
        // class name without namespace.
15 16
        $className = str_replace('App\\Widgets\\', '', get_class($widget));
16
17
        // replace slashes with dots
18 16
        $className = str_replace(['\\', '/'], '.', $className);
19
20 16
        if (! property_exists($widget, 'template')) {
21 1
            $widget->template = 'Widgets::'.$className.'View';
22
        }
23
24 16
        if (! view()->exists($widget->template)) {
25
            throw new \InvalidArgumentException("View file \"{$widget->template}\" not found by: '".get_class($widget)." '");
26
        }
27 16
    }
28
}
29