Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
GeneralizedSql
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 stringify
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getRawSql
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20namespace Wikimedia\Rdbms;
21
22/**
23 * Lazy-loaded wrapper for simplification and scrubbing of SQL queries for profiling
24 *
25 * @since 1.34
26 * @ingroup Profiler
27 * @ingroup Database
28 */
29class GeneralizedSql {
30    /** @var string */
31    private $rawSql;
32    /** @var string */
33    private $prefix;
34
35    /** @var string|null */
36    private $genericSql;
37
38    /**
39     * @param string $rawSql
40     * @param string $prefix
41     */
42    public function __construct( $rawSql, $prefix ) {
43        $this->rawSql = $rawSql;
44        $this->prefix = $prefix;
45    }
46
47    /**
48     * @return string
49     */
50    public function stringify() {
51        if ( $this->genericSql !== null ) {
52            return $this->genericSql;
53        }
54
55        $this->genericSql = $this->prefix .
56            substr( QueryBuilderFromRawSql::generalizeSQL( $this->rawSql ), 0, 255 );
57
58        return $this->genericSql;
59    }
60
61    public function getRawSql() {
62        return $this->rawSql;
63    }
64}