Completed
Push — master ( 2fa8c8...aae24d )
by Tim
9s
created

AbstractObserver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 67
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setSubject() 0 4 1
A getSubject() 0 4 1
A getFilename() 0 4 1
A getLineNumber() 0 4 1
A getSystemLogger() 0 4 1
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
     * Return's the name of the file to import.
71
     *
72
     * @return string The filename
73
     */
74
    protected function getFilename()
75
    {
76
        return $this->getSubject()->getFilename();
77
    }
78
79
    /**
80
     * Return's the actual line number.
81
     *
82
     * @return integer The line number
83
     */
84
    protected function getLineNumber()
85
    {
86
        return $this->getSubject()->getLineNumber();
87
    }
88
89
    /**
90
     * Return's the system logger.
91
     *
92
     * @return \Psr\Log\LoggerInterface The system logger instance
93
     */
94
    protected function getSystemLogger()
95
    {
96
        return $this->getSubject()->getSystemLogger();
97
    }
98
}
99