Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strict (not-)equal checks #1092

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators">
<exclude-pattern>/includes</exclude-pattern>
</rule>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function up(): void
$table->timestamps();
});
} catch (QueryException $e) {
if ($type != 'json') {
if ($type !== 'json') {
throw $e;
}

Expand Down
2 changes: 1 addition & 1 deletion db/migrations/2022_12_15_000000_create_shifts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function up(): void
->get();
foreach ($records as $record) {
$isUpdated = !empty($record->edited_at_timestamp)
&& $record->edited_at_timestamp != $record->created_at_timestamp;
&& $record->edited_at_timestamp !== $record->created_at_timestamp;

$connection->table('shifts')->insert([
'id' => $record->SID,
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/Admin/UserWorkLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function editWorklog(Request $request): Response
if (isset($worklogId)) {
$worklog = $this->worklog->findOrFail((int) $worklogId);

if ($worklog->user->id != $userId) {
if ($worklog->user->id !== $userId) {
throw new HttpNotFound();
}
return $this->showEditWorklog($user, $worklog->worked_at, $worklog->hours, $worklog->comment, true);
Expand All @@ -72,7 +72,7 @@ public function saveWorklog(Request $request): Response
if (isset($worklogId)) {
$worklog = $this->worklog->findOrFail((int) $worklogId);

if ($worklog->user->id != $userId) {
if ($worklog->user->id !== $userId) {
throw new HttpNotFound();
}
} else {
Expand All @@ -99,7 +99,7 @@ public function showDeleteWorklog(Request $request): Response
$user = $this->user->findOrFail($userId);
$worklog = $this->worklog->findOrFail($worklogId);

if ($worklog->user->id != $userId) {
if ($worklog->user->id !== $userId) {
throw new HttpNotFound();
}

Expand All @@ -116,7 +116,7 @@ public function deleteWorklog(Request $request): Response

$worklog = $this->worklog->findOrFail($worklogId);

if ($worklog->user->id != $userId) {
if ($worklog->user->id !== $userId) {
throw new HttpNotFound();
}
$worklog->delete();
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function listConversations(): Response

$conversations = [];
foreach ($latestMessages as $msg) {
$otherUser = $msg->user_id == $currentUser->id ? $msg->receiver : $msg->sender;
$otherUser = $msg->user_id === $currentUser->id ? $msg->receiver : $msg->sender;
$unreadMessages = $numberOfUnreadMessages[$otherUser->id] ?? 0;

$conversations[] = [
Expand Down Expand Up @@ -114,7 +114,7 @@ public function messagesOfConversation(Request $request): Response
->get();

$unreadMessages = $messages->filter(function ($m) use ($otherUser) {
return $m->user_id == $otherUser->id && !$m->read;
return $m->user_id === $otherUser->id && !$m->read;
});

foreach ($unreadMessages as $msg) {
Expand Down Expand Up @@ -146,7 +146,7 @@ public function send(Request $request): Response
$newMessage->sender()->associate($currentUser);
$newMessage->receiver()->associate($otherUser);
$newMessage->text = $data['text'];
$newMessage->read = $otherUser->id == $currentUser->id; // if its to myself, I obviously read it.
$newMessage->read = $otherUser->id === $currentUser->id; // if its to myself, I obviously read it.
$newMessage->save();

return $this->redirect->to('/messages/' . $otherUser->id . '#newest');
Expand All @@ -164,7 +164,7 @@ public function delete(Request $request): Response
$currentUser = $this->auth->user();
$msg = $this->message->findOrFail($msgId);

if ($msg->user_id == $currentUser->id) {
if ($msg->user_id === $currentUser->id) {
$msg->delete();
} else {
throw new HttpForbidden('You can not delete a message you haven\'t send');
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Metrics/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function stats(): Response
protected function checkAuth(bool $isJson = false): void
{
$apiKey = $this->config->get('api_key');
if (empty($apiKey) || $this->request->get('api_key') == $apiKey) {
if (empty($apiKey) || $this->request->get('api_key') === $apiKey) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Metrics/MetricsEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function get(string $path, array $data = []): string
foreach ($list as $row) {
$row = $this->expandData($row);

if ($type == 'histogram') {
if ($type === 'histogram') {
$return = array_merge($return, $this->formatHistogram($row, $name));

continue;
Expand Down Expand Up @@ -177,7 +177,7 @@ protected function escape(mixed $value): mixed

public function canRender(string $path): bool
{
return $path == '/metrics';
return $path === '/metrics';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function deleteComment(Request $request): Response

$comment = $this->comment->findOrFail($commentId);
if (
$comment->user->id != $this->auth->user()->id
$comment->user->id !== $this->auth->user()->id
&& !$this->auth->can('admin_news')
&& !$this->auth->can('comment.delete')
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public function index(Request $request): Response
}

$user = $this->auth->user();
if ($oauth && $user && $user->id != $oauth->user_id) {
if ($oauth && $user && $user->id !== $oauth->user_id) {
throw new HttpNotFound('oauth.already-connected');
}

$connectProvider = $this->session->get('oauth2_connect_provider');
$this->session->remove('oauth2_connect_provider');
if (!$oauth && $user && $connectProvider && $connectProvider == $providerName) {
if (!$oauth && $user && $connectProvider && $connectProvider === $providerName) {
$oauth = new OAuth([
'provider' => $providerName,
'identifier' => $resourceId,
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/QuestionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function delete(Request $request): Response
);

$question = $this->question->findOrFail($data['id']);
if ($question->user->id != $this->auth->user()->id) {
if ($question->user->id !== $this->auth->user()->id) {
throw new HttpForbidden();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function savePassword(Request $request): Response

if (!empty($user->password) && !$this->auth->verifyPassword($user, $data['password'])) {
$this->addNotification('auth.password.error', NotificationType::ERROR);
} elseif ($data['new_password'] != $data['new_password2']) {
} elseif ($data['new_password'] !== $data['new_password2']) {
$this->addNotification('validation.password.confirmed', NotificationType::ERROR);
} else {
$this->auth->setPassword($user, $data['new_password']);
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Listener/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function syncTeams(string $providerName, User $user, array $ssoTeam):
return;
}

if ($userAngeltype->pivot->supporter != $supporter) {
if ($userAngeltype->pivot->supporter !== $supporter) {
$userAngeltype->pivot->supporter = $supporter;
$userAngeltype->pivot->save();

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/Handlers/Legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function report(Throwable $e): void
$this->stripBasePath($e->getFile()),
$e->getLine(),
$previous ? $previous->getMessage() : 'None',
json_encode($e->getTrace(), PHP_SAPI == 'cli' ? JSON_PRETTY_PRINT : 0)
json_encode($e->getTrace(), PHP_SAPI === 'cli' ? JSON_PRETTY_PRINT : 0)
));

if (is_null($this->log)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/ConfigureEnvironmentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function register(): void
$this->setTimeZone($timezone);

$this->displayErrors(false);
if ($config->get('environment') == 'development') {
if ($config->get('environment') === 'development') {
$this->displayErrors(true);
$this->errorReporting(E_ALL);
$this->setupDevErrorHandler();
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Schedule/XmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function parseEvents(array $eventElements, Room $room): array

$recording = '';
$recordingElement = $event->xpath('recording');
if ($recordingElement && $this->getFirstXpathContent('optout', $recordingElement[0]) == 'false') {
if ($recordingElement && $this->getFirstXpathContent('optout', $recordingElement[0]) === 'false') {
$recording = $this->getFirstXpathContent('license', $recordingElement[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function path(): string
{
$pattern = trim($this->getPathInfo(), '/');

return $pattern == '' ? '/' : $pattern;
return $pattern === '' ? '/' : $pattern;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function withView(string $view, array $data = [], int $status = 200, arra

$new = clone $this;
$new->setContent($this->renderer->render($view, $data));
$new->setStatusCode($status, ($status == $this->getStatusCode() ? $this->statusText : null));
$new->setStatusCode($status, ($status === $this->getStatusCode() ? $this->statusText : null));

foreach ($headers as $key => $values) {
$new = $new->withAddedHeader($key, $values);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/SessionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ protected function getSessionStorage(): SessionStorageInterface
*/
protected function isCli(): bool
{
return PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg';
return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg';
}
}
4 changes: 2 additions & 2 deletions src/Middleware/RouteDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$route = $this->dispatcher->dispatch($request->getMethod(), $path);

$status = $route[0];
if ($status == FastRouteDispatcher::NOT_FOUND) {
if ($status === FastRouteDispatcher::NOT_FOUND) {
if ($this->notFound instanceof MiddlewareInterface) {
return $this->notFound->process($request, $handler);
}

return $this->response->withStatus(404);
}

if ($status == FastRouteDispatcher::METHOD_NOT_ALLOWED) {
if ($status === FastRouteDispatcher::METHOD_NOT_ALLOWED) {
$methods = $route[1];
return $this->response
->withStatus(405)
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RouteDispatcherServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function register(): void
'cacheFile' => $this->app->get('path.cache.routes'),
];

if ($config->get('environment') == 'development') {
if ($config->get('environment') === 'development') {
$options['cacheDisabled'] = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Twig/Extensions/Develop.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(protected Config $config)
*/
public function getFunctions(): array
{
if ($this->config->get('environment') != 'development') {
if ($this->config->get('environment') !== 'development') {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/TwigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function registerTwigEngine(): void

$cache = $this->app->get('path.cache.views');
$twigDebug = false;
if ($config->get('environment') == 'development') {
if ($config->get('environment') === 'development') {
$cache = false;
$twigDebug = true;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Controllers/MessagesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function testIndexWithConversationsOnlyContainsConversationsWithMe(): voi
$this->assertEquals(2, count($conversations));
$msg0 = $conversations[0]['latest_message']->text;
$msg1 = $conversations[1]['latest_message']->text;
$this->assertTrue(($msg0 == 'a>b' && $msg1 == 'c>a') || ($msg1 == 'c>a' && $msg0 == 'a>b'));
$this->assertTrue(($msg0 === 'a>b' && $msg1 === 'c>a') || ($msg1 === 'c>a' && $msg0 === 'a>b'));

return $this->response;
});
Expand Down Expand Up @@ -540,7 +540,7 @@ public function setUp(): void

protected function assertArrayOrCollection(mixed $obj): void
{
$this->assertTrue(gettype($obj) == 'array' || $obj instanceof Collection);
$this->assertTrue(gettype($obj) === 'array' || $obj instanceof Collection);
}

protected function createMessage(User $from, User $to, string $text, Carbon $at): Message
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Helpers/Stub/UserModelImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UserModelImplementation extends User

public function find(mixed $id, array $columns = ['*']): ?User
{
if ($id != static::$id) {
if ($id !== static::$id) {
throw new InvalidArgumentException('Wrong user ID searched');
}

Expand All @@ -31,7 +31,7 @@ public function find(mixed $id, array $columns = ['*']): ?User
*/
public static function whereApiKey(string $apiKey): array|Collection|QueryBuilder
{
if ($apiKey != static::$apiKey) {
if ($apiKey !== static::$apiKey) {
throw new InvalidArgumentException('Wrong api key searched');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Helpers/Translation/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testReplaceText(): void
->method('gettext')
->willReturnCallback(function () use (&$i) {
$i++;
if ($i != 4) {
if ($i !== 4) {
throw new TranslationNotFound();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testRegister(): void
$subject();
}

return is_callable($subject) || $subject == LegacyMiddleware::class;
return is_callable($subject) || $subject === LegacyMiddleware::class;
}));

/** @var RouteDispatcherServiceProvider|MockObject $serviceProvider */
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class ExtensionTest extends TestCase
protected function assertFilterExists(string $name, callable $callback, array $functions): void
{
foreach ($functions as $function) {
if ($function->getName() != $name) {
if ($function->getName() !== $name) {
continue;
}

Expand All @@ -47,7 +47,7 @@ protected function assertExtensionExists(
array $options = []
): void {
foreach ($functions as $function) {
if ($function->getName() != $name) {
if ($function->getName() !== $name) {
continue;
}

Expand Down