Passed
Push — master ( 566a3a...fbef46 )
by 世昌
02:19
created

ReadStatement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAccess() 0 3 1
A __construct() 0 7 1
A one() 0 3 1
A fetchAll() 0 3 1
A all() 0 3 1
A fetch() 0 3 1
1
<?php
2
namespace suda\database\struct;
3
4
use suda\database\exception\SQLException;
5
use suda\database\TableAccess;
6
7
class ReadStatement extends \suda\database\statement\ReadStatement
8
{
9
    /**
10
     * 访问操作
11
     *
12
     * @var TableAccess
13
     */
14
    protected $access;
15
16
    public function __construct(TableAccess $access)
17
    {
18
        $this->access = $access;
19
        parent::__construct(
20
            $access->getSource()->write()->rawTableName($access->getStruct()->getName()),
21
            $access->getStruct(),
22
            $access->getMiddleware()
23
        );
24
    }
25
26
    /**
27
     * 取1
28
     *
29
     * @param string|null $class
30
     * @param array $args
31
     * @return mixed
32
     * @throws SQLException
33
     * @throws \ReflectionException
34
     */
35
    public function one(?string $class = null, array $args = [])
36
    {
37
        return $this->access->run($this->wantOne($class, $args));
38
    }
39
40
    /**
41
     * 取全部
42
     *
43
     * @param string|null $class
44
     * @param array $args
45
     * @return array
46
     * @throws SQLException
47
     * @throws \ReflectionException
48
     */
49
    public function all(?string $class = null, array $args = []):array
50
    {
51
        return $this->access->run($this->wantAll($class, $args));
52
    }
53
54
    /**
55
     * 取1
56
     *
57
     * @param string|null $class
58
     * @param array $args
59
     * @return mixed
60
     * @throws SQLException
61
     * @throws \ReflectionException
62
     */
63
    public function fetch(?string $class = null, array $args = [])
64
    {
65
        return $this->one($class, $args);
66
    }
67
68
    /**
69
     * 取全部
70
     *
71
     * @param string|null $class
72
     * @param array $args
73
     * @return array
74
     * @throws SQLException
75
     * @throws \ReflectionException
76
     */
77
    public function fetchAll(?string $class = null, array $args = []):array
78
    {
79
        return $this->all($class, $args);
80
    }
81
82
    /**
83
     * Get 访问操作
84
     *
85
     * @return  TableAccess
86
     */
87
    public function getAccess():TableAccess
88
    {
89
        return $this->access;
90
    }
91
}
92