DeleteWriter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 39
c 1
b 0
f 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A write() 0 11 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 6/11/14
5
 * Time: 1:50 AM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Sql\QueryBuilder\Builder\Syntax;
12
13
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
14
use NilPortugues\Sql\QueryBuilder\Manipulation\Delete;
15
16
/**
17
 * Class DeleteWriter.
18
 */
19
class DeleteWriter
20
{
21
    /**
22
     * @var GenericBuilder
23
     */
24
    private $writer;
25
26
    /**
27
     * @var PlaceholderWriter
28
     */
29
    private $placeholderWriter;
30
31
    /**
32
     * @param GenericBuilder    $writer
33
     * @param PlaceholderWriter $placeholder
34
     */
35
    public function __construct(GenericBuilder $writer, PlaceholderWriter $placeholder)
36
    {
37
        $this->writer = $writer;
38
        $this->placeholderWriter = $placeholder;
39
    }
40
41
    /**
42
     * @param Delete $delete
43
     *
44
     * @return string
45
     */
46
    public function write(Delete $delete)
47
    {
48
        $table = $this->writer->writeTable($delete->getTable());
49
        $parts = array("DELETE FROM {$table}");
50
51
        AbstractBaseWriter::writeWhereCondition($delete, $this->writer, $this->placeholderWriter, $parts);
52
        AbstractBaseWriter::writeLimitCondition($delete, $this->placeholderWriter, $parts);
53
        $comment = AbstractBaseWriter::writeQueryComment($delete);
54
55
        return $comment.implode(' ', $parts);
56
    }
57
}
58