Passed
Pull Request — master (#130)
by
unknown
05:17
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
     * @param mixed $type
25
     * @param mixed $name
26
     * @param mixed $skeleton
27
     * @return array|void
28
     */
29
    public static function get($type, $name, $skeleton)
30
    {
31
        $skeletonView = MailEclipse::VIEW_NAMESPACE."::skeletons.{$type}.{$name}.{$skeleton}";
32
33
        if (View::exists($skeletonView)) {
34
            $skeletonViewPath = View::make($skeletonView)->getPath();
35
            $templateContent = Storage::get($skeletonViewPath);
36
37
            return [
38
                'type' => $type,
39
                'name' => $name,
40
                'skeleton' => $skeleton,
41
                'template' => Replacer::toEditor($templateContent),
42
                'view' => $skeletonView,
43
                'view_path' => $skeletonViewPath,
44
            ];
45
        }
46
    }
47
}
48