Factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 15 1
1
<?php
2
3
namespace Webwizo\Shortcodes\View;
4
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\View\ViewFinderInterface;
7
use Illuminate\View\Engines\EngineResolver;
8
use Illuminate\View\Factory as IlluminateViewFactory;
9
use Webwizo\Shortcodes\Compilers\ShortcodeCompiler;
10
11
class Factory extends IlluminateViewFactory
12
{
13
    /**
14
     * Short code engine resolver
15
     *
16
     * @var ShortcodeCompiler
17
     */
18
    public $shortcode;
19
20
    /**
21
     * Create a new view factory instance.
22
     *
23
     * @param \Illuminate\View\Compilers\EngineResolver|EngineResolver $engines
24
     * @param  \Illuminate\View\ViewFinderInterface                    $finder
25
     * @param  \Illuminate\Events\Dispatcher                           $events
26
     * @param \Webwizo\Shortcodes\Compilers\ShortcodeCompiler          $shortcode
27
     */
28
    public function __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events, ShortcodeCompiler $shortcode)
29
    {
30
        parent::__construct($engines, $finder, $events);
31
        $this->shortcode = $shortcode;
32
    }
33
34
    /**
35
     * Get the evaluated view contents for the given view.
36
     *
37
     * @param  string $view
38
     * @param  array  $data
39
     * @param  array  $mergeData
40
     *
41
     * @return \Illuminate\Contracts\View\View|string|View
42
     */
43
    public function make($view, $data = [], $mergeData = [])
44
    {
45
        $path = $this->finder->find(
46
            $view = $this->normalizeName($view)
47
        );
48
49
        // Next, we will create the view instance and call the view creator for the view
50
        // which can set any data, etc. Then we will return the view instance back to
51
        // the caller for rendering or performing other view manipulations on this.
52
        $data = array_merge($mergeData, $this->parseData($data));
53
54
        return tap(new View($this->shortcode, $this, $this->getEngineFromPath($path), $view, $path, $data), function ($view) {
55
            $this->callCreator($view);
56
        });
57
    }
58
}
59