Conditions | 9 |
Paths | 12 |
Total Lines | 66 |
Code Lines | 28 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
69 | public static function connect( |
||
70 | #[SensitiveParameter] |
||
71 | string $driver, |
||
72 | #[SensitiveParameter] |
||
73 | string $host, |
||
74 | #[SensitiveParameter] |
||
75 | string $port, |
||
76 | #[SensitiveParameter] |
||
77 | string $database, |
||
78 | #[SensitiveParameter] |
||
79 | string $username, |
||
80 | #[SensitiveParameter] |
||
81 | string $password, |
||
82 | #[SensitiveParameter] |
||
83 | string $prefix, |
||
84 | #[SensitiveParameter] |
||
85 | string $key, |
||
86 | #[SensitiveParameter] |
||
87 | string $certificate, |
||
88 | #[SensitiveParameter] |
||
89 | string $ca, |
||
90 | #[SensitiveParameter] |
||
91 | bool $verify_certificate, |
||
92 | ): void { |
||
93 | $options = [ |
||
94 | // Some drivers do this and some don't. Make them consistent. |
||
95 | PDO::ATTR_STRINGIFY_FETCHES => true, |
||
96 | ]; |
||
97 | |||
98 | // MySQL/MariaDB support encrypted connections |
||
99 | if ($driver === self::MYSQL && $key !== '' && $certificate !== '' && $ca !== '') { |
||
100 | $options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $verify_certificate; |
||
101 | $options[PDO::MYSQL_ATTR_SSL_KEY] = Webtrees::ROOT_DIR . 'data/' . $key; |
||
102 | $options[PDO::MYSQL_ATTR_SSL_CERT] = Webtrees::ROOT_DIR . 'data/' . $certificate; |
||
103 | $options[PDO::MYSQL_ATTR_SSL_CA] = Webtrees::ROOT_DIR . 'data/' . $ca; |
||
104 | } |
||
105 | |||
106 | if ($driver === self::SQLITE && $database !== ':memory:') { |
||
107 | $database = Webtrees::ROOT_DIR . 'data/' . $database . '.sqlite'; |
||
108 | } |
||
109 | |||
110 | $capsule = new self(); |
||
111 | $capsule->addConnection([ |
||
112 | 'driver' => $driver, |
||
113 | 'host' => $host, |
||
114 | 'port' => $port, |
||
115 | 'database' => $database, |
||
116 | 'username' => $username, |
||
117 | 'password' => $password, |
||
118 | 'prefix' => $prefix, |
||
119 | 'prefix_indexes' => true, |
||
120 | 'options' => $options, |
||
121 | ]); |
||
122 | $capsule->setAsGlobal(); |
||
123 | |||
124 | // Eager-load the connection, to prevent database credentials appearing in error logs. |
||
125 | try { |
||
126 | self::pdo(); |
||
127 | } catch (PDOException $exception) { |
||
128 | throw new RuntimeException($exception->getMessage()); |
||
129 | } |
||
130 | |||
131 | $sql = self::DRIVER_INITIALIZATION[$driver]; |
||
132 | |||
133 | if ($sql !== '') { |
||
134 | self::exec($sql); |
||
135 | } |
||
236 |
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