Skip to content

Commit

Permalink
chore(php8): rector common-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei committed Dec 1, 2022
1 parent c878375 commit 0e5d4df
Show file tree
Hide file tree
Showing 108 changed files with 269 additions and 694 deletions.
10 changes: 4 additions & 6 deletions EMS/common-bundle/src/Command/Admin/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@

class CreateCommand extends AbstractCommand
{
public const CONFIG_TYPE = 'config-type';
public const JSON_PATH = 'json-path';
public const FOLDER = 'folder';
final public const CONFIG_TYPE = 'config-type';
final public const JSON_PATH = 'json-path';
final public const FOLDER = 'folder';
private string $configType;
private string $jsonPath;
private AdminHelper $adminHelper;
private string $folder;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.ConfigHelper::DEFAULT_FOLDER;
}

Expand Down
8 changes: 3 additions & 5 deletions EMS/common-bundle/src/Command/Admin/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@

class DeleteCommand extends AbstractCommand
{
public const CONFIG_TYPE = 'config-type';
public const ENTITY_NAME = 'entity-name';
final public const CONFIG_TYPE = 'config-type';
final public const ENTITY_NAME = 'entity-name';
private string $configType;
private string $entityName;
private AdminHelper $adminHelper;

public function __construct(AdminHelper $adminHelper)
public function __construct(private readonly AdminHelper $adminHelper)
{
parent::__construct();
$this->adminHelper = $adminHelper;
}

public function initialize(InputInterface $input, OutputInterface $output): void
Expand Down
10 changes: 4 additions & 6 deletions EMS/common-bundle/src/Command/Admin/GetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

class GetCommand extends AbstractCommand
{
public const CONFIG_TYPE = 'config-type';
public const EXPORT = 'export';
public const FOLDER = 'folder';
private AdminHelper $adminHelper;
final public const CONFIG_TYPE = 'config-type';
final public const EXPORT = 'export';
final public const FOLDER = 'folder';
private string $configType;
private bool $export;
private string $folder;
private CoreApiInterface $coreApi;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.ConfigHelper::DEFAULT_FOLDER;
}

Expand Down
8 changes: 3 additions & 5 deletions EMS/common-bundle/src/Command/Admin/JobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

class JobCommand extends AbstractCommand
{
public const JOB_ID = 'job-id';
private AdminHelper $adminHelper;
final public const JOB_ID = 'job-id';
private CoreApiInterface $coreApi;
private string $jobIdOrJsonFile;
private string $folder;
private readonly string $folder;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.ConfigHelper::DEFAULT_FOLDER;
}

Expand Down
6 changes: 1 addition & 5 deletions EMS/common-bundle/src/Command/Admin/LoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ class LoginCommand extends AbstractCommand
private const ARG_BASE_URL = 'base-url';
private const OPTION_USERNAME = 'username';
private const OPTION_PASSWORD = 'password';
private AdminHelper $adminHelper;
private ?string $backendUrl;

public function __construct(AdminHelper $adminHelper, ?string $backendUrl)
public function __construct(private readonly AdminHelper $adminHelper, private ?string $backendUrl)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->backendUrl = $backendUrl;
}

protected function configure(): void
Expand Down
12 changes: 5 additions & 7 deletions EMS/common-bundle/src/Command/Admin/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@

class UpdateCommand extends AbstractCommand
{
public const CONFIG_TYPE = 'config-type';
public const ENTITY_NAME = 'entity-name';
public const JSON_PATH = 'json-path';
public const FOLDER = 'folder';
final public const CONFIG_TYPE = 'config-type';
final public const ENTITY_NAME = 'entity-name';
final public const JSON_PATH = 'json-path';
final public const FOLDER = 'folder';
private string $configType;
private string $entityName;
private ?string $jsonPath = null;
private AdminHelper $adminHelper;
private string $folder;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.ConfigHelper::DEFAULT_FOLDER;
}

Expand Down
4 changes: 1 addition & 3 deletions EMS/common-bundle/src/Command/ClearLogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
class ClearLogsCommand extends AbstractCommand
{
protected static $defaultName = Commands::CLEAR_LOGS;
private LogRepository $logRepository;
private \DateTime $before;
/** @var string[] */
private array $channels = [];

private const OPTION_BEFORE = 'before';
private const OPTION_CHANNEL = 'channel';

public function __construct(LogRepository $logRepository)
public function __construct(private readonly LogRepository $logRepository)
{
parent::__construct();
$this->logRepository = $logRepository;
}

protected function configure(): void
Expand Down
28 changes: 9 additions & 19 deletions EMS/common-bundle/src/Command/CurlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,23 @@

class CurlCommand extends AbstractCommand
{
public const ARGUMENT_URL = 'url';
public const ARGUMENT_FILENAME = 'filename';
public const OPTION_METHOD = 'method';
public const OPTION_BASE_URL = 'base-url';
public const OPTION_SAVE = 'save';
final public const ARGUMENT_URL = 'url';
final public const ARGUMENT_FILENAME = 'filename';
final public const OPTION_METHOD = 'method';
final public const OPTION_BASE_URL = 'base-url';
final public const OPTION_SAVE = 'save';
protected static $defaultName = Commands::CURL;
private EventDispatcherInterface $eventDispatcher;
private ControllerResolverInterface $controllerResolver;
private AssetRuntime $assetRuntime;
private ?SessionInterface $session = null;
private RequestStack $requestStack;
private StorageManager $storageManager;

private string $url;
private string $method;
private string $filename;
private ?string $baseUrl = null;
private bool $save;

public function __construct(EventDispatcherInterface $eventDispatcher, ControllerResolverInterface $controllerResolver, RequestStack $requestStack, StorageManager $storageManager, AssetRuntime $assetRuntime)
public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly ControllerResolverInterface $controllerResolver, private readonly RequestStack $requestStack, private readonly StorageManager $storageManager, private readonly AssetRuntime $assetRuntime)
{
parent::__construct();
$this->eventDispatcher = $eventDispatcher;
$this->controllerResolver = $controllerResolver;
$this->requestStack = $requestStack;
$this->storageManager = $storageManager;
$this->assetRuntime = $assetRuntime;
}

protected function configure(): void
Expand Down Expand Up @@ -81,20 +71,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->io->writeln(\sprintf('The file %s has been generated', $this->filename));

if (!$this->save && null === $this->baseUrl) {
return parent::EXECUTE_SUCCESS;
return self::EXECUTE_SUCCESS;
}

$hash = $this->storageManager->saveFile($this->filename, StorageInterface::STORAGE_USAGE_ASSET);
$this->io->writeln(\sprintf('The file has been saved with the id %s', $hash));

if (null === $this->baseUrl) {
return parent::EXECUTE_SUCCESS;
return self::EXECUTE_SUCCESS;
}

$url = $this->getUrl($hash);
$this->io->writeln(\sprintf('The file is available at %s', $url));

return parent::EXECUTE_SUCCESS;
return self::EXECUTE_SUCCESS;
}

protected function performRequest(): void
Expand Down
4 changes: 1 addition & 3 deletions EMS/common-bundle/src/Command/Document/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ class DownloadCommand extends AbstractCommand
private const CONTENT_TYPE = 'content-type';
private const FOLDER = 'folder';
private const DEFAULT_FOLDER = 'document';
private AdminHelper $adminHelper;
private string $contentType;
private string $folder;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.self::DEFAULT_FOLDER;
}

Expand Down
4 changes: 1 addition & 3 deletions EMS/common-bundle/src/Command/Document/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ class UpdateCommand extends AbstractCommand
private const CONTENT_TYPE = 'content-type';
private const FOLDER = 'folder';
private const DEFAULT_FOLDER = 'document';
private AdminHelper $adminHelper;
private string $contentType;
private string $folder;

public function __construct(AdminHelper $adminHelper, string $projectFolder)
public function __construct(private readonly AdminHelper $adminHelper, string $projectFolder)
{
parent::__construct();
$this->adminHelper = $adminHelper;
$this->folder = $projectFolder.DIRECTORY_SEPARATOR.self::DEFAULT_FOLDER;
}

Expand Down
5 changes: 1 addition & 4 deletions EMS/common-bundle/src/Command/MetricCollectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@

final class MetricCollectCommand extends AbstractCommand
{
private MetricCollector $metricCollector;

private const OPTION_CLEAR = 'clear';

public function __construct(MetricCollector $metricCollector)
public function __construct(private readonly MetricCollector $metricCollector)
{
parent::__construct();
$this->metricCollector = $metricCollector;
}

protected function configure(): void
Expand Down
7 changes: 1 addition & 6 deletions EMS/common-bundle/src/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ class StatusCommand extends AbstractCommand
private const OPTION_SILENT = 'silent';
private const OPTION_WAIT_FOR_STATUS = 'wait-for-status';

private ElasticaService $elasticaService;
private StorageManager $storageManager;

public function __construct(ElasticaService $elasticaService, StorageManager $storageManager)
public function __construct(private readonly ElasticaService $elasticaService, private readonly StorageManager $storageManager)
{
parent::__construct();
$this->elasticaService = $elasticaService;
$this->storageManager = $storageManager;
}

protected function configure(): void
Expand Down
6 changes: 3 additions & 3 deletions EMS/common-bundle/src/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Commands
{
public const CURL = 'ems:curl';
public const STATUS = 'ems:status';
public const CLEAR_LOGS = 'ems:logs:clear';
final public const CURL = 'ems:curl';
final public const STATUS = 'ems:status';
final public const CLEAR_LOGS = 'ems:logs:clear';
}
13 changes: 2 additions & 11 deletions EMS/common-bundle/src/Common/Admin/AdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@

class AdminHelper
{
private CoreApiFactoryInterface $coreApiFactory;
private CacheItemPoolInterface $cache;
private LoggerInterface $logger;
private ?CoreApiInterface $coreApi = null;

public function __construct(
CoreApiFactoryInterface $coreApiFactory,
CacheItemPoolInterface $cache,
LoggerInterface $logger
) {
$this->coreApiFactory = $coreApiFactory;
$this->cache = $cache;
$this->logger = $logger;
public function __construct(private readonly CoreApiFactoryInterface $coreApiFactory, private readonly CacheItemPoolInterface $cache, private readonly LoggerInterface $logger)
{
}

public function login(string $baseUrl, string $username, string $password): CoreApiInterface
Expand Down
6 changes: 2 additions & 4 deletions EMS/common-bundle/src/Common/Admin/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
final class ConfigHelper
{
public const DEFAULT_FOLDER = 'admin';
private string $directory;
private ConfigInterface $config;
private readonly string $directory;

public function __construct(ConfigInterface $config, string $saveFolder)
public function __construct(private readonly ConfigInterface $config, string $saveFolder)
{
$this->config = $config;
$this->directory = \implode(DIRECTORY_SEPARATOR, [$saveFolder, $this->config->getType()]);
if (!\is_dir($this->directory)) {
\mkdir($this->directory, 0777, true);
Expand Down
6 changes: 2 additions & 4 deletions EMS/common-bundle/src/Common/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

final class Cache
{
private Config $config;
private string $cacheDir;
private readonly Config $config;

private ?\Redis $redis = null;
private ?AdapterInterface $adapter = null;
Expand All @@ -31,10 +30,9 @@ final class Cache
/**
* @param array<mixed> $config
*/
public function __construct(array $config, string $cacheDir)
public function __construct(array $config, private readonly string $cacheDir)
{
$this->config = new Config($config);
$this->cacheDir = $cacheDir;
}

public function isApc(): bool
Expand Down
4 changes: 1 addition & 3 deletions EMS/common-bundle/src/Common/Composer/ComposerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

final class ComposerInfo
{
private string $projectDir;
/** @var array<string, string> */
private array $versionPackages = [];

Expand All @@ -21,9 +20,8 @@ final class ComposerInfo
'symfony/framework-bundle' => 'symfony',
];

public function __construct(string $rootDir)
public function __construct(private readonly string $projectDir)
{
$this->projectDir = $rootDir;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions EMS/common-bundle/src/Common/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static function toAscii(string $str): string
$clean = Converter::convertSpecialChars($str);
try {
$clean = \iconv('UTF-8', 'ASCII//TRANSLIT', $clean);
} catch (\Exception $e) {
} catch (\Exception) {
$clean = false;
}

Expand Down Expand Up @@ -37,10 +37,7 @@ public static function formatBytes(int $bytes, int $precision = 2): string
return \round($bytes, $precision).' '.$units[$pow];
}

/**
* @param mixed $var
*/
public static function stringify($var, string $defaultValue = ''): string
public static function stringify(mixed $var, string $defaultValue = ''): string
{
if (!\is_array($var) && !\is_object($var)) {
return \strval($var);
Expand All @@ -50,7 +47,7 @@ public static function stringify($var, string $defaultValue = ''): string
}
try {
return \json_encode($var, JSON_THROW_ON_ERROR);
} catch (\Throwable $e) {
} catch (\Throwable) {
return $defaultValue;
}
}
Expand Down
Loading

0 comments on commit 0e5d4df

Please sign in to comment.