Templates   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 18
dl 0
loc 36
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A entries() 0 19 6
A label() 0 3 1
A hasEntries() 0 3 1
A isVisible() 0 3 2
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