ViewFinderTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 29
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getViewNames() 0 7 3
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\db;
9
10
/**
11
 * ViewFinderTrait implements the method getViewNames for finding views in a database.
12
 *
13
 * @author Qiang Xue <[email protected]>
14
 * @author Bob Olde Hampsink <[email protected]>
15
 * @since 2.0.12
16
 */
17
trait ViewFinderTrait
18
{
19
    /**
20
     * @var array list of ALL view names in the database
21
     */
22
    private $_viewNames = [];
23
24
    /**
25
     * Returns all views names in the database.
26
     * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema.
27
     * @return array all views names in the database. The names have NO schema name prefix.
28
     */
29
    abstract protected function findViewNames($schema = '');
30
31
    /**
32
     * Returns all view names in the database.
33
     * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema name.
34
     * If not empty, the returned view names will be prefixed with the schema name.
35
     * @param bool $refresh whether to fetch the latest available view names. If this is false,
36
     * view names fetched previously (if available) will be returned.
37
     * @return string[] all view names in the database.
38
     */
39
    public function getViewNames($schema = '', $refresh = false)
40
    {
41
        if (!isset($this->_viewNames[$schema]) || $refresh) {
42
            $this->_viewNames[$schema] = $this->findViewNames($schema);
43
        }
44
45
        return $this->_viewNames[$schema];
46
    }
47
}
48