Skip to content

Refactored Code with Typed Properties and Constructor Promotion via Rector #65

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

Open
wants to merge 3 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
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ parameters:
identifier: argument.type
count: 1
path: src/lib/Storage/Metrics/DraftsCountMetrics.php

-
message: '#^Parameter \#1 \$items of class Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Registry\\IdentifierBased constructor expects array\<Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector\>, array\<Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector\|PHPUnit\\Framework\\MockObject\\MockObject\> given\.$#'
identifier: argument.type
count: 3
path: tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php
14 changes: 14 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@
declare(strict_types=1);

use Ibexa\Contracts\Rector\Sets\IbexaSetList;
use Ibexa\Rector\Rule\ReplaceInterfaceRector;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([
SetList::TYPE_DECLARATION,
IbexaSetList::IBEXA_50->value,
SymfonySetList::SYMFONY_60,
SymfonySetList::SYMFONY_61,
SymfonySetList::SYMFONY_62,
SymfonySetList::SYMFONY_63,
SymfonySetList::SYMFONY_64,
])
->withRules([
TypedPropertyFromAssignsRector::class,
ReplaceInterfaceRector::class,
TypedPropertyFromStrictSetUpRector::class,
TypedPropertyFromCreateMockAssignRector::class,
ClassPropertyAssignToConstructorPromotionRector::class,
]);
19 changes: 4 additions & 15 deletions src/bundle/Command/SystemInfoDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@
)]
final class SystemInfoDumpCommand extends Command
{
private SystemInfoCollectorRegistry $systemInfoCollectorRegistry;

private OutputFormatRegistry $outputFormatRegistry;

public function __construct(SystemInfoCollectorRegistry $systemInfoCollectorRegistry, OutputFormatRegistry $outputFormatRegistry)
{
$this->systemInfoCollectorRegistry = $systemInfoCollectorRegistry;
$this->outputFormatRegistry = $outputFormatRegistry;

public function __construct(
private readonly SystemInfoCollectorRegistry $systemInfoCollectorRegistry,
private readonly OutputFormatRegistry $outputFormatRegistry
) {
parent::__construct();
}

Expand Down Expand Up @@ -65,12 +60,6 @@ protected function configure(): void
;
}

/**
* Execute the Command.
*
* @param $input InputInterface
* @param $output OutputInterface
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('list-info-collectors')) {
Expand Down
15 changes: 3 additions & 12 deletions src/bundle/Controller/SystemInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@

class SystemInfoController extends AdminUiController
{
/** @var \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry */
protected $collectorRegistry;

/**
* @param \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry $collectorRegistry
*/
public function __construct(SystemInfoCollectorRegistry $collectorRegistry)
{
$this->collectorRegistry = $collectorRegistry;
public function __construct(
private readonly SystemInfoCollectorRegistry $collectorRegistry
) {
}

public function performAccessCheck(): void
Expand All @@ -49,9 +43,6 @@ public function viewInfoAction(SystemInfoView $view): SystemInfoView
return $view;
}

/**
* Renders a PHP info page.
*/
public function phpinfoAction(): Response
{
ob_start();
Expand Down
9 changes: 3 additions & 6 deletions src/bundle/DependencyInjection/IbexaSystemInfoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

class IbexaSystemInfoExtension extends Extension implements PrependExtensionInterface
{
public const EXTENSION_NAME = 'ibexa_system_info';
public const METRICS_TAG = 'ibexa.system_info.metrics';
public const SERVICE_TAG = 'ibexa.system_info.service';
public const string EXTENSION_NAME = 'ibexa_system_info';
public const string METRICS_TAG = 'ibexa.system_info.metrics';
public const string SERVICE_TAG = 'ibexa.system_info.service';

public function getAlias(): string
{
Expand All @@ -34,9 +34,6 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co
return new Configuration();
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\YamlFileLoader(
Expand Down
10 changes: 2 additions & 8 deletions src/bundle/EventSubscriber/AddXPoweredByHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
/**
* Sets X-Powered-By header to promote use of Platform.
*/
class AddXPoweredByHeader implements EventSubscriberInterface
readonly class AddXPoweredByHeader implements EventSubscriberInterface
{
/**
* @var string If empty, this powered by header is skipped.
*/
private $installationName;

public function __construct(string $installationName)
public function __construct(private string $installationName)
{
$this->installationName = $installationName;
}

public static function getSubscribedEvents(): array
Expand Down
6 changes: 3 additions & 3 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ services:
lazy: true
autowire: true
arguments:
$db: '@ibexa.persistence.connection'
$connection: '@ibexa.persistence.connection'
tags:
- { name: ibexa.system_info.collector, identifier: repository }

Expand Down Expand Up @@ -108,7 +108,7 @@ services:

Ibexa\SystemInfo\Storage\AggregateMetricsProvider:
arguments:
$metrics: !tagged_locator
$metricsLocator: !tagged_locator
tag: !php/const \Ibexa\Bundle\SystemInfo\DependencyInjection\IbexaSystemInfoExtension::METRICS_TAG
index_by: identifier

Expand Down Expand Up @@ -158,7 +158,7 @@ services:

Ibexa\SystemInfo\Service\AggregateServiceProvider:
arguments:
$service: !tagged_locator
$serviceLocator: !tagged_locator
tag: !php/const \Ibexa\Bundle\SystemInfo\DependencyInjection\IbexaSystemInfoExtension::SERVICE_TAG
index_by: identifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,15 @@
*/
class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector
{
/**
* Symfony kernel.
*
* @var \Symfony\Component\HttpKernel\Kernel
*/
private $kernel;

/**
* Installed bundles.
*
* A hash containing the active bundles, where the key is the bundle name, and the value is the corresponding namespace.
*
* Example:
* array (
* 'AppBundle' => 'AppBundle\\AppBundle',
* 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle',
* )
*
* @var array<string, class-string>
*/
private $bundles;

/**
* @param array<string, class-string> $bundles
*/
public function __construct(Kernel $kernel, array $bundles)
{
$this->kernel = $kernel;
$this->bundles = $bundles;
public function __construct(
private readonly Kernel $kernel,
private array $bundles = []
) {
}

/**
* Collects information about the Symfony kernel.
*
* @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SymfonyKernelSystemInfo
*/
public function collect(): SymfonyKernelSystemInfo
{
ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING);
Expand Down
12 changes: 2 additions & 10 deletions src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@
/**
* Collects hardware system information using zetacomponents/sysinfo.
*/
class EzcHardwareSystemInfoCollector implements SystemInfoCollector
readonly class EzcHardwareSystemInfoCollector implements SystemInfoCollector
{
/**
* @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper
*/
private $ezcSystemInfo;

public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
public function __construct(private EzcSystemInfoWrapper $ezcSystemInfo)
{
$this->ezcSystemInfo = $ezcSystemInfo;
}

/**
* Collects information about the hardware Ibexa DXP is installed on.
* - cpu information
* - memory size.
*
* @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\HardwareSystemInfo
*/
public function collect(): HardwareSystemInfo
{
Expand Down
10 changes: 2 additions & 8 deletions src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
/**
* Collects PHP information using zetacomponents/sysinfo.
*/
class EzcPhpSystemInfoCollector implements SystemInfoCollector
readonly class EzcPhpSystemInfoCollector implements SystemInfoCollector
{
/**
* @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper
*/
private $ezcSystemInfo;

public function __construct(EzcSystemInfoWrapper $ezcSystemInfo)
public function __construct(private EzcSystemInfoWrapper $ezcSystemInfo)
{
$this->ezcSystemInfo = $ezcSystemInfo;
}

/**
Expand Down
50 changes: 12 additions & 38 deletions src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
*
* Mainly for usage for trial to calculate TTL expiry.
*/
public const RELEASES = [
public const array RELEASES = [
'2.5' => '2019-03-29T16:59:59+00:00',
'3.0' => '2020-04-02T23:59:59+00:00',
'3.1' => '2020-07-15T23:59:59+00:00',
Expand All @@ -58,7 +58,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
*
* @see: https://support.ibexa.co/Public/Service-Life
*/
public const EOM = [
public const array EOM = [
'2.5' => '2022-03-29T23:59:59+00:00',
'3.0' => '2020-07-10T23:59:59+00:00',
'3.1' => '2020-11-30T23:59:59+00:00',
Expand All @@ -77,7 +77,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
*
* @see: https://support.ibexa.co/Public/Service-Life
*/
public const EOL = [
public const array EOL = [
'2.5' => '2024-03-29T23:59:59+00:00',
'3.0' => '2020-08-31T23:59:59+00:00',
'3.1' => '2021-01-30T23:59:59+00:00',
Expand All @@ -92,62 +92,39 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
/**
* Vendors we watch for stability (and potentially more).
*/
public const PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//';
public const string PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//';

/**
* Packages that identify installation as "Headless".
*/
public const HEADLESS_PACKAGES = [
public const array HEADLESS_PACKAGES = [
'ibexa/headless',
];

public const EXPERIENCE_PACKAGES = [
public const array EXPERIENCE_PACKAGES = [
'ibexa/experience',
];

/**
* Packages that identify installation as "Commerce".
*/
public const COMMERCE_PACKAGES = [
public const array COMMERCE_PACKAGES = [
'ibexa/commerce',
];

/**
* @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector
*/
private $systemInfoCollector;
private ?ComposerSystemInfo $composerInfo = null;

/**
* @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo|null
*/
private $composerInfo;

/** @var string */
private $kernelProjectDir;

/**
* @param \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector $composerCollector
*/
public function __construct(
SystemInfoCollector $composerCollector,
string $kernelProjectDir,
private readonly SystemInfoCollector $composerCollector,
private readonly string $kernelProjectDir
) {
$this->systemInfoCollector = $composerCollector;
$this->kernelProjectDir = $kernelProjectDir;
}

/**
* Collects information about the Ibexa distribution and version.
*
* @throws \Exception
*
* @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo
*/
public function collect(): IbexaSystemInfo
{
if ($this->composerInfo === null) {
try {
$composerInfo = $this->systemInfoCollector->collect();
$composerInfo = $this->composerCollector->collect();
if ($composerInfo instanceof ComposerSystemInfo) {
$this->composerInfo = $composerInfo;
}
Expand All @@ -168,9 +145,6 @@ public function collect(): IbexaSystemInfo
return $ibexa;
}

/**
* @throws \Exception
*/
private function setReleaseInfo(IbexaSystemInfo $ibexa): void
{
$ibexa->release = Ibexa::VERSION;
Expand Down Expand Up @@ -247,7 +221,7 @@ private static function getStability(ComposerSystemInfo $composerInfo): string
}

/**
* @param list<string> $packageNames
* @param string[] $packageNames
*/
private static function hasAnyPackage(
ComposerSystemInfo $composerInfo,
Expand Down
Loading
Loading