Passed
Pull Request — master (#130)
by
unknown
10:48
created

TemplateSkeletons::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 15
rs 9.9
1
<?php
2
3
namespace Qoraiche\MailEclipse\Utils;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Facades\Storage;
7
use Illuminate\Support\Facades\View;
8
use Qoraiche\MailEclipse\MailEclipse;
9
use Qoraiche\MailEclipse\Utils\Replacer;
10
11
class TemplateSkeletons
12
{
13
    /**
14
     * Gets the template Skeletons from the configuration file.
15
     *
16
     * @return \Illuminate\Support\Collection
17
     */
18
    public static function skeletons()
19
    {
20
        return new Collection(config('maileclipse.skeletons'));
21
    }
22
23
    /**
24
     *
25
     * @param mixed $type
26
     * @param mixed $name
27
     * @param mixed $skeleton
28
     * @return array|void
29
     */
30
    public static function get($type, $name, $skeleton)
31
    {
32
        $skeletonView = MailEclipse::VIEW_NAMESPACE."::skeletons.{$type}.{$name}.{$skeleton}";
33
34
        if (View::exists($skeletonView)) {
35
            $skeletonViewPath = View::make($skeletonView)->getPath();
36
            $templateContent = Storage::get($skeletonViewPath);
37
38
            return [
39
                'type' => $type,
40
                'name' => $name,
41
                'skeleton' => $skeleton,
42
                'template' => Replacer::toEditor($templateContent),
43
                'view' => $skeletonView,
44
                'view_path' => $skeletonViewPath,
45
            ];
46
        }
47
    }
48
}
49