Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 17
SymfonyCaster
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 17
 castRequest
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 8
 castHttpClient
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 4
 castHttpClientResponse
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\VarDumper\Caster;
13
14use Symfony\Component\HttpFoundation\Request;
15use Symfony\Component\VarDumper\Cloner\Stub;
16
17/**
18 * @final
19 */
20class SymfonyCaster
21{
22    private static $requestGetters = [
23        'pathInfo' => 'getPathInfo',
24        'requestUri' => 'getRequestUri',
25        'baseUrl' => 'getBaseUrl',
26        'basePath' => 'getBasePath',
27        'method' => 'getMethod',
28        'format' => 'getRequestFormat',
29    ];
30
31    public static function castRequest(Request $request, array $a, Stub $stub, bool $isNested)
32    {
33        $clone = null;
34
35        foreach (self::$requestGetters as $prop => $getter) {
36            $key = Caster::PREFIX_PROTECTED.$prop;
37            if (\array_key_exists($key, $a) && null === $a[$key]) {
38                if (null === $clone) {
39                    $clone = clone $request;
40                }
41                $a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
42            }
43        }
44
45        return $a;
46    }
47
48    public static function castHttpClient($client, array $a, Stub $stub, bool $isNested)
49    {
50        $multiKey = sprintf("\0%s\0multi", \get_class($client));
51        if (isset($a[$multiKey])) {
52            $a[$multiKey] = new CutStub($a[$multiKey]);
53        }
54
55        return $a;
56    }
57
58    public static function castHttpClientResponse($response, array $a, Stub $stub, bool $isNested)
59    {
60        $stub->cut += \count($a);
61        $a = [];
62
63        foreach ($response->getInfo() as $k => $v) {
64            $a[Caster::PREFIX_VIRTUAL.$k] = $v;
65        }
66
67        return $a;
68    }
69}