PHPQuery::compile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc\url;
13
14
/**
15
 *	PHPQuery parses a given query string with parse_str and makes all the arguments and
16
 *	values available as key => value pairs in an array-like object.
17
 *	It also allows you to import PHP variables from another query string or an array with
18
 *	key => value pairs.
19
 *	When cast to string PHPQuery generates a valid query string compatible with PHP.
20
 *
21
 *	Usage:
22
 *		$query = new \arc\url\PHPQuery( 'a[0]=1&a[1]=2&test=foo');
23
 *		$query['a'][] = 3;
24
 *		$query['bar']= 'test';
25
 *		unset( $queyr['foo'] );
26
 *		echo $query; // => 'a[0]=1&a[1]=2&a[2]=3&bar=test';
27
 */
28
class PHPQuery extends Query
29
{
30
    /**
31
     * Create a query string from the given values
32
     * @param array $values
33
     * @return string
34
     */
35 38
    protected function compile($values)
36
    {
37 38
        return http_build_query( $values, '', '&', PHP_QUERY_RFC3986 );
38
    }
39
40
    /**
41
     * Parse a query string and return an array with values.
42
     * @param string $queryString
43
     * @return mixed
44
     */
45 42
    protected function parseQueryString($queryString)
46
    {
47 42
        parse_str( (string) $queryString, $values );
48
49 42
        return $values;
50
    }
51
}
52