Test Failed
Push — 1.0.0-dev ( 2340a7...e69566 )
by nguereza
02:13
created

setDependencyInstanceFromParamOrCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 12
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseClass::getLogger() 0 2 1
1
<?php
2
    defined('ROOT_PATH') || exit('Access denied');
3
    /**
4
     * TNH Framework
5
     *
6
     * A simple PHP framework using HMVC architecture
7
     *
8
     * This content is released under the MIT License (MIT)
9
     *
10
     * Copyright (c) 2017 TNH Framework
11
     *
12
     * Permission is hereby granted, free of charge, to any person obtaining a copy
13
     * of this software and associated documentation files (the "Software"), to deal
14
     * in the Software without restriction, including without limitation the rights
15
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
     * copies of the Software, and to permit persons to whom the Software is
17
     * furnished to do so, subject to the following conditions:
18
     *
19
     * The above copyright notice and this permission notice shall be included in all
20
     * copies or substantial portions of the Software.
21
     *
22
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
     * SOFTWARE.
29
     */
30
31
    class BaseClass {
32
        /**
33
         * The logger instance
34
         * @var object
35
         */
36
        protected $logger = null;
37
38
        /**
39
         * Class constructor
40
         */
41
        public function __construct() {
42
            //Set default Log instance to use
43
            $this->logger = & class_loader('Log', 'classes');
44
            $this->logger->setLogger('Class::' . get_class($this));
45
        }
46
47
        /**
48
         * Set this class dependency instance using class_loader function
49
         * @param string $name this class property name.
50
         * @param string $className the name of class to load using class_loader function.
51
         * @param string $classPath the path of class to load using class_loader function.
52
         *
53
         * @return object the current instance
54
         */
55
        protected function setDependency($name, $className, $classPath = 'classes') {
56
            $this->{$name} = & class_loader($className, $classPath);
57
            return $this;
58
        }
59
60
        /**
61
         * Return the Log instance
62
         * @return object
63
         */
64
        public function getLogger() {
65
            return $this->logger;
66
        }
67
68
        /**
69
         * Set the log instance
70
         * @param object $logger the log object
71
         * @return object the current instance 
72
         */
73
        public function setLogger($logger) {
74
            $this->logger = $logger;
75
            return $this;
76
        }
77
78
    }
79