Passed
Push — master ( dabdd0...83db8c )
by Wilmer
10:25
created

ViewFinderTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 30
ccs 4
cts 4
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getViewNames() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\View;
6
7
trait ViewFinderTrait
8
{
9
    private array $viewNames = [];
10
11
    /**
12
     * Returns all views names in the database.
13
     *
14
     * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema.
15
     *
16
     * @return array all views names in the database. The names have NO schema name prefix.
17
     */
18
    abstract protected function findViewNames(string $schema = ''): array;
19
20
    /**
21
     * Returns all view names in the database.
22
     *
23
     * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema
24
     * name. If not empty, the returned view names will be prefixed with the schema name.
25
     * @param bool $refresh whether to fetch the latest available view names. If this is false, view names fetched
26
     * previously (if available) will be returned.
27
     *
28
     * @return array all view names in the database.
29
     */
30 1
    public function getViewNames(string $schema = '', bool $refresh = false): array
31
    {
32 1
        if (!isset($this->viewNames[$schema]) || $refresh) {
33 1
            $this->viewNames[$schema] = $this->findViewNames($schema);
34
        }
35
36 1
        return $this->viewNames[$schema];
37
    }
38
}
39