Completed
Push — ezp-31420-merge-up ( ec14fb...141a64 )
by
unknown
40:13 queued 27:42
created

InsertDoctrineQuery::insertInto()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Persistence\Doctrine;
8
9
use eZ\Publish\Core\Persistence\Database\InsertQuery;
10
use eZ\Publish\Core\Persistence\Database\QueryException;
11
12
/**
13
 * Class InsertDoctrineQuery.
14
 *
15
 * @deprecated Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection)
16
 *             it provides richer and more powerful DB abstraction which is also easier to use.
17
 */
18
class InsertDoctrineQuery extends AbstractDoctrineQuery implements InsertQuery
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...e\AbstractDoctrineQuery has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The interface eZ\Publish\Core\Persistence\Database\InsertQuery has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
19
{
20
    /** @var string */
21
    private $table;
22
23
    /** @var array */
24
    private $values = [];
25
26
    /**
27
     * Opens the query and sets the target table to $table.
28
     *
29
     * insertInto() returns a pointer to $this.
30
     *
31
     * @param string $table
32
     *
33
     * @return \eZ\Publish\Core\Persistence\Database\InsertQuery
34
     */
35
    public function insertInto($table)
36
    {
37
        $this->table = $table;
38
39
        return $this;
40
    }
41
42
    /**
43
     * The insert query will set the column $column to the value $expression.
44
     *
45
     * set() returns a pointer to $this.
46
     *
47
     * @param string $column
48
     * @param string $expression
49
     *
50
     * @return \eZ\Publish\Core\Persistence\Database\InsertQuery
51
     */
52
    public function set($column, $expression)
53
    {
54
        $this->values[$column] = $expression;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getQuery()
63
    {
64
        if (strlen($this->table) === 0) {
65
            throw new QueryException('Missing table name');
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
66
        }
67
68
        if (count($this->values) === 0) {
69
            throw new QueryException('Missing values');
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...Database\QueryException has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
70
        }
71
72
        return 'INSERT INTO ' . $this->table
73
               . ' (' . implode(', ', array_keys($this->values)) . ')'
74
               . ' VALUES (' . implode(', ', $this->values) . ')';
75
    }
76
}
77