Skip to content

Commit

Permalink
psalm & phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Mar 27, 2024
1 parent b1cb6c5 commit c986093
Show file tree
Hide file tree
Showing 27 changed files with 1,265 additions and 1,327 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"symfony/dom-crawler": "^7.0",
"symfony/uid": "^7.0",
"web-auth/webauthn-lib": "^4.7",
"web-token/jwt-key-mgmt": "^3.2",
"web-token/jwt-signature-algorithm-ecdsa": "^3.2",
"web-token/jwt-signature-algorithm-eddsa": "^3.2",
"web-token/jwt-signature-algorithm-rsa": "^3.2",
"web-token/jwt-library": "^3.3",
"whichbrowser/parser": "^2.1"
},
"require-dev": {
Expand Down
2,504 changes: 1,222 additions & 1,282 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
@@ -20,17 +21,17 @@
</php>

<!-- Load extension for fixtures -->
<extensions>
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Authenticator/WebauthnAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
'userHandle' => $this->getUserHandle($request),
]);

if (empty($user)) {
if ($user == null) {
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/DownloadMatchdayRatingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
{
$matchday = (int)$args->getArgument('matchday');

return $this->exec($matchday, $io) ? CommandInterface::CODE_SUCCESS : CommandInterface::CODE_ERROR;
return $this->exec($matchday, $io) != null ? CommandInterface::CODE_SUCCESS : CommandInterface::CODE_ERROR;
}

/**
Expand All @@ -75,7 +75,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
public function exec(int $matchday, ConsoleIo $io): ?string
{
$url = $this->getDropboxUrl($matchday, $io);
if ($url) {
if ($url != null) {
return $this->downloadDropboxFile($url, $matchday, $io);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/GetMatchdayScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
{
/** @var \App\Model\Table\SeasonsTable $seasonsTable */
$seasonsTable = $this->fetchTable('Seasons');
$season = $args->getArgument('season') ?
$season = $args->getArgument('season') != null ?
$seasonsTable->get($args->getArgument('season')) : $this->currentSeason;
if (!$args->hasArgument('matchday')) {
$matchday = $this->currentMatchday;
Expand Down Expand Up @@ -108,7 +108,7 @@ public function exec(Season $season, Matchday $matchday, ConsoleIo $io): DateTim
$seasonOption = $crawler->filterXPath('//select[@name="season"]/option[text()="' . $year . '"]');
if ($seasonOption->count()) {
$seasonId = $seasonOption->first()->attr('value');
if ($seasonId) {
if ($seasonId != null) {
$matchdayResponse = $client->get('/api/season/' . $seasonId . '/championship/A/matchday?lang=it');
/**
* @psalm-suppress MixedArrayAccess
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RecalcScoresCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
$io->out('Was ' . $orig . ' to ' . $score->points);
}

return $scoresTable->saveMany($scores) ? CommandInterface::CODE_SUCCESS : CommandInterface::CODE_ERROR;
return $scoresTable->saveMany($scores) != false ? CommandInterface::CODE_SUCCESS : CommandInterface::CODE_ERROR;
}
}
2 changes: 1 addition & 1 deletion src/Command/ResetPasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
private function reset(User $user, ConsoleIo $io): void
{
$usersTable = $this->fetchTable('Users');
if ($user->email && $user->name) {
if ($user->email != null && $user->name != null) {
$hasher = new DefaultPasswordHasher();
$io->out('Resetting password for ' . $user->email);
$user->password = $hasher->hash(strtolower($user->name));
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SendLineupsEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
*/
public function execute(Arguments $args, ConsoleIo $io): ?int
{
if ($this->currentMatchday->date->wasWithinLast('59 seconds') || $args->getOption('force')) {
if ($this->currentMatchday->date->wasWithinLast('59 seconds') || $args->getOption('force') == true) {
$championshipsTable = $this->fetchTable('Championships');
/** @var array<\App\Model\Entity\Championship> $championships */
$championships = $championshipsTable->find()
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SendMissingLineupNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
{
$tomorrow = DateTime::now()->addDays(1)->second(0);
if (
$args->getOption('force') ||
$args->getOption('force') == true ||
$this->currentMatchday->date->isWithinNext('30 minutes') ||
$this->currentMatchday->date->equals($tomorrow)
) {
Expand Down
6 changes: 3 additions & 3 deletions src/Command/TransfertCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
*/
public function execute(Arguments $args, ConsoleIo $io): ?int
{
if ($this->currentMatchday->isDoTransertDay() || $args->getOption('force')) {
if ($this->currentMatchday->isDoTransertDay() || $args->getOption('force') == true) {
$matchday = $this->currentMatchday;
if ($args->hasArgument('matchday')) {
$matchdaysTable = $this->fetchTable('Matchdays');
Expand Down Expand Up @@ -98,7 +98,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
];
}
$io->helper('Table')->output($table);
if (!$args->getOption('no-commit')) {
if ($args->getOption('no-commit') == false) {
$this->doTransferts($io, $selectionsArray);
}
} else {
Expand All @@ -121,7 +121,7 @@ private function doTransferts(ConsoleIo $io, array $selections): void
{
/** @var \App\Model\Table\SelectionsTable $selectionsTable */
$selectionsTable = $this->fetchTable('Selections');
if ($selectionsTable->saveMany($selections)) {
if ($selectionsTable->saveMany($selections) != false) {
$io->out('Changes committed');
} else {
$io->out('Error occurred');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/UpdateMatchdayCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function exec(Season $season, int $matchdayNumber, Arguments $args, Conso

$date = (new GetMatchdayScheduleCommand())->exec($season, $matchday, $io);
if ($date != null && (!$season->key_gazzetta || $date->isFuture())) {
$res = $args->getOption('no-interaction') || ($args->getOption('no-interaction') == false &&
$res = $args->getOption('no-interaction') == true || ($args->getOption('no-interaction') == false &&
$io->askChoice(
'Set ' . $date->format('Y-m-d H:i:s') . ' for matchday ' . $matchday->number,
['y', 'n'],
Expand Down
10 changes: 5 additions & 5 deletions src/Command/WeeklyScriptCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
$io->out('Completed succesfully');
}
}
if ($args->getOption('force_send_mail')) {
if ($args->getOption('force_send_mail') == true) {
/** @var \App\Model\Entity\Matchday $matchday */
$matchday = $this->fetchTable('Matchdays')
->find()
Expand Down Expand Up @@ -160,7 +160,7 @@ protected function calculatePoints(Matchday $matchday, array $championships, Arg
$scores = [];
$success = false;
foreach ($championships as $championship) {
if (!$args->getOption('no_calc_scores')) {
if ($args->getOption('no_calc_scores') == false) {
$io->out("Calculating points of matchday {$matchday->number} for league {$championship->league->name}");
foreach ($championship->teams as $team) {
$io->out('Elaborating team ' . $team->name);
Expand All @@ -169,16 +169,16 @@ protected function calculatePoints(Matchday $matchday, array $championships, Arg
$success = $scoresTable->saveMany($scores, [
'checkRules' => false,
'associated' => ['Lineups.Dispositions' => ['associated' => false]],
]);
} elseif ($args->getOption('force_send_mail')) {
]) != false;
} elseif ($args->getOption('force_send_mail') == true) {
$scoresTable = $this->fetchTable('Scores');
/** @var array<array-key, \App\Model\Entity\Score> $scores */
$scores = $scoresTable->find('list', [
'keyField' => 'team_id',
])->where(['matchday_id' => $matchday->id])->toArray();
$success = true;
}
if ($success && $championship->started && !$args->getOption('no_send_mail')) {
if ($success && $championship->started && $args->getOption('no_send_mail') == false) {
$io->out('Sending mails');
$this->sendScoreMails($matchday, $championship);
$io->out('Sending notification');
Expand Down
1 change: 1 addition & 0 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function initialize(): void
EventManager::instance()->on(new GetStreamEventListener());

$this->getCurrentMatchday();
$this->response->withType('json');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Teams/ScoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function viewByMatchday(?int $matchdayId = null): void
$conditions = [
'team_id' => (int)$this->getRequest()->getParam('team_id'),
];
if ($matchdayId) {
if ($matchdayId != null) {
$conditions['matchday_id'] = $matchdayId;
}
$this->Crud->on('beforeFind', function (EventInterface $event) use ($conditions): SelectQuery {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Club extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_virtual = [
'abbreviation',
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Member extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'created_at',
Expand All @@ -76,7 +76,7 @@ class Member extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_virtual = [
'photo_url',
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Player extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_virtual = [
'photo_url',
Expand Down Expand Up @@ -72,6 +72,6 @@ protected function _getPhotoUrl(): ?string
*/
protected function _getFullName(): string
{
return $this->surname . ($this->name ? ' ' . $this->name : '');
return $this->surname . ($this->name != null ? ' ' . $this->name : '');
}
}
2 changes: 1 addition & 1 deletion src/Model/Entity/PublicKeyCredentialSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PublicKeyCredentialSource extends Entity
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'attestation_type',
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/PushSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PushSubscription extends Entity
/**
* Fields that are excluded from JSON an array versions of the entity.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'auth_token',
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Season extends Entity
/**
* Fields that are excluded from JSON an array versions of the entity.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'key_gazzetta',
Expand All @@ -57,7 +57,7 @@ class Season extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_virtual = [
'started',
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Team extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'photo',
Expand All @@ -81,7 +81,7 @@ class Team extends Entity
/**
* Undocumented variable
*
* @var array<string>
* @var list<string>
*/
protected array $_virtual = [
'photo_url',
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class User extends Entity implements AuthorizationIdentity, AuthenticationIdenti
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = [
'password',
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ComputeScoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function regularize(
$points -= $rating->getBonusCleanSheetPoints($disposition->member);
}
$disposition->points = $points;
if ($cap && $disposition->member->id == $cap) {
if ($cap != null && $disposition->member->id == $cap) {
$disposition->consideration = 2;
$points *= 2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/DownloadRatingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private function downloadRatings(
?string $url = null
): ?string {
$url = $url ?? $this->getRatingsFile($matchdayGazzetta);
if (!empty($url)) {
if ($url != null && $url != "") {

Check failure on line 80 in src/Service/DownloadRatingsService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Right side of && is always true.
$content = $this->decryptMXMFile($matchday, $url);
if (!empty($content) && strlen($content) > 42000) {
if ($content != null && empty($content) == false && strlen($content) > 42000) {

Check failure on line 82 in src/Service/DownloadRatingsService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Right side of && is always true.

Check failure on line 82 in src/Service/DownloadRatingsService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

Variable $content in empty() always exists and is not falsy.
$this->writeCsvRatings($content, $path);
//self::writeXmlVoti($content, $percorsoXml);
return $path;
Expand Down
4 changes: 2 additions & 2 deletions src/Service/RatingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public function calculateKey(
*/
public function importRatings(Matchday $matchday, ?string $path = null): bool
{
$path = $path ? $path : $this->DownloadRatings->getRatings($matchday);
if ($path) {
$path = $path != null ? $path : $this->DownloadRatings->getRatings($matchday);
if ($path != null) {
$csvRow = $this->DownloadRatings->returnArray($path, ';');

/** @var \App\Model\Table\MembersTable $membersTable */
Expand Down
8 changes: 4 additions & 4 deletions src/Service/WebauthnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Webauthn\AttestationStatement\PackedAttestationStatementSupport;
use Webauthn\AttestationStatement\TPMAttestationStatementSupport;
use Webauthn\AuthenticationExtensions\AuthenticationExtension;
use Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
use Webauthn\AuthenticationExtensions\AuthenticationExtensions;
use Webauthn\AuthenticationExtensions\ExtensionOutputCheckerHandler;
use Webauthn\AuthenticatorAssertionResponse;
use Webauthn\AuthenticatorAssertionResponseValidator;
Expand Down Expand Up @@ -119,11 +119,11 @@ public function createUserEntity(User $user): PublicKeyCredentialUserEntity
/**
* Undocumented function
*
* @return \Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs
* @return \Webauthn\AuthenticationExtensions\AuthenticationExtensions
*/
private function getExtensions(): AuthenticationExtensionsClientInputs
private function getExtensions(): AuthenticationExtensions
{
$extensions = new AuthenticationExtensionsClientInputs([
$extensions = new AuthenticationExtensions([
new AuthenticationExtension('loc', true),
]);

Expand Down

0 comments on commit c986093

Please sign in to comment.