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

Base64Test   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testUrlSafe() 0 6 1
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