Skip to content

Commit

Permalink
Always prefer stricter comparison for non-empty strings. (#26139)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored and taylorotwell committed Oct 17, 2018
1 parent b75c688 commit 67b9ef9
Show file tree
Hide file tree
Showing 27 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Console/ConfirmableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function confirmToProceed($warning = 'Application In Production!', $callb
protected function getDefaultConfirmCallback()
{
return function () {
return $this->getLaravel()->environment() == 'production';
return $this->getLaravel()->environment() === 'production';
};
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function __construct(EventMutex $mutex, $command)
*/
public function getDefaultOutput()
{
return (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null';
return (DIRECTORY_SEPARATOR === '\\') ? 'NUL' : '/dev/null';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connectors/SQLiteConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function connect(array $config)
// SQLite supports "in-memory" databases that only last as long as the owning
// connection does. These are useful for tests or for short lifetime store
// querying. In-memory databases may only have a single open connection.
if ($config['database'] == ':memory:') {
if ($config['database'] === ':memory:') {
return $this->createConnection('sqlite::memory:', $config, $options);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ protected function configure(Connection $connection, $type)
*/
protected function setPdoForType(Connection $connection, $type = null)
{
if ($type == 'read') {
if ($type === 'read') {
$connection->setPdo($connection->getReadPdo());
} elseif ($type == 'write') {
} elseif ($type === 'write') {
$connection->setReadPdo($connection->getPdo());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function withCount($relations)

unset($alias);

if (count($segments) == 3 && Str::lower($segments[1]) == 'as') {
if (count($segments) == 3 && Str::lower($segments[1]) === 'as') {
[$name, $alias] = [$segments[0], $segments[2]];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
*/
protected function incrementOrDecrementAttributeValue($column, $amount, $extra, $method)
{
$this->{$column} = $this->{$column} + ($method == 'increment' ? $amount : $amount * -1);
$this->{$column} = $this->{$column} + ($method === 'increment' ? $amount : $amount * -1);

$this->forceFill($extra);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function getRelationValue(array $dictionary, $key, $type)
{
$value = $dictionary[$key];

return $type == 'one' ? reset($value) : $this->related->newCollection($value);
return $type === 'one' ? reset($value) : $this->related->newCollection($value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ public function orderBy($column, $direction = 'asc')
{
$this->{$this->unions ? 'unionOrders' : 'orders'}[] = [
'column' => $column,
'direction' => strtolower($direction) == 'asc' ? 'asc' : 'desc',
'direction' => strtolower($direction) === 'asc' ? 'asc' : 'desc',
];

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function addFluentCommands(Grammar $grammar)
protected function creating()
{
return collect($this->commands)->contains(function ($command) {
return $command->name == 'create';
return $command->name === 'create';
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
}

if ($fluent['type'] == 'json') {
if ($fluent['type'] === 'json') {
$options['customSchemaOptions'] = [
'collation' => '',
];
Expand Down Expand Up @@ -206,6 +206,6 @@ protected static function mapFluentOptionToDoctrine($attribute)
*/
protected static function mapFluentValueToDoctrine($option, $value)
{
return $option == 'notnull' ? ! $value : $value;
return $option === 'notnull' ? ! $value : $value;
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/SqlServerConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SqlServerConnection extends Connection
public function transaction(Closure $callback, $attempts = 1)
{
for ($a = 1; $a <= $attempts; $a++) {
if ($this->getDriverName() == 'sqlsrv') {
if ($this->getDriverName() === 'sqlsrv') {
return parent::transaction($callback);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function supported($key, $cipher)
*/
public static function generateKey($cipher)
{
return random_bytes($cipher == 'AES-128-CBC' ? 16 : 32);
return random_bytes($cipher === 'AES-128-CBC' ? 16 : 32);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function environment()
*/
public function isLocal()
{
return $this['env'] == 'local';
return $this['env'] === 'local';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/VendorPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ protected function parseChoice($choice)
{
[$type, $value] = explode(': ', strip_tags($choice));

if ($type == 'Provider') {
if ($type === 'Provider') {
$this->provider = $value;
} elseif ($type == 'Tag') {
} elseif ($type === 'Tag') {
$this->tags = [$value];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function run()
try {
$exitCode = $this->app[Kernel::class]->call($this->command, $this->parameters);
} catch (NoMatchingExpectationException $e) {
if ($e->getMethodName() == 'askQuestion') {
if ($e->getMethodName() === 'askQuestion') {
$this->test->fail('Unexpected question "'.$e->getActualArguments()[0]->getQuestion().'" was asked.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Testing/RefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function usingInMemoryDatabase()
{
return config('database.connections')[
config('database.default')
]['database'] == ':memory:';
]['database'] === ':memory:';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function fullUrl()
{
$query = $this->getQueryString();

$question = $this->getBaseUrl().$this->getPathInfo() == '/' ? '/?' : '?';
$question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?';

return $query ? $this->url().$question.$query : $this->url();
}
Expand All @@ -121,7 +121,7 @@ public function fullUrl()
*/
public function fullUrlWithQuery(array $query)
{
$question = $this->getBaseUrl().$this->getPathInfo() == '/' ? '/?' : '?';
$question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?';

return count($this->query()) > 0
? $this->url().$question.Arr::query(array_merge($this->query(), $query))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level == 'error')
@if ($level === 'error')
# @lang('Whoops!')
@else
# @lang('Hello!')
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Matching/UriValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UriValidator implements ValidatorInterface
*/
public function matches(Route $route, Request $request)
{
$path = $request->path() == '/' ? '/' : '/'.$request->path();
$path = $request->path() === '/' ? '/' : '/'.$request->path();

return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function guest($path, $status = 302, $headers = [], $secure = null)
{
$request = $this->generator->getRequest();

$intended = $request->method() == 'GET' && $request->route() && ! $request->expectsJson()
$intended = $request->method() === 'GET' && $request->route() && ! $request->expectsJson()
? $this->generator->full()
: $this->generator->previous();

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected function checkForAlternateVerbs($request)
*/
protected function getRouteForMethods($request, array $methods)
{
if ($request->method() == 'OPTIONS') {
if ($request->method() === 'OPTIONS') {
return (new Route('OPTIONS', $request->path(), function () use ($methods) {
return new Response('', 200, ['Allow' => implode(',', $methods)]);
}))->bind($request);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function __call($method, $parameters)
}

if (in_array($method, $this->allowedAttributes)) {
if ($method == 'middleware') {
if ($method === 'middleware') {
return $this->attribute($method, is_array($parameters[0]) ? $parameters[0] : $parameters);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ public function __call($method, $parameters)
return $this->macroCall($method, $parameters);
}

if ($method == 'middleware') {
if ($method === 'middleware') {
return (new RouteRegistrar($this))->attribute($method, is_array($parameters[0]) ? $parameters[0] : $parameters);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public static function slug($title, $separator = '-', $language = 'en')
$title = static::ascii($title, $language);

// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
$flip = $separator === '-' ? '_' : '-';

$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Translation/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function __construct(Filesystem $files, $path)
*/
public function load($locale, $group, $namespace = null)
{
if ($group == '*' && $namespace == '*') {
if ($group === '*' && $namespace === '*') {
return $this->loadJsonPaths($locale);
}

if (is_null($namespace) || $namespace == '*') {
if (is_null($namespace) || $namespace === '*') {
return $this->loadPath($this->path, $locale, $group);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Translation/MessageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private function extractFromString($part, $number)
if (Str::contains($condition, ',')) {
[$from, $to] = explode(',', $condition, 2);

if ($to == '*' && $number >= $from) {
if ($to === '*' && $number >= $from) {
return $value;
} elseif ($from == '*' && $number <= $to) {
} elseif ($from === '*' && $number <= $to) {
return $value;
} elseif ($number >= $from && $number <= $to) {
return $value;
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function validateDigitsBetween($attribute, $value, $parameters)
*/
public function validateDimensions($attribute, $value, $parameters)
{
if ($this->isValidFileInstance($value) && $value->getClientMimeType() == 'image/svg+xml') {
if ($this->isValidFileInstance($value) && $value->getClientMimeType() === 'image/svg+xml') {
return true;
}

Expand Down Expand Up @@ -713,7 +713,7 @@ protected function prepareUniqueId($id)
$id = $this->getValue($matches[1]);
}

if (strtolower($id) == 'null') {
if (strtolower($id) === 'null') {
$id = null;
}

Expand Down

0 comments on commit 67b9ef9

Please sign in to comment.