Completed
Push — 2.0 ( 6e1974...7f0480 )
by Marco
13:21
created

TaskErrorHandlerTrait::restoreErrorHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Comodojo\Extender\Traits;
2
3
use \Comodojo\Foundation\Utils\ErrorLevelConverter;
4
5
/**
6
 * @package     Comodojo Extender
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @license     MIT
9
 *
10
 * LICENSE:
11
 *
12
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
 * THE SOFTWARE.
19
 */
20
21
trait TaskErrorHandlerTrait {
22
23
    public function installErrorHandler() {
24
25
        set_error_handler([$this, 'customErrorHandler']);
26
27
    }
28
29
    public function restoreErrorHandler() {
30
31
        restore_error_handler();
32
33
    }
34
35
    public function customErrorHandler($errno, $errstr, $errfile, $errline) {
36
37
        $error = ErrorLevelConverter::convert($errno);
38
39
        $this->getLogger()->error("Unhandled $error ($errno): $errstr [in $errfile line $errline]");
0 ignored issues
show
Bug introduced by
It seems like getLogger() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
41
        return true;
42
43
    }
44
45
}
46