Triggers   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 5 1
B write() 0 24 2
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDbDump/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDbDump\Db\Dump\Platform\Mysql\Table;
11
12
use SplFileObject as File;
13
use WebinoDbDump\Db\Dump\Table\AbstractExtra;
14
use Zend\Db\ResultSet\ResultSet;
15
16
/**
17
 * Mysql database dump utility platform triggers
18
 *
19
 * @author Peter Bačinský <[email protected]>
20
 */
21
class Triggers extends AbstractExtra
22
{
23
    /**
24
     *
25
     */
26
    protected function show()
27
    {
28
        $name = $this->getPlatform()->quoteValue($this->tableName);
29
        return $this->adapter->executeQuery('SHOW TRIGGERS LIKE ' . $name);
30
    }
31
32
    /**
33
     *
34
     */
35
    protected function write(File $file, ResultSet $triggers)
36
    {
37
        $file->fwrite('DELIMITER ;;' . PHP_EOL . PHP_EOL);
38
39
        $platform = $this->getPlatform();
40
        foreach ($triggers as $trigger) {
41
42
            $file->fwrite(
43
                sprintf(
44
                    'CREATE TRIGGER %s %s %s ON %s FOR EACH ROW '
45
                    . PHP_EOL . ' %s;;',
46
                    $platform->quoteIdentifier($trigger['Trigger']),
47
                    $trigger['Timing'],
48
                    $trigger['Event'],
49
                    $platform->quoteIdentifier($this->tableName),
50
                    $trigger['Statement']
51
                )
52
                . PHP_EOL . PHP_EOL
53
            );
54
        }
55
56
        $file->fwrite('DELIMITER ;' . PHP_EOL . PHP_EOL);
57
        return $this;
58
    }
59
}
60