Completed
Push — master ( 6c8968...c3386c )
by Tim
20s
created

AbstractObserver::setSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Observers\AbstractObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Observers;
22
23
/**
24
 * An abstract observer implementation.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
abstract class AbstractObserver implements ObserverInterface
33
{
34
35
    /**
36
     * Initializes the observer with the passed subject instance.
37
     *
38
     * @param object|null $subject The observer's subject instance
39
     */
40
    public function __construct($subject = null)
41
    {
42
        if ($subject != null) {
43
            $this->setSubject($subject);
44
        }
45
    }
46
47
    /**
48
     * Set's the obeserver's subject instance to initialize the observer with.
49
     *
50
     * @param object $subject The observer's subject
51
     *
52
     * @return void
53
     */
54
    public function setSubject($subject)
55
    {
56
        $this->subject = $subject;
0 ignored issues
show
Bug introduced by
The property subject does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
57
    }
58
59
    /**
60
     * Return's the observer's subject instance.
61
     *
62
     * @return object The observer's subject instance
63
     */
64
    protected function getSubject()
65
    {
66
        return $this->subject;
67
    }
68
69
    /**
70
     * Queries whether or not debug mode is enabled or not, default is TRUE.
71
     *
72
     * @return boolean TRUE if debug mode is enabled, else FALSE
73
     */
74
    protected function isDebugMode()
75
    {
76
        return $this->getSubject()->isDebugMode();
77
    }
78
79
    /**
80
     * Stop's observer execution on the actual row.
81
     *
82
     * @return void
83
     */
84
    protected function skipRow()
85
    {
86
        $this->getSubject()->skipRow();
87
    }
88
89
    /**
90
     * Return's the name of the file to import.
91
     *
92
     * @return string The filename
93
     */
94
    protected function getFilename()
95
    {
96
        return $this->getSubject()->getFilename();
97
    }
98
99
    /**
100
     * Return's the actual line number.
101
     *
102
     * @return integer The line number
103
     */
104
    protected function getLineNumber()
105
    {
106
        return $this->getSubject()->getLineNumber();
107
    }
108
109
    /**
110
     * Return's the system logger.
111
     *
112
     * @return \Psr\Log\LoggerInterface The system logger instance
113
     */
114
    protected function getSystemLogger()
115
    {
116
        return $this->getSubject()->getSystemLogger();
117
    }
118
}
119