Conditions | 21 |
Paths | 3463 |
Total Lines | 113 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | function parseDSN($dsn) |
||
42 | { |
||
43 | if (is_array($dsn)) { |
||
44 | return $dsn; |
||
45 | } |
||
46 | |||
47 | $parsed = [ |
||
48 | 'phptype' => false, |
||
49 | 'dbsyntax' => false, |
||
50 | 'username' => false, |
||
51 | 'password' => false, |
||
52 | 'protocol' => false, |
||
53 | 'hostspec' => false, |
||
54 | 'port' => false, |
||
55 | 'socket' => false, |
||
56 | 'database' => false |
||
57 | ]; |
||
58 | |||
59 | // Find phptype and dbsyntax |
||
60 | if (($pos = strpos($dsn, '://')) !== false) { |
||
61 | $str = substr($dsn, 0, $pos); |
||
62 | $dsn = substr($dsn, $pos + 3); |
||
63 | } else { |
||
64 | $str = $dsn; |
||
65 | $dsn = null; |
||
66 | } |
||
67 | |||
68 | // Get phptype and dbsyntax |
||
69 | // $str => phptype(dbsyntax) |
||
70 | if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) { |
||
71 | $parsed['phptype'] = $arr[1]; |
||
72 | $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2]; |
||
73 | } else { |
||
74 | $parsed['phptype'] = $str; |
||
75 | $parsed['dbsyntax'] = $str; |
||
76 | } |
||
77 | |||
78 | if (empty($dsn)) { |
||
79 | return $parsed; |
||
80 | } |
||
81 | |||
82 | // Get (if found): username and password |
||
83 | // $dsn => username:password@protocol+hostspec/database |
||
84 | if (($at = strrpos($dsn, '@')) !== false) { |
||
85 | $str = substr($dsn, 0, $at); |
||
86 | $dsn = substr($dsn, $at + 1); |
||
87 | if (($pos = strpos($str, ':')) !== false) { |
||
88 | $parsed['username'] = rawurldecode(substr($str, 0, $pos)); |
||
89 | $parsed['password'] = rawurldecode(substr($str, $pos + 1)); |
||
90 | } else { |
||
91 | $parsed['username'] = rawurldecode($str); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | // Find protocol and hostspec |
||
96 | |||
97 | // $dsn => proto(proto_opts)/database |
||
98 | if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) { |
||
99 | $proto = $match[1]; |
||
100 | $proto_opts = (!empty($match[2])) ? $match[2] : false; |
||
101 | $dsn = $match[3]; |
||
102 | |||
103 | // $dsn => protocol+hostspec/database (old format) |
||
104 | } else { |
||
105 | if (strpos($dsn, '+') !== false) { |
||
106 | list($proto, $dsn) = explode('+', $dsn, 2); |
||
107 | } |
||
108 | if (strpos($dsn, '/') !== false) { |
||
109 | list($proto_opts, $dsn) = explode('/', $dsn, 2); |
||
110 | } else { |
||
111 | $proto_opts = $dsn; |
||
112 | $dsn = null; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | // process the different protocol options |
||
117 | $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp'; |
||
118 | $proto_opts = rawurldecode($proto_opts); |
||
119 | if ($parsed['protocol'] == 'tcp') { |
||
120 | if (strpos($proto_opts, ':') !== false) { |
||
121 | list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts); |
||
122 | } else { |
||
123 | $parsed['hostspec'] = $proto_opts; |
||
124 | } |
||
125 | } elseif ($parsed['protocol'] == 'unix') { |
||
126 | $parsed['socket'] = $proto_opts; |
||
127 | } |
||
128 | |||
129 | // Get dabase if any |
||
130 | // $dsn => database |
||
131 | if (!empty($dsn)) { |
||
132 | // /database |
||
133 | if (($pos = strpos($dsn, '?')) === false) { |
||
134 | $parsed['database'] = $dsn; |
||
135 | // /database?param1=value1¶m2=value2 |
||
136 | } else { |
||
137 | $parsed['database'] = substr($dsn, 0, $pos); |
||
138 | $dsn = substr($dsn, $pos + 1); |
||
139 | if (strpos($dsn, '&') !== false) { |
||
140 | $opts = explode('&', $dsn); |
||
141 | } else { // database?param1=value1 |
||
142 | $opts = [$dsn]; |
||
143 | } |
||
144 | foreach ($opts as $opt) { |
||
145 | list($key, $value) = explode('=', $opt); |
||
146 | if (!isset($parsed[$key])) { // don't allow params overwrite |
||
147 | $parsed[$key] = rawurldecode($value); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | return $parsed; |
||
154 | } |
||
189 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths