Completed
Pull Request — master (#267)
by
unknown
10:23
created

UtilTest.php ➔ time()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Qiniu\Rtc
4
{
5
    function time()
0 ignored issues
show
Coding Style introduced by
time 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...
6
    {
7
        return isset($_SERVER['override_qiniu_auth_time'])
8
            ? 1234567890
9
            : \time();
10
    }
11
}
12
13
namespace Rtc\Tests
14
{
15
    use \Qiniu\Rtc\Utils;
16
17
    class Base64Test extends \PHPUnit_Framework_TestCase
18
    {
19
        public function testUrlSafe()
20
        {
21
            $a = '你好';
22
            $b = Utils::base64UrlEncode($a);
23
            $this->assertEquals($a, Utils::base64UrlDecode($b));
24
        }
25
    }
26
}
27