Templates::entries()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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