TemplateNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 22
ccs 6
cts 7
cp 0.8571
rs 10
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
use Imanghafoori\Widgets\Utils\NormalizerContract;
6
7
class TemplateNormalizer implements NormalizerContract
8
{
9
    /**
10
     * Figures out which template to render.
11
     *
12
     * @param  object  $widget
13
     * @return void
14
     */
15 24
    public function normalize($widget): void
16
    {
17
        // class name without namespace.
18 24
        $className = str_replace(app()->getNamespace().'Widgets\\', '', get_class($widget));
0 ignored issues
show
introduced by
The method getNamespace() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $className = str_replace(app()->/** @scrutinizer ignore-call */ getNamespace().'Widgets\\', '', get_class($widget));
Loading history...
19
20
        // replace slashes with dots
21 24
        $className = str_replace(['\\', '/'], '.', $className);
22
23 24
        if (! property_exists($widget, 'template')) {
24 1
            $widget->template = 'Widgets::'.$className.'View';
25
        }
26
27 24
        if (! view()->exists($widget->template)) {
28
            throw new \InvalidArgumentException("View file \"{$widget->template}\" not found by: '".get_class($widget)." '");
29
        }
30 24
    }
31
}
32