Completed
Push — 2.1 ( 7c8525...0afc41 )
by Alexander
21:05 queued 16:02
created

ViewFinderTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 31
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
findViewNames() 0 1 ?
A getViewNames() 0 8 3
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://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