Completed
Push — travis ( 254a42 )
by Akihito
02:20
created

ExceptionAsString   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 93.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 40
ccs 14
cts 15
cp 0.9333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A summery() 0 4 1
A getPhpVariables() 0 8 2
A detail() 0 12 1
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Provide\Error;
8
9
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
10
11
class ExceptionAsString
12
{
13 3
    public function summery(\Exception $e, $log)
14
    {
15 3
        return sprintf("\n\n[%s]\n%s\n %s", get_class($e), $e->getMessage(), $log);
16
    }
17
18
    /**
19
     * @param Request $request
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $request does not match actual variable name $e
Loading history...
20
     * @param string  $lastErrorLog
0 ignored issues
show
Bug introduced by
There is no parameter named $lastErrorLog. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
Coding Style introduced by
Doc comment for parameter $lastErrorLog does not match actual variable name $request
Loading history...
21
     *
22
     * @return string
23
     */
24 3
    public function detail(\Exception $e, Request $request)
1 ignored issue
show
Coding Style introduced by
detail uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    {
26 3
        $eSummery = sprintf("[%s]\n%s\nin file %s on line %s\n\n%s",
27 3
            get_class($e),
28 3
            $e->getMessage(),
29 3
            $e->getFile(),
30 3
            $e->getLine(),
31 3
            $e->getTraceAsString()
32 3
        );
33
34 3
        return sprintf("%s\n%s\n\n%s\n%s", date(DATE_RFC2822), $request, $eSummery, $this->getPhpVariables($_SERVER));
35
    }
36
37
    /**
38
     * @param array $server
39
     *
40
     * @return string
41
     */
42 3
    private function getPhpVariables(array $server)
43
    {
44 3
        if (PHP_SAPI === 'cli') {
45 3
            return '';
46
        }
47
48
        return sprintf("\nPHP Variables\n\n\$_SERVER => %s",  print_r($server, true));
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
49
    }
50
}
51