Printable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 12
c 1
b 0
f 1
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 9 1
A desensitization() 0 7 3
1
<?php
2
/**
3
 * Make it printable
4
 * User: moyo
5
 * Date: 21/11/2017
6
 * Time: 3:30 PM
7
 */
8
9
namespace Carno\Net\Chips\Endpoint;
10
11
trait Printable
12
{
13
    /**
14
     * @return string
15
     */
16
    public function __toString() : string
17
    {
18
        return sprintf(
19
            '%s$%s$%s:%d$%s',
20
            $this->service ?? 'core',
21
            $this->identify ?? 'id',
22
            $this->desensitization($this->address->host()),
23
            $this->address->port(),
24
            implode(',', $this->tags)
25
        );
26
    }
27
28
    /**
29
     * hide password from dsn
30
     * @param string $host
31
     * @return string
32
     */
33
    private function desensitization(string $host) : string
34
    {
35
        if ($px1 = strpos($host, '@')) {
36
            $px2 = strpos($host, ':', ($pxs = strpos($host, '://')) ? $pxs + 3 : 0);
37
            return substr($host, 0, $px2 + 1) . '***' . substr($host, $px1);
38
        }
39
        return $host;
40
    }
41
}
42