Error   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 4 1
A __toString() 0 4 1
1
<?php namespace Tarsana\Functional;
2
3
/**
4
 * This class represents an error. It extends the `Exception` class and thus can be thrown.
5
 * @class
6
 */
7
class Error extends \Exception {
8
    /**
9
     * Creates a new Error.
10
     * ```php
11
     * $err = Error::of('Ooops !'); // [Error: Ooops !]
12
     * $err2 = Error::of('Second error', $err); // [Error: Second error -> Ooops !]
13
     * ```
14
     *
15
     * @signature String -> Error
16
     * @signature (String, Error) -> Error
17
     * @param  string     $message
18
     * @param  Error|null $error
19
     * @return Error
20
     */
21
    public static function of ($message, $code = 0, Error $error = null)
22
    {
23
        return new Error($message, $code, $error);
24
    }
25
26
    /**
27
     * Returns a string representation of the error.
28
     *
29
     * @return string
30
     */
31
    public function __toString()
32
    {
33
        return "[Error: {$this->getMessage()}]";
34
    }
35
}
36