Skip to content
Merged
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
78 changes: 16 additions & 62 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,25 @@
->in(__DIR__.'/tests')
->name('*.php')
->notPath('Fixtures')
->notPath('Search/results')
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => ['statements' => ['declare', 'return']],
'cast_spaces' => ['space' => 'single'],
'header_comment' => ['header' => $header],
'include' => true,

'class_attributes_separation' => ['elements' => ['method' => 'one', 'trait_import' => 'none']],
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_namespace_whitespace' => true,
'no_trailing_comma_in_singleline' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
//'phpdoc_align' => true,
'phpdoc_indent' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
//'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'psr_autoloading' => true,
'blank_lines_before_namespace' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'unary_operator_spaces' => true,

// imports
'no_unused_imports' => true,
'fully_qualified_strict_types' => true,
'single_line_after_imports' => true,
//'global_namespace_import' => ['import_classes' => true],
'no_leading_import_slash' => true,
'single_import_per_statement' => true,

// PHP 7.2 migration
'array_syntax' => true,
'list_syntax' => true,
'regular_callable_call' => true,
'static_lambda' => true,
'nullable_type_declaration_for_default_null_value' => true,
'explicit_indirect_variable' => true,
'visibility_required' => ['elements' => ['property', 'method', 'const']],
'non_printable_character' => true,
'combine_nested_dirname' => true,
'random_api_migration' => true,
'ternary_to_null_coalescing' => true,
'phpdoc_to_param_type' => true,
'declare_strict_types' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],

// TODO php 7.4 migration (one day..)
'phpdoc_to_property_type' => true,
return $config
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@PHP84Migration' => true,
'@PHPUnit100Migration:risky' => true,
'@PER-CS' => true,
'@Symfony' => true,
'@Symfony:risky' => true,

// overrides
'blank_line_after_opening_tag' => false,
'linebreak_after_opening_tag' => false,
'yoda_style' => false,
'phpdoc_summary' => false,
'increment_style' => false,
])
->setUsingCache(true)
->setRiskyAllowed(true)
Expand Down
2 changes: 1 addition & 1 deletion src/ArgumentResolver/UserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
}

$username = $request->attributes->get($varName);
if (!is_string($username)) {
if (!\is_string($username)) {
throw new \UnexpectedValueException('Missing "'.$varName.'" in request attributes, cannot resolve $'.$argument->getName());
}

Expand Down
38 changes: 19 additions & 19 deletions src/Audit/AuditRecordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@

enum AuditRecordType: string
{
# package ownership
case AddMaintainer = 'add_maintainer'; # TODO
case RemoveMaintainer = 'remove_maintainer'; # TODO
case TransferPackage = 'transfer_package'; # TODO
// package ownership
case AddMaintainer = 'add_maintainer'; // TODO
case RemoveMaintainer = 'remove_maintainer'; // TODO
case TransferPackage = 'transfer_package'; // TODO

# package management
// package management
case PackageCreated = 'package_created';
case PackageDeleted = 'package_deleted';
case CanonicalUrlChange = 'canonical_url_change';
case VersionDeleted = 'version_deleted';
case VersionReferenceChange = 'version_reference_change';
case PackageAbandoned = 'package_abandoned'; # TODO
case PackageUnabandoned = 'package_unabandoned'; # TODO
case PackageAbandoned = 'package_abandoned'; // TODO
case PackageUnabandoned = 'package_unabandoned'; // TODO

# user management
case UserCreated = 'user_created'; # TODO
case UserDeleted = 'user_deleted'; # TODO
case PasswordResetRequest = 'password_reset_request'; # TODO
case PasswordReset = 'password_reset'; # TODO
case PasswordChange = 'password_change'; # TODO
case EmailChange = 'email_change'; # TODO
case UsernameChange = 'username_change'; # TODO
case GitHubLinkedWithUser = 'github_linked_with_user'; # TODO
case GitHubDisconnectedFromUser = 'github_disconnected_from_user'; # TODO
case TwoFaActivated = 'two_fa_activated'; # TODO
case TwoFaDeactivated = 'two_fa_deactivated'; # TODO
// user management
case UserCreated = 'user_created'; // TODO
case UserDeleted = 'user_deleted'; // TODO
case PasswordResetRequest = 'password_reset_request'; // TODO
case PasswordReset = 'password_reset'; // TODO
case PasswordChange = 'password_change'; // TODO
case EmailChange = 'email_change'; // TODO
case UsernameChange = 'username_change'; // TODO
case GitHubLinkedWithUser = 'github_linked_with_user'; // TODO
case GitHubDisconnectedFromUser = 'github_disconnected_from_user'; // TODO
case TwoFaActivated = 'two_fa_activated'; // TODO
case TwoFaDeactivated = 'two_fa_deactivated'; // TODO
}
14 changes: 7 additions & 7 deletions src/Command/CleanIndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace App\Command;

use Algolia\AlgoliaSearch\SearchClient;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Service\Locker;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanIndexCommand extends Command
{
Expand Down Expand Up @@ -74,11 +74,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$page = 0;
$perPage = 100;
do {
$results = $index->search('', ['facets' => "*,type,tags", 'facetFilters' => ['type:virtual-package'], 'numericFilters' => ['trendiness=100'], 'hitsPerPage' => $perPage, 'page' => $page]);
$results = $index->search('', ['facets' => '*,type,tags', 'facetFilters' => ['type:virtual-package'], 'numericFilters' => ['trendiness=100'], 'hitsPerPage' => $perPage, 'page' => $page]);
foreach ($results['hits'] as $result) {
if (0 !== strpos($result['objectID'], 'virtual:')) {
$duplicate = $index->search('', ['facets' => "*,objectID,type,tags", 'facetFilters' => ['objectID:virtual:'.$result['objectID']]]);
if (count($duplicate['hits']) === 1) {
if (!str_starts_with($result['objectID'], 'virtual:')) {
$duplicate = $index->search('', ['facets' => '*,objectID,type,tags', 'facetFilters' => ['objectID:virtual:'.$result['objectID']]]);
if (\count($duplicate['hits']) === 1) {
if ($verbose) {
$output->writeln('Deleting '.$result['objectID'].' which is a duplicate of '.$duplicate['hits'][0]['objectID']);
}
Expand All @@ -95,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
$page++;
} while (count($results['hits']) >= $perPage);
} while (\count($results['hits']) >= $perPage);

$this->locker->unlockCommand(__CLASS__);

Expand Down
2 changes: 1 addition & 1 deletion src/Command/CleanSpamPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace App\Command;

use App\Entity\Package;
use App\Entity\PackageFreezeReason;
use App\Entity\Version;
use App\Entity\VersionRepository;
use App\Model\PackageManager;
use App\Model\ProviderManager;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Package;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ClearVersionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace App\Command;

use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Package;
use App\Entity\Version;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Command/CompileStatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

namespace App\Command;

use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Entity\Download;
use App\Service\Locker;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Predis\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @author Jordi Boggiano <j.boggiano@seld.be>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DumpPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace App\Command;

use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Package;
use App\Package\SymlinkDumper;
use App\Service\Locker;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Seld\Signal\SignalHandler;
use Symfony\Component\Console\Command\Command;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DumpPackagesV2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace App\Command;

use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Package;
use App\Package\V2Dumper;
use App\Service\Locker;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Seld\Signal\SignalHandler;
use Symfony\Component\Console\Command\Command;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace App\Command;

use App\Entity\User;
use App\Util\DoctrineTrait;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\User;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down
25 changes: 13 additions & 12 deletions src/Command/IndexPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
use App\Entity\PackageFreezeReason;
use App\Model\DownloadManager;
use App\Model\FavoriteManager;
use App\Service\Locker;
use Composer\Pcre\Preg;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\Persistence\ManagerRegistry;
use Predis\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Persistence\ManagerRegistry;
use App\Service\Locker;
use Predis\Client;
use Symfony\Component\Console\Command\Command;

class IndexPackagesCommand extends Command
{
Expand Down Expand Up @@ -119,12 +119,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$index->clear();
}

$total = count($ids);
$total = \count($ids);
$current = 0;

// update package index
while ($ids) {
$indexTime = new \DateTime;
$indexTime = new \DateTime();
$idsSlice = array_splice($ids, 0, 50);
$packages = $this->getEM()->getRepository(Package::class)->findBy(['id' => $idsSlice]);

Expand All @@ -134,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($packages as $package) {
$current++;
if ($verbose) {
$output->writeln('['.sprintf('%'.strlen((string) $total).'d', $current).'/'.$total.'] Indexing '.$package->getName());
$output->writeln('['.\sprintf('%'.\strlen((string) $total).'d', $current).'/'.$total.'] Indexing '.$package->getName());
}

// delete spam packages from the search index
Expand Down Expand Up @@ -168,7 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$index->saveObjects($records);
} catch (\Exception $e) {
$output->writeln('<error>'.get_class($e).': '.$e->getMessage().', occurred while processing packages: '.implode(',', $idsSlice).'</error>');
$output->writeln('<error>'.$e::class.': '.$e->getMessage().', occurred while processing packages: '.implode(',', $idsSlice).'</error>');
continue;
}

Expand All @@ -192,7 +192,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param string[] $tags
* @return array<string, int|string|float|null|array<string, string|int>>
*
* @return array<string, int|string|float|array<string, string|int>|null>
*/
private function packageToSearchableArray(Package $package, array $tags): array
{
Expand All @@ -213,9 +214,9 @@ private function packageToSearchableArray(Package $package, array $tags): array
'type' => $package->getType(),
'repository' => $package->getRepository(),
'language' => $package->getLanguage(),
# log10 of downloads over the last 7days
// log10 of downloads over the last 7days
'trendiness' => $trendiness > 0 ? log($trendiness, 10) : 0,
# log10 of downloads + gh stars
// log10 of downloads + gh stars
'popularity' => $popularity,
'meta' => [
'downloads' => $downloads['total'],
Expand All @@ -233,7 +234,7 @@ private function packageToSearchableArray(Package $package, array $tags): array
$record['replacementPackage'] = '';
}

if (in_array($package->getType(), ['php-ext', 'php-ext-zend'], true)) {
if (\in_array($package->getType(), ['php-ext', 'php-ext-zend'], true)) {
$record['extension'] = 1;
}

Expand Down
Loading