Url   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B current() 0 12 5
1
<?php
2
3
namespace EntWeChat\Support;
4
5
/**
6
 * Class Url.
7
 */
8
class Url
9
{
10
    /**
11
     * Get current url.
12
     *
13
     * @return string
14
     */
15
    public static function current()
0 ignored issues
show
Coding Style introduced by
current 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...
16
    {
17
        if (defined('PHPUNIT_RUNNING')) {
18
            return 'http://localhost';
19
        }
20
21
        $protocol = (!empty($_SERVER['HTTPS'])
22
            && $_SERVER['HTTPS'] !== 'off'
23
            || (int) $_SERVER['SERVER_PORT'] === 443) ? 'https://' : 'http://';
24
25
        return $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
26
    }
27
}
28