Passed
Push — master ( 80d34d...67ed39 )
by Paul
02:55
created

Templates::id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\BlackBar\Modules;
4
5
use GeminiLabs\BlackBar\Application;
6
7
class Templates extends Module
8
{
9
    public function entries(): array
10
    {
11
        if (!empty($this->entries)) {
12
            return $this->entries;
13
        }
14
        if (class_exists('\GeminiLabs\Castor\Facades\Development')
15
            && class_exists('\GeminiLabs\Castor\Helpers\Development')
16
            && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line
17
            $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths();
18
        } else {
19
            $files = array_values(array_filter(get_included_files(), function ($file) {
20
                $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php');
21
                return (bool) apply_filters('blackbar/templates/file', $bool, $file);
22
            }));
23
            $this->entries = array_map(function ($file) {
24
                return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file);
25
            }, $files);
26
        }
27
        return $this->entries;
28
    }
29
30
    public function hasEntries(): bool
31
    {
32
        return !empty($this->entries());
33
    }
34
35
    public function isVisible(): bool
36
    {
37
        return !is_admin() && $this->hasEntries();
38
    }
39
40
    public function label(): string
41
    {
42
        return __('Templates', 'blackbar');
43
    }
44
}
45