Skip to content

Commit 82ff98b

Browse files
Made tweaks found by a static anayzer
1 parent 0136b7a commit 82ff98b

File tree

10 files changed

+24
-42
lines changed

10 files changed

+24
-42
lines changed

src/Dotenv.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function create($paths, $file = null, FactoryInterface $envFactory
5959
* @param string[] $paths
6060
* @param string $file
6161
*
62-
* @return string
62+
* @return string[]
6363
*/
6464
private static function getFilePaths(array $paths, $file)
6565
{
@@ -73,7 +73,7 @@ private static function getFilePaths(array $paths, $file)
7373
*
7474
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
7575
*
76-
* @return string[]
76+
* @return array<string|null>
7777
*/
7878
public function load()
7979
{
@@ -85,7 +85,7 @@ public function load()
8585
*
8686
* @throws \Dotenv\Exception\InvalidFileException
8787
*
88-
* @return string[]
88+
* @return array<string|null>
8989
*/
9090
public function safeLoad()
9191
{
@@ -102,7 +102,7 @@ public function safeLoad()
102102
*
103103
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
104104
*
105-
* @return string[]
105+
* @return array<string|null>
106106
*/
107107
public function overload()
108108
{
@@ -116,7 +116,7 @@ public function overload()
116116
*
117117
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
118118
*
119-
* @return string[]
119+
* @return array<string|null>
120120
*/
121121
protected function loadData($overload = false)
122122
{
@@ -126,13 +126,13 @@ protected function loadData($overload = false)
126126
/**
127127
* Required ensures that the specified variables exist, and returns a new validator object.
128128
*
129-
* @param string|string[] $variable
129+
* @param string|string[] $variables
130130
*
131131
* @return \Dotenv\Validator
132132
*/
133-
public function required($variable)
133+
public function required($variables)
134134
{
135-
return new Validator((array) $variable, $this->loader);
135+
return new Validator((array) $variables, $this->loader);
136136
}
137137

138138
/**

src/Environment/AbstractVariables.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function isImmutable()
4747
*/
4848
public function has($name)
4949
{
50-
return !is_null($this->get($name));
50+
return $this->get($name) !== null;
5151
}
5252

5353
/**

src/Environment/Adapter/ApacheAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function get($name)
4646
public function set($name, $value = null)
4747
{
4848
if (apache_getenv($name) !== false) {
49-
apache_setenv($name, $value);
49+
apache_setenv($name, (string) $value);
5050
}
5151
}
5252

src/Exception/InvalidCallbackException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Lines.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function process(array $lines)
3737
* @param string $line
3838
* @param string[] $buffer
3939
*
40-
* @return string[]
40+
* @return array
4141
*/
4242
private static function multilineProcess($multiline, $line, array $buffer)
4343
{

src/Loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function setImmutable($immutable = false)
8282
*
8383
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
8484
*
85-
* @return string[]
85+
* @return array<string|null>
8686
*/
8787
public function load()
8888
{
@@ -143,7 +143,7 @@ private static function readFromFile($filePath)
143143
*
144144
* @param string[] $entries
145145
*
146-
* @return string[]
146+
* @return array<string|null>
147147
*/
148148
private function processEntries(array $entries)
149149
{

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static function processQuotedValue($value)
154154
$quote
155155
);
156156

157-
$value = preg_replace($pattern, '$1', $value);
157+
$value = (string) preg_replace($pattern, '$1', $value);
158158

159159
return str_replace('\\\\', '\\', str_replace("\\$quote", $quote, $value));
160160
}

src/Validator.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Dotenv;
44

5-
use Dotenv\Exception\InvalidCallbackException;
65
use Dotenv\Exception\ValidationException;
76

87
/**
@@ -129,28 +128,24 @@ function ($value) use ($choices) {
129128
* @param callable $callback
130129
* @param string $message
131130
*
132-
* @throws \Dotenv\Exception\InvalidCallbackException|\Dotenv\Exception\ValidationException
131+
* @throws \Dotenv\Exception\ValidationException
133132
*
134133
* @return \Dotenv\Validator
135134
*/
136-
protected function assertCallback($callback, $message = 'failed callback assertion')
135+
protected function assertCallback(callable $callback, $message = 'failed callback assertion')
137136
{
138-
if (!is_callable($callback)) {
139-
throw new InvalidCallbackException('The provided callback must be callable.');
140-
}
137+
$failing = [];
141138

142-
$variablesFailingAssertion = [];
143-
foreach ($this->variables as $variableName) {
144-
$variableValue = $this->loader->getEnvironmentVariable($variableName);
145-
if (call_user_func($callback, $variableValue) === false) {
146-
$variablesFailingAssertion[] = $variableName." $message";
139+
foreach ($this->variables as $variable) {
140+
if ($callback($this->loader->getEnvironmentVariable($variable)) === false) {
141+
$failing[] = sprintf('%s %s', $variable, $message);
147142
}
148143
}
149144

150-
if (count($variablesFailingAssertion) > 0) {
145+
if (count($failing) > 0) {
151146
throw new ValidationException(sprintf(
152147
'One or more environment variables failed assertions: %s.',
153-
implode(', ', $variablesFailingAssertion)
148+
implode(', ', $failing)
154149
));
155150
}
156151

tests/Dotenv/LinesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class LinesTest extends TestCase
77
{
88
/**
9-
* @var string
9+
* @var string|false
1010
*/
1111
protected $autodetect;
1212

tests/Dotenv/LoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LoaderTest extends TestCase
1212
protected $folder;
1313

1414
/**
15-
* @var string|null
15+
* @var string[]|null
1616
*/
1717
protected $keyVal;
1818

0 commit comments

Comments
 (0)