Passed
Push — master ( e26094...28949d )
by Paul
02:50
created

Templates::entries()   A

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
use GeminiLabs\BlackBar\Application;
6
7
class Templates implements Module
8
{
9
    /**
10
     * @var Application
11
     */
12
    protected $app;
13
    /**
14
     * @var array
15
     */
16
    protected $entries;
17
18
    public function __construct(Application $app)
19
    {
20
        $this->app = $app;
21
        $this->entries = [];
22
    }
23
24
    public function entries(): array
25
    {
26
        if (!empty($this->entries)) {
27
            return $this->entries;
28
        }
29
        if (class_exists('\GeminiLabs\Castor\Facades\Development')
30
            && class_exists('\GeminiLabs\Castor\Helpers\Development')
31
            && method_exists('\GeminiLabs\Castor\Helpers\Development', 'templatePaths')) { // @phpstan-ignore-line
32
            $this->entries = \GeminiLabs\Castor\Facades\Development::templatePaths();
1 ignored issue
show
Bug introduced by
The type GeminiLabs\Castor\Facades\Development was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
        } else {
34
            $files = array_values(array_filter(get_included_files(), function ($file) {
35
                $bool = false !== strpos($file, '/themes/') && false === strpos($file, '/functions.php');
36
                return (bool) apply_filters('blackbar/templates/file', $bool, $file);
37
            }));
38
            $this->entries = array_map(function ($file) {
39
                return str_replace(trailingslashit(WP_CONTENT_DIR), '', $file);
40
            }, $files);
41
        }
42
        return $this->entries;
43
    }
44
45
    public function hasEntries(): bool
46
    {
47
        return !empty($this->entries());
48
    }
49
50
    public function id(): string
51
    {
52
        return 'glbb-templates';
53
    }
54
55
    public function isVisible(): bool
56
    {
57
        return !is_admin();
58
    }
59
60
    public function label(): string
61
    {
62
        return __('Templates', 'blackbar');
63
    }
64
65
    public function render(): void
66
    {
67
        $this->app->render('panels/templates', ['templates' => $this]);
68
    }
69
}
70