Completed
Pull Request — master (#540)
by Eric
01:26
created

PrettyPageHandler::getBlacklistForSuperGlobal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace Whoops\Handler;
8
9
use InvalidArgumentException;
10
use RuntimeException;
11
use Symfony\Component\VarDumper\Cloner\AbstractCloner;
12
use Symfony\Component\VarDumper\Cloner\VarCloner;
13
use UnexpectedValueException;
14
use Whoops\Exception\Formatter;
15
use Whoops\Util\Misc;
16
use Whoops\Util\TemplateHelper;
17
18
class PrettyPageHandler extends Handler
19
{
20
    /**
21
     * Search paths to be scanned for resources, in the reverse
22
     * order they're declared.
23
     *
24
     * @var array
25
     */
26
    private $searchPaths = [];
27
28
    /**
29
     * Fast lookup cache for known resource locations.
30
     *
31
     * @var array
32
     */
33
    private $resourceCache = [];
34
35
    /**
36
     * The name of the custom css file.
37
     *
38
     * @var string
39
     */
40
    private $customCss = null;
41
42
    /**
43
     * @var array[]
44
     */
45
    private $extraTables = [];
46
47
    /**
48
     * @var bool
49
     */
50
    private $handleUnconditionally = false;
51
52
    /**
53
     * @var string
54
     */
55
    private $pageTitle = "Whoops! There was an error.";
56
57
    /**
58
     * @var array[]
59
     */
60
    private $applicationPaths;
61
62
    /**
63
     * @var array[]
64
     */
65
    private $blacklist = [
66
        '_GET' => [],
67
        '_POST' => [],
68
        '_FILES' => [],
69
        '_COOKIE' => [],
70
        '_SESSION' => [],
71
        '_SERVER' => [],
72
        '_ENV' => [],
73
        '*' => [],
74
    ];
75
76
    /**
77
     * A string identifier for a known IDE/text editor, or a closure
78
     * that resolves a string that can be used to open a given file
79
     * in an editor. If the string contains the special substrings
80
     * %file or %line, they will be replaced with the correct data.
81
     *
82
     * @example
83
     *  "txmt://open?url=%file&line=%line"
84
     * @var mixed $editor
85
     */
86
    protected $editor;
87
88
    /**
89
     * A list of known editor strings
90
     * @var array
91
     */
92
    protected $editors = [
93
        "sublime"  => "subl://open?url=file://%file&line=%line",
94
        "textmate" => "txmt://open?url=file://%file&line=%line",
95
        "emacs"    => "emacs://open?url=file://%file&line=%line",
96
        "macvim"   => "mvim://open/?url=file://%file&line=%line",
97
        "phpstorm" => "phpstorm://open?file=%file&line=%line",
98
        "idea"     => "idea://open?file=%file&line=%line",
99
        "vscode"   => "vscode://file/%file:%line",
100
    ];
101
102
    /**
103
     * @var TemplateHelper
104
     */
105
    private $templateHelper;
106
107
    /**
108
     * Constructor.
109
     */
110 2
    public function __construct()
111
    {
112 2
        if (ini_get('xdebug.file_link_format') || extension_loaded('xdebug')) {
113
            // Register editor using xdebug's file_link_format option.
114
            $this->editors['xdebug'] = function ($file, $line) {
115 1
                return str_replace(['%f', '%l'], [$file, $line], ini_get('xdebug.file_link_format'));
116
            };
117 2
        }
118
119
        // Add the default, local resource search path:
120 2
        $this->searchPaths[] = __DIR__ . "/../Resources";
121
122
        // blacklist php provided auth based values
123 2
        $this->blacklist('_SERVER', 'PHP_AUTH_PW');
124
125 2
        $this->templateHelper = new TemplateHelper();
126
127 2
        if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
128 2
            $cloner = new VarCloner();
129
            // Only dump object internals if a custom caster exists.
130
            $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
0 ignored issues
show
Unused Code introduced by
The parameter $isNested is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $filter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
                $class = $stub->class;
132
                $classes = [$class => $class] + class_parents($class) + class_implements($class);
133
134
                foreach ($classes as $class) {
135
                    if (isset(AbstractCloner::$defaultCasters[$class])) {
136
                        return $a;
137
                    }
138
                }
139
140
                // Remove all internals
141
                return [];
142 2
            }]);
143 2
            $this->templateHelper->setCloner($cloner);
144 2
        }
145 2
    }
146
147
    /**
148
     * @return int|null
149
     */
150 1
    public function handle()
151
    {
152 1
        if (!$this->handleUnconditionally()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->handleUnconditionally() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
153
            // Check conditions for outputting HTML:
154
            // @todo: Make this more robust
155 1
            if (PHP_SAPI === 'cli') {
156
                // Help users who have been relying on an internal test value
157
                // fix their code to the proper method
158 1
                if (isset($_ENV['whoops-test'])) {
159
                    throw new \Exception(
160
                        'Use handleUnconditionally instead of whoops-test'
161
                        .' environment variable'
162
                    );
163
                }
164
165 1
                return Handler::DONE;
166
            }
167
        }
168
169
        $templateFile = $this->getResource("views/layout.html.php");
170
        $cssFile      = $this->getResource("css/whoops.base.css");
171
        $zeptoFile    = $this->getResource("js/zepto.min.js");
172
        $clipboard    = $this->getResource("js/clipboard.min.js");
173
        $jsFile       = $this->getResource("js/whoops.base.js");
174
175
        if ($this->customCss) {
176
            $customCssFile = $this->getResource($this->customCss);
177
        }
178
179
        $inspector = $this->getInspector();
180
        $frames = $this->getExceptionFrames();
181
        $code = $this->getExceptionCode();
182
183
        // List of variables that will be passed to the layout template.
184
        $vars = [
185
            "page_title" => $this->getPageTitle(),
186
187
            // @todo: Asset compiler
188
            "stylesheet" => file_get_contents($cssFile),
189
            "zepto"      => file_get_contents($zeptoFile),
190
            "clipboard"  => file_get_contents($clipboard),
191
            "javascript" => file_get_contents($jsFile),
192
193
            // Template paths:
194
            "header"                     => $this->getResource("views/header.html.php"),
195
            "header_outer"               => $this->getResource("views/header_outer.html.php"),
196
            "frame_list"                 => $this->getResource("views/frame_list.html.php"),
197
            "frames_description"         => $this->getResource("views/frames_description.html.php"),
198
            "frames_container"           => $this->getResource("views/frames_container.html.php"),
199
            "panel_details"              => $this->getResource("views/panel_details.html.php"),
200
            "panel_details_outer"        => $this->getResource("views/panel_details_outer.html.php"),
201
            "panel_left"                 => $this->getResource("views/panel_left.html.php"),
202
            "panel_left_outer"           => $this->getResource("views/panel_left_outer.html.php"),
203
            "frame_code"                 => $this->getResource("views/frame_code.html.php"),
204
            "env_details"                => $this->getResource("views/env_details.html.php"),
205
206
            "title"          => $this->getPageTitle(),
207
            "name"           => explode("\\", $inspector->getExceptionName()),
208
            "message"        => $inspector->getExceptionMessage(),
209
            "docref_url"     => $inspector->getExceptionDocrefUrl(),
210
            "code"           => $code,
211
            "plain_exception" => Formatter::formatExceptionPlain($inspector),
212
            "frames"         => $frames,
213
            "has_frames"     => !!count($frames),
214
            "handler"        => $this,
215
            "handlers"       => $this->getRun()->getHandlers(),
216
217
            "active_frames_tab" => count($frames) && $frames->offsetGet(0)->isApplication() ?  'application' : 'all',
0 ignored issues
show
Bug introduced by
The method isApplication cannot be called on $frames->offsetGet(0) (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
218
            "has_frames_tabs"   => $this->getApplicationPaths(),
219
220
            "tables"      => [
221
                "GET Data"              => $this->masked($_GET, '_GET'),
222
                "POST Data"             => $this->masked($_POST, '_POST'),
223
                "Files"                 => isset($_FILES) ? $this->masked($_FILES, '_FILES') : [],
224
                "Cookies"               => $this->masked($_COOKIE, '_COOKIE'),
225
                "Session"               => isset($_SESSION) ? $this->masked($_SESSION, '_SESSION') :  [],
226
                "Server/Request Data"   => $this->masked($_SERVER, '_SERVER'),
227
                "Environment Variables" => $this->masked($_ENV, '_ENV'),
228
            ],
229
        ];
230
231
        if (isset($customCssFile)) {
232
            $vars["stylesheet"] .= file_get_contents($customCssFile);
233
        }
234
235
        // Add extra entries list of data tables:
236
        // @todo: Consolidate addDataTable and addDataTableCallback
237
        $extraTables = array_map(function ($table) use ($inspector) {
238
            return $table instanceof \Closure ? $table($inspector) : $table;
239
        }, $this->getDataTables());
240
        $vars["tables"] = array_merge($extraTables, $vars["tables"]);
241
242
        $plainTextHandler = new PlainTextHandler();
243
        $plainTextHandler->setException($this->getException());
244
        $plainTextHandler->setInspector($this->getInspector());
245
        $vars["preface"] = "<!--\n\n\n" .  $this->templateHelper->escape($plainTextHandler->generateResponse()) . "\n\n\n\n\n\n\n\n\n\n\n-->";
246
247
        $this->templateHelper->setVariables($vars);
248
        $this->templateHelper->render($templateFile);
249
250
        return Handler::QUIT;
251
    }
252
253
    /**
254
     * Get the stack trace frames of the exception that is currently being handled.
255
     *
256
     * @return \Whoops\Exception\FrameCollection;
0 ignored issues
show
Documentation introduced by
The doc-type \Whoops\Exception\FrameCollection; could not be parsed: Expected "|" or "end of type", but got ";" at position 33. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
257
     */
258
    protected function getExceptionFrames()
259
    {
260
        $frames = $this->getInspector()->getFrames();
261
262
        if ($this->getApplicationPaths()) {
263
            foreach ($frames as $frame) {
264
                foreach ($this->getApplicationPaths() as $path) {
265
                    if (strpos($frame->getFile(), $path) === 0) {
266
                        $frame->setApplication(true);
267
                        break;
268
                    }
269
                }
270
            }
271
        }
272
273
        return $frames;
274
    }
275
276
    /**
277
     * Get the code of the exception that is currently being handled.
278
     *
279
     * @return string
280
     */
281
    protected function getExceptionCode()
282
    {
283
        $exception = $this->getException();
284
285
        $code = $exception->getCode();
286
        if ($exception instanceof \ErrorException) {
287
            // ErrorExceptions wrap the php-error types within the 'severity' property
288
            $code = Misc::translateErrorCode($exception->getSeverity());
289
        }
290
291
        return (string) $code;
292
    }
293
294
    /**
295
     * @return string
296
     */
297
    public function contentType()
298
    {
299
        return 'text/html';
300
    }
301
302
    /**
303
     * Adds an entry to the list of tables displayed in the template.
304
     * The expected data is a simple associative array. Any nested arrays
305
     * will be flattened with print_r
306
     * @param string $label
307
     * @param array  $data
308
     */
309 1
    public function addDataTable($label, array $data)
310
    {
311 1
        $this->extraTables[$label] = $data;
312 1
    }
313
314
    /**
315
     * Lazily adds an entry to the list of tables displayed in the table.
316
     * The supplied callback argument will be called when the error is rendered,
317
     * it should produce a simple associative array. Any nested arrays will
318
     * be flattened with print_r.
319
     *
320
     * @throws InvalidArgumentException If $callback is not callable
321
     * @param  string                   $label
322
     * @param  callable                 $callback Callable returning an associative array
323
     */
324 1
    public function addDataTableCallback($label, /* callable */ $callback)
325
    {
326 1
        if (!is_callable($callback)) {
327
            throw new InvalidArgumentException('Expecting callback argument to be callable');
328
        }
329
330 1
        $this->extraTables[$label] = function (\Whoops\Exception\Inspector $inspector = null) use ($callback) {
331
            try {
332 1
                $result = call_user_func($callback, $inspector);
333
334
                // Only return the result if it can be iterated over by foreach().
335 1
                return is_array($result) || $result instanceof \Traversable ? $result : [];
336
            } catch (\Exception $e) {
337
                // Don't allow failure to break the rendering of the original exception.
338
                return [];
339
            }
340
        };
341 1
    }
342
343
    /**
344
     * Returns all the extra data tables registered with this handler.
345
     * Optionally accepts a 'label' parameter, to only return the data
346
     * table under that label.
347
     * @param  string|null      $label
348
     * @return array[]|callable
349
     */
350 2
    public function getDataTables($label = null)
351
    {
352 2
        if ($label !== null) {
353 2
            return isset($this->extraTables[$label]) ?
354 2
                   $this->extraTables[$label] : [];
355
        }
356
357 2
        return $this->extraTables;
358
    }
359
360
    /**
361
     * Allows to disable all attempts to dynamically decide whether to
362
     * handle or return prematurely.
363
     * Set this to ensure that the handler will perform no matter what.
364
     * @param  bool|null $value
365
     * @return bool|null
366
     */
367 2
    public function handleUnconditionally($value = null)
368
    {
369 2
        if (func_num_args() == 0) {
370 2
            return $this->handleUnconditionally;
371
        }
372
373
        $this->handleUnconditionally = (bool) $value;
374
    }
375
376
    /**
377
     * Adds an editor resolver, identified by a string
378
     * name, and that may be a string path, or a callable
379
     * resolver. If the callable returns a string, it will
380
     * be set as the file reference's href attribute.
381
     *
382
     * @example
383
     *  $run->addEditor('macvim', "mvim://open?url=file://%file&line=%line")
384
     * @example
385
     *   $run->addEditor('remove-it', function($file, $line) {
386
     *       unlink($file);
387
     *       return "http://stackoverflow.com";
388
     *   });
389
     * @param string $identifier
390
     * @param string $resolver
391
     */
392 1
    public function addEditor($identifier, $resolver)
393
    {
394 1
        $this->editors[$identifier] = $resolver;
395 1
    }
396
397
    /**
398
     * Set the editor to use to open referenced files, by a string
399
     * identifier, or a callable that will be executed for every
400
     * file reference, with a $file and $line argument, and should
401
     * return a string.
402
     *
403
     * @example
404
     *   $run->setEditor(function($file, $line) { return "file:///{$file}"; });
405
     * @example
406
     *   $run->setEditor('sublime');
407
     *
408
     * @throws InvalidArgumentException If invalid argument identifier provided
409
     * @param  string|callable          $editor
410
     */
411 4
    public function setEditor($editor)
412
    {
413 4
        if (!is_callable($editor) && !isset($this->editors[$editor])) {
414
            throw new InvalidArgumentException(
415
                "Unknown editor identifier: $editor. Known editors:" .
416
                implode(",", array_keys($this->editors))
417
            );
418
        }
419
420 4
        $this->editor = $editor;
421 4
    }
422
423
    /**
424
     * Given a string file path, and an integer file line,
425
     * executes the editor resolver and returns, if available,
426
     * a string that may be used as the href property for that
427
     * file reference.
428
     *
429
     * @throws InvalidArgumentException If editor resolver does not return a string
430
     * @param  string                   $filePath
431
     * @param  int                      $line
432
     * @return string|bool
433
     */
434 4
    public function getEditorHref($filePath, $line)
435
    {
436 4
        $editor = $this->getEditor($filePath, $line);
437
438 4
        if (empty($editor)) {
439
            return false;
440
        }
441
442
        // Check that the editor is a string, and replace the
443
        // %line and %file placeholders:
444 4
        if (!isset($editor['url']) || !is_string($editor['url'])) {
445
            throw new UnexpectedValueException(
446
                __METHOD__ . " should always resolve to a string or a valid editor array; got something else instead."
447
            );
448
        }
449
450 4
        $editor['url'] = str_replace("%line", rawurlencode($line), $editor['url']);
451 4
        $editor['url'] = str_replace("%file", rawurlencode($filePath), $editor['url']);
452
453 4
        return $editor['url'];
454
    }
455
456
    /**
457
     * Given a boolean if the editor link should
458
     * act as an Ajax request. The editor must be a
459
     * valid callable function/closure
460
     *
461
     * @throws UnexpectedValueException  If editor resolver does not return a boolean
462
     * @param  string                   $filePath
463
     * @param  int                      $line
464
     * @return bool
465
     */
466 1
    public function getEditorAjax($filePath, $line)
467
    {
468 1
        $editor = $this->getEditor($filePath, $line);
469
470
        // Check that the ajax is a bool
471 1
        if (!isset($editor['ajax']) || !is_bool($editor['ajax'])) {
472
            throw new UnexpectedValueException(
473
                __METHOD__ . " should always resolve to a bool; got something else instead."
474
            );
475
        }
476 1
        return $editor['ajax'];
477
    }
478
479
    /**
480
     * Given a boolean if the editor link should
481
     * act as an Ajax request. The editor must be a
482
     * valid callable function/closure
483
     *
484
     * @param  string $filePath
485
     * @param  int    $line
486
     * @return array
487
     */
488 1
    protected function getEditor($filePath, $line)
489
    {
490 1
        if (!$this->editor || (!is_string($this->editor) && !is_callable($this->editor))) {
491
            return [];
492
        }
493
494 1
        if (is_string($this->editor) && isset($this->editors[$this->editor]) && !is_callable($this->editors[$this->editor])) {
495
            return [
496
                'ajax' => false,
497
                'url' => $this->editors[$this->editor],
498
            ];
499
        }
500
501 1
        if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) {
502 1
            if (is_callable($this->editor)) {
503
                $callback = call_user_func($this->editor, $filePath, $line);
504
            } else {
505 1
                $callback = call_user_func($this->editors[$this->editor], $filePath, $line);
506
            }
507
508 1
            if (is_string($callback)) {
509
                return [
510 1
                    'ajax' => false,
511 1
                    'url' => $callback,
512 1
                ];
513
            }
514
515
            return [
516
                'ajax' => isset($callback['ajax']) ? $callback['ajax'] : false,
517
                'url' => isset($callback['url']) ? $callback['url'] : $callback,
518
            ];
519
        }
520
521
        return [];
522
    }
523
524
    /**
525
     * @param  string $title
526
     * @return void
527
     */
528 1
    public function setPageTitle($title)
529
    {
530 1
        $this->pageTitle = (string) $title;
531 1
    }
532
533
    /**
534
     * @return string
535
     */
536 1
    public function getPageTitle()
537
    {
538 1
        return $this->pageTitle;
539
    }
540
541
    /**
542
     * Adds a path to the list of paths to be searched for
543
     * resources.
544
     *
545
     * @throws InvalidArgumentException If $path is not a valid directory
546
     *
547
     * @param  string $path
548
     * @return void
549
     */
550 2
    public function addResourcePath($path)
551
    {
552 2
        if (!is_dir($path)) {
553 1
            throw new InvalidArgumentException(
554 1
                "'$path' is not a valid directory"
555 1
            );
556
        }
557
558 1
        array_unshift($this->searchPaths, $path);
559 1
    }
560
561
    /**
562
     * Adds a custom css file to be loaded.
563
     *
564
     * @param  string $name
565
     * @return void
566
     */
567
    public function addCustomCss($name)
568
    {
569
        $this->customCss = $name;
570
    }
571
572
    /**
573
     * @return array
574
     */
575 1
    public function getResourcePaths()
576
    {
577 1
        return $this->searchPaths;
578
    }
579
580
    /**
581
     * Finds a resource, by its relative path, in all available search paths.
582
     * The search is performed starting at the last search path, and all the
583
     * way back to the first, enabling a cascading-type system of overrides
584
     * for all resources.
585
     *
586
     * @throws RuntimeException If resource cannot be found in any of the available paths
587
     *
588
     * @param  string $resource
589
     * @return string
590
     */
591
    protected function getResource($resource)
592
    {
593
        // If the resource was found before, we can speed things up
594
        // by caching its absolute, resolved path:
595
        if (isset($this->resourceCache[$resource])) {
596
            return $this->resourceCache[$resource];
597
        }
598
599
        // Search through available search paths, until we find the
600
        // resource we're after:
601
        foreach ($this->searchPaths as $path) {
602
            $fullPath = $path . "/$resource";
603
604
            if (is_file($fullPath)) {
605
                // Cache the result:
606
                $this->resourceCache[$resource] = $fullPath;
607
                return $fullPath;
608
            }
609
        }
610
611
        // If we got this far, nothing was found.
612
        throw new RuntimeException(
613
            "Could not find resource '$resource' in any resource paths."
614
            . "(searched: " . join(", ", $this->searchPaths). ")"
615
        );
616
    }
617
618
    /**
619
     * @deprecated
620
     *
621
     * @return string
622
     */
623
    public function getResourcesPath()
624
    {
625
        $allPaths = $this->getResourcePaths();
626
627
        // Compat: return only the first path added
628
        return end($allPaths) ?: null;
629
    }
630
631
    /**
632
     * @deprecated
633
     *
634
     * @param  string $resourcesPath
635
     * @return void
636
     */
637
    public function setResourcesPath($resourcesPath)
638
    {
639
        $this->addResourcePath($resourcesPath);
640
    }
641
642
    /**
643
     * Return the application paths.
644
     *
645
     * @return array
646
     */
647
    public function getApplicationPaths()
648
    {
649
        return $this->applicationPaths;
650
    }
651
652
    /**
653
     * Set the application paths.
654
     *
655
     * @param array $applicationPaths
656
     */
657
    public function setApplicationPaths($applicationPaths)
658
    {
659
        $this->applicationPaths = $applicationPaths;
660
    }
661
662
    /**
663
     * Set the application root path.
664
     *
665
     * @param string $applicationRootPath
666
     */
667
    public function setApplicationRootPath($applicationRootPath)
668
    {
669
        $this->templateHelper->setApplicationRootPath($applicationRootPath);
670
    }
671
672
    /**
673
     * blacklist a sensitive value within one of the superglobal arrays.
674
     *
675
     * @param $superGlobalName string the name of the superglobal array, e.g. '_GET'
676
     * @param $key string the key within the superglobal
677
     */
678 2
    public function blacklist($superGlobalName, $key)
679
    {
680 2
        $this->blacklist[$superGlobalName][] = $key;
681 2
    }
682
683
    /**
684
     * Get the blacklisted values for the given superGlobal
685
     *
686
     * @param $superGlobalName string the name of the superglobal array, e.g. '_GET'
687
     * @return array
688
     */
689 1
    public function getBlacklistForSuperGlobal($superGlobalName)
690
    {
691 1
        return array_unique(array_merge(
692 1
            $this->blacklist['*'],
693 1
            $this->blacklist[$superGlobalName]
694 1
        ));
695
    }
696
697
    /**
698
     * Checks all values within the given superGlobal array.
699
     * Blacklisted values will be replaced by a equal length string cointaining only '*' characters.
700
     *
701
     * We intentionally dont rely on $GLOBALS as it depends on 'auto_globals_jit' php.ini setting.
702
     *
703
     * @param $superGlobal array One of the superglobal arrays
704
     * @param $superGlobalName string the name of the superglobal array, e.g. '_GET'
705
     * @return array $values without sensitive data
706
     */
707
    private function masked(array $superGlobal, $superGlobalName)
708
    {
709
        $blacklisted = $this->getBlacklistForSuperGlobal($superGlobalName);
710
711
        $values = $superGlobal;
712
        foreach ($blacklisted as $key) {
713
            if (isset($superGlobal[$key])) {
714
                $values[$key] = str_repeat('*', strlen($superGlobal[$key]));
715
            }
716
        }
717
        return $values;
718
    }
719
}
720