| Conditions | 2 |
| Paths | 2 |
| Total Lines | 55 |
| Code Lines | 42 |
| 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 |
||
| 24 | public function testWriteLocalEnvVars() |
||
| 25 | { |
||
| 26 | $this->projectDir = dirname(__DIR__, 5) . '/var/cache/test/dotenvtest'; |
||
| 27 | $fileSystem = new Filesystem(); |
||
| 28 | $fileSystem->copy(__DIR__ . '/Fixture/.env.local', $this->projectDir . '/.env.local', true); |
||
| 29 | $originalFileContents = trim($this->getFileContents()); |
||
| 30 | $helper = new LocalDotEnvHelper($this->projectDir); |
||
| 31 | |||
| 32 | $helper->writeLocalEnvVars([]); |
||
| 33 | $this->assertEquals($originalFileContents, $this->getFileContents()); |
||
| 34 | |||
| 35 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => 'foo']); |
||
| 36 | $expected = $originalFileContents . "\nMY_NEW_VAR=foo"; |
||
| 37 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 38 | |||
| 39 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => 'f#oo']); |
||
| 40 | $expected = $originalFileContents . "\nMY_NEW_VAR=f%23oo"; |
||
| 41 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 42 | |||
| 43 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => '\'bar\'']); |
||
| 44 | $expected = $originalFileContents . "\nMY_NEW_VAR='bar'"; |
||
| 45 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 46 | |||
| 47 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => 'foo', 'BAR' => 123], true); |
||
| 48 | $expected = "MY_NEW_VAR=foo\nBAR=123"; |
||
| 49 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 50 | |||
| 51 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => '!f@oo', 'BAR' => '!1(2)3'], true); |
||
| 52 | $expected = "MY_NEW_VAR=f@oo\nBAR=1(2)3"; |
||
| 53 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 54 | |||
| 55 | $helper->writeLocalEnvVars(['MY_NEW_VAR' => '!\'f@oo\''], true); |
||
| 56 | $expected = 'MY_NEW_VAR=\'f@oo\''; |
||
| 57 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 58 | |||
| 59 | $helper->writeLocalEnvVars(['FOO' => 'foo', 'BAR' => 'bar', 'FEE' => 'fee', 'BEE' => 'bee'], true); |
||
| 60 | $helper->writeLocalEnvVars(['BAR' => 'bar2', 'BOO' => 'boo']); // overwriting a value should place it at the end of the list |
||
| 61 | $expected = "FOO=foo\nFEE=fee\nBEE=bee\nBAR=bar2\nBOO=boo"; |
||
| 62 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 63 | |||
| 64 | $data = [ |
||
| 65 | 'database_driver' => 'mysql', |
||
| 66 | 'database_host' => 'localhost', |
||
| 67 | 'database_name' => 'foo' |
||
| 68 | ]; |
||
| 69 | $vars = [ |
||
| 70 | 'DATABASE_URL' => '!' . $data['database_driver'] |
||
| 71 | . '://$DATABASE_USER:$DATABASE_PWD' |
||
| 72 | . '@' . $data['database_host'] . (!empty($data['database_port']) ? ':' . $data['database_port'] : '') |
||
| 73 | . '/' . $data['database_name'] |
||
| 74 | . '?serverVersion=5.7' // any value will work (bypasses DBALException) |
||
| 75 | ]; |
||
| 76 | $helper->writeLocalEnvVars($vars, true); |
||
| 77 | $expected = 'DATABASE_URL=mysql://$DATABASE_USER:$DATABASE_PWD@localhost/foo?serverVersion=5.7'; |
||
| 78 | $this->assertEquals($expected, $this->getFileContents()); |
||
| 79 | } |
||
| 86 |
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