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

Templates   A

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
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