AbstractExtra   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPlatform() 0 4 1
show() 0 1 ?
write() 0 1 ?
A writeIfAny() 0 11 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\Table;
11
12
use SplFileObject as File;
13
use WebinoDbDump\Db\Dump\Adapter;
14
use Zend\Db\ResultSet\ResultSet;
15
16
/**
17
 * Base class for a platform table triggers
18
 *
19
 * @author Peter Bačinský <[email protected]>
20
 */
21
abstract class AbstractExtra implements ExtraInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $tableName;
27
28
    /**
29
     * @var Adapter
30
     */
31
    protected $adapter;
32
33
    /**
34
     * @param string $tableName
35
     * @param Adapter $adapter
36
     */
37
    public function __construct($tableName, Adapter $adapter)
38
    {
39
        $this->tableName = $tableName;
40
        $this->adapter   = $adapter;
41
    }
42
43
    /**
44
     * @return \Zend\Db\Platform\PlatformInterface
45
     */
46
    protected function getPlatform()
47
    {
48
        return $this->adapter->getPlatform();
49
    }
50
51
    /**
52
     * @return ResultSet
53
     */
54
    abstract protected function show();
55
56
    /**
57
     * @param File $file
58
     * @param ResultSet $triggers
59
     * @return $this
60
     */
61
    abstract protected function write(File $file, ResultSet $triggers);
62
63
    /**
64
     * @param File $file
65
     * @return $this
66
     */
67
    public function writeIfAny(File $file)
68
    {
69
        $triggers = $this->show();
70
        if (!$triggers->count()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $triggers->count() of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
71
            // nothing to write
72
            return $this;
73
        }
74
75
        $this->write($file, $triggers);
76
        return $this;
77
    }
78
}
79