Skip to content

Commit

Permalink
Require PhpStan to level 9 and fix by internal strict rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Nov 11, 2021
1 parent 87cc970 commit 9d44582
Show file tree
Hide file tree
Showing 39 changed files with 354 additions and 260 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"baraja-core/doctrine": "^3.0",
"baraja-core/structured-api": "^3.0 >=3.0.6",
"baraja-core/admin-bar": "^2.3",
"baraja-core/plugin-system": "^2.0",
"baraja-core/plugin-system": "^2.3",
"baraja-core/localization": "^2.0",
"baraja-core/baraja-cloud": "^2.0",
"baraja-core/url": "^1.1",
Expand Down Expand Up @@ -58,7 +58,7 @@
},
"scripts": {
"phpstan": [
"vendor/bin/phpstan analyse src -c phpstan.neon --level 8 --no-progress"
"vendor/bin/phpstan analyse src -c phpstan.neon --level 9 --no-progress"
]
},
"minimum-stability": "stable"
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
includes:
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/spaze/phpstan-disallowed-calls/extension.neon
- vendor/spaze/phpstan-disallowed-calls/disallowed-dangerous-calls.neon
- vendor/spaze/phpstan-disallowed-calls/disallowed-execution-calls.neon

Expand Down
12 changes: 6 additions & 6 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ private function route(string $path): array

if ($more === '' && $view !== '') { // route plugin request in format "xxx/yyy"
$plugin = Helpers::formatPresenterNameByUri($plugin);
$view = Helpers::formatActionNameByUri(explode('?', $view)[0]) ?: null;
$view = Helpers::formatActionNameByUri(explode('?', $view)[0]);
} elseif ($plugin !== '') { // route plugin request in format "xxx"
$plugin = Helpers::formatPresenterNameByUri(explode('?', $plugin)[0]) ?: null;
$plugin = Helpers::formatPresenterNameByUri(explode('?', $plugin)[0]);
}

return [
'plugin' => $plugin ?: 'Homepage',
'view' => $view ?: 'default',
'plugin' => $plugin !== '' ? $plugin : 'Homepage',
'view' => $view !== '' ? $view : 'default',
'locale' => $locale,
'path' => $path,
];
Expand All @@ -138,8 +138,8 @@ private function runApplication(string $plugin, string $view, string $locale, st
{
try {
$this->application->run(
plugin: $plugin ?: 'Homepage',
view: $view ?: 'default',
plugin: $plugin,
view: $view,
locale: $locale,
path: $path,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Announcement/Entity/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Announcement
public function __construct(User $user, ?string $locale, string $message, ?self $parent = null)
{
$this->user = $user;
$this->locale = $locale ? Localization::normalize($locale) : null;
$this->locale = $locale !== null ? Localization::normalize($locale) : null;
$this->setMessage($message);
$this->parent = $parent;
$this->showSince = new \DateTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/CmsDashboardEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function postPostTopic(string $message): void

private function getUserIdentity(): User
{
$identity = $this->userManager->getCmsIdentity();
$identity = $this->userManager->getIdentity();
assert($identity instanceof User);

return $identity;
Expand Down
9 changes: 5 additions & 4 deletions src/Api/CmsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public function postSign(string $locale, string $username, string $password, boo
$this->sendError('Empty username or password.');
}
try {
$user = $this->userManager->authenticate($username, $password, $remember);
$this->userManager->authenticate($username, $password, $remember);
} catch (AuthenticationException $e) {
$code = $e->getCode();
if (in_array($code, [Authenticator::IDENTITY_NOT_FOUND, Authenticator::INVALID_CREDENTIAL, Authenticator::FAILURE], true)) {
$this->sendError($e->getMessage());
} elseif ($code === Authenticator::NOT_APPROVED) {
$reason = (string) $e->getMessage();
$reason = $e->getMessage();
$this->sendError(
'The user has been assigned a permanent block. Please contact your administrator.'
. ($reason !== '' ? ' Reason for blocking: ' . $reason : ''),
. ($reason !== '' ? ' Block reason: ' . $reason : ''),
);
} else {
$this->sendError('Wrong username or password.');
Expand All @@ -92,6 +92,7 @@ public function postCheckOtpCode(string $locale, string $code): void
if ($userEntity === null) {
$this->sendError('User is not logged in.');
}
assert($userEntity instanceof CmsUser);
try {
$user = $this->userManager->getUserById($userEntity->getId());
} catch (NoResultException | NonUniqueResultException) {
Expand Down Expand Up @@ -149,7 +150,7 @@ public function postForgotPassword(string $locale, string $username): void

public function postForgotUsername(string $locale, string $realName): void
{
if (preg_match('/^(\S+)\s+(\S+)$/', trim($realName), $parser)) {
if (preg_match('/^(\S+)\s+(\S+)$/', trim($realName), $parser) === 1) {
try {
/** @var CmsUser $user */
$user = $this->entityManager->getRepository($this->userManager->getDefaultEntity())
Expand Down
12 changes: 7 additions & 5 deletions src/Api/CmsInstallEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ public function postCloudCreateAccount(
$this->sendError('Zadejte vaše reálné jméno, které musí existovat.');
}

/** @var array{token?: string, message?: string} $response */
$response = (array) json_decode(
@file_get_contents(
(string) @file_get_contents(
CloudManager::ENDPOINT_URL . '/cloud-status/create-account?domain='
. urlencode(Url::get()->getNetteUrl()->getDomain(3))
. '&email=' . urlencode($email)
. '&password=' . urlencode($password)
. '&firstName=' . urlencode($firstName)
. '&lastName=' . urlencode($lastName)
. ($phone ? '&phone=' . urlencode($phone) : '')
) ?: '{}',
. ($phone !== null ? '&phone=' . urlencode($phone) : '')
),
true
);
if (isset($response['token']) === false) {
Expand All @@ -168,13 +169,14 @@ public function postCloudLogin(string $email, string $password): void
$this->sendError('E-mail nemá správný formát.');
}

/** @var array{token?: string, message?: string} $response */
$response = (array) json_decode(
@file_get_contents(
(string) @file_get_contents(
CloudManager::ENDPOINT_URL . '/cloud-status/token-by-user?domain='
. urlencode(Url::get()->getNetteUrl()->getDomain(3))
. '&email=' . urlencode($email)
. '&password=' . urlencode($password)
) ?: '{}',
),
true
);
if (isset($response['token']) === false) {
Expand Down
3 changes: 1 addition & 2 deletions src/Api/InternalSupportEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Baraja\Cms\Support\Support;
use Baraja\StructuredApi\BaseEndpoint;
use Nette\Utils\DateTime;
use Nette\Utils\Strings;
use Nette\Utils\Validators;

Expand Down Expand Up @@ -52,7 +51,7 @@ public function createIssue(
}
$dueDateReal = null;
if ($dueDate !== null) {
$dueDateReal = DateTime::from($dueDate);
$dueDateReal = new \DateTime($dueDate);
if ($dueDateReal->getTimestamp() <= time()) {
$this->sendError('Ths issue due date cannot be in the past.');
}
Expand Down
Loading

0 comments on commit 9d44582

Please sign in to comment.