PostTemplates::list()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 18
rs 9.8666
1
<?php
2
3
namespace App\Services;
4
5
use Illuminate\Support\Facades\Storage;
6
7
class PostTemplates
8
{
9
    /**
10
     * Get all the post templates as a collection.
11
     *
12
     * @return array
13
     */
14
    public static function list($type = 'post')
15
    {
16
        $dir = 'post-layouts';
17
        if ($type != 'post') {
18
            $dir = $type.'-layouts';
19
        }
20
        $postTemplatefilesList = collect([]);
21
        $postTemplatefiles = Storage::disk($dir)->files('');
22
23
        foreach ($postTemplatefiles as $postTemplatefile) {
24
            $name = substr($postTemplatefile, 0, strpos($postTemplatefile, '.blade.php'));
25
            $postTemplatefilesList[] = [
26
                'name' => $name,
27
                'path' => 'blog.'.$dir.'.'.$name,
28
            ];
29
        }
30
31
        return $postTemplatefilesList;
32
    }
33
}
34