mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[CS][DX] Refactor (#18652)
This PR has been generated automatically. For more details see [refactor.yaml](/Sylius/Sylius/blob/2.1/.github/workflows/refactor.yaml).
This commit is contained in:
commit
ac880f5f41
22 changed files with 40 additions and 23 deletions
|
|
@ -79,6 +79,7 @@ final class BusinessDataCollector implements TelemetryDataCollectorInterface
|
|||
|
||||
/**
|
||||
* @param array<string, mixed> $normalized
|
||||
*
|
||||
* @return array{0: array<string, mixed>, 1: array<string, mixed>}
|
||||
*/
|
||||
private function separateMetrics(array $normalized): array
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ final class OrdersBusinessDataProvider implements DataProviderInterface
|
|||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $results
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function processResults(array $results): array
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ final class DatabasePlatformDataProvider implements DataProviderInterface
|
|||
],
|
||||
'oracle' => [
|
||||
"SELECT BANNER FROM v\$version WHERE BANNER LIKE 'Oracle%'",
|
||||
"SELECT version FROM v\$instance",
|
||||
'SELECT version FROM v$instance',
|
||||
"SELECT * FROM PRODUCT_COMPONENT_VERSION WHERE PRODUCT LIKE 'Oracle%'",
|
||||
],
|
||||
default => [
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final class EnvironmentDataProvider implements DataProviderInterface
|
|||
return new EnvironmentData(
|
||||
app: $this->appEnvironment,
|
||||
webserver: $this->getWebServerSoftware(),
|
||||
os: PHP_OS_FAMILY,
|
||||
os: \PHP_OS_FAMILY,
|
||||
docker: $this->isRunningInDocker(),
|
||||
ramGb: $this->getSystemMemoryInGb(),
|
||||
phpMemoryLimit: ini_get('memory_limit') ?: null,
|
||||
|
|
@ -42,7 +42,7 @@ final class EnvironmentDataProvider implements DataProviderInterface
|
|||
return $_SERVER['SERVER_SOFTWARE'];
|
||||
}
|
||||
|
||||
return PHP_SAPI;
|
||||
return \PHP_SAPI;
|
||||
}
|
||||
|
||||
private function isRunningInDocker(): bool
|
||||
|
|
@ -52,7 +52,7 @@ final class EnvironmentDataProvider implements DataProviderInterface
|
|||
|
||||
private function getSystemMemoryInGb(): ?float
|
||||
{
|
||||
return match (PHP_OS_FAMILY) {
|
||||
return match (\PHP_OS_FAMILY) {
|
||||
'Linux' => $this->getLinuxMemory(),
|
||||
'Darwin' => $this->getMacOsMemory(),
|
||||
'Windows' => $this->getWindowsMemory(),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ final class VersionDataProvider implements DataProviderInterface
|
|||
{
|
||||
return new VersionData(
|
||||
syliusVersion: SyliusCoreBundle::VERSION,
|
||||
phpVersion: PHP_VERSION,
|
||||
phpVersion: \PHP_VERSION,
|
||||
symfonyVersion: Kernel::VERSION,
|
||||
doctrineVersion: $this->getInstalledPackageVersion('doctrine/orm'),
|
||||
twigVersion: Environment::VERSION,
|
||||
|
|
|
|||
|
|
@ -45,10 +45,8 @@ final class TelemetrySender implements TelemetrySenderInterface
|
|||
|
||||
return $statusCode === 200;
|
||||
} catch (TransportExceptionInterface $exception) {
|
||||
|
||||
return false;
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
|||
final class TelemetryCacheTest extends TestCase
|
||||
{
|
||||
private ArrayAdapter $cache;
|
||||
|
||||
private TelemetryCache $telemetryCache;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|||
final class TelemetryListenerTest extends TestCase
|
||||
{
|
||||
private TelemetrySendManagerInterface $telemetrySendManager;
|
||||
|
||||
private TelemetryListener $listener;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ final class ValueRangeMapperTest extends TestCase
|
|||
/**
|
||||
* @dataProvider gmvDataProvider
|
||||
*/
|
||||
public function test_it_maps_gmv_to_correct_range(int|float $value, string $expectedRange): void
|
||||
public function test_it_maps_gmv_to_correct_range(float|int $value, string $expectedRange): void
|
||||
{
|
||||
self::assertSame($expectedRange, ValueRangeMapper::mapGmv($value));
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ final class ValueRangeMapperTest extends TestCase
|
|||
/**
|
||||
* @dataProvider aovDataProvider
|
||||
*/
|
||||
public function test_it_maps_aov_to_correct_range(int|float $value, string $expectedRange): void
|
||||
public function test_it_maps_aov_to_correct_range(float|int $value, string $expectedRange): void
|
||||
{
|
||||
self::assertSame($expectedRange, ValueRangeMapper::mapAov($value));
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ final class ValueRangeMapperTest extends TestCase
|
|||
/**
|
||||
* @dataProvider avgItemsDataProvider
|
||||
*/
|
||||
public function test_it_maps_avg_items_to_correct_range(int|float $value, string $expectedRange): void
|
||||
public function test_it_maps_avg_items_to_correct_range(float|int $value, string $expectedRange): void
|
||||
{
|
||||
self::assertSame($expectedRange, ValueRangeMapper::mapAvgItems($value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Business\CurrenciesDataProvider;
|
|||
final class CurrenciesDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private CurrenciesDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ final class LocalesDataProviderTest extends TestCase
|
|||
private const DEFAULT_LOCALE = 'en_US';
|
||||
|
||||
private Connection $connection;
|
||||
|
||||
private LocalesDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Business\MetricsCountsDataProvid
|
|||
final class MetricsCountsDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private MetricsCountsDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Business\OrdersBusinessDataProvi
|
|||
final class OrdersBusinessDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private OrdersBusinessDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Business\PaymentMethodsDataProvi
|
|||
final class PaymentMethodsDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private PaymentMethodsDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Business\ShippingMethodsDataProv
|
|||
final class ShippingMethodsDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private ShippingMethodsDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ use Sylius\Bundle\CoreBundle\Telemetry\Provider\Technical\DatabasePlatformDataPr
|
|||
final class DatabasePlatformDataProviderTest extends TestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private ManagerRegistry $managerRegistry;
|
||||
|
||||
private DatabasePlatformDataProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ final class EnvironmentDataProviderTest extends TestCase
|
|||
$data = $this->provider->provide();
|
||||
|
||||
self::assertInstanceOf(EnvironmentData::class, $data);
|
||||
self::assertSame(PHP_OS_FAMILY, $data->os);
|
||||
self::assertSame(\PHP_OS_FAMILY, $data->os);
|
||||
}
|
||||
|
||||
public function test_it_returns_boolean_for_docker(): void
|
||||
|
|
|
|||
|
|
@ -41,6 +41,6 @@ final class VersionDataProviderTest extends TestCase
|
|||
$data = $this->provider->provide();
|
||||
|
||||
self::assertInstanceOf(VersionData::class, $data);
|
||||
self::assertSame(PHP_VERSION, $data->phpVersion);
|
||||
self::assertSame(\PHP_VERSION, $data->phpVersion);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ final class TelemetrySenderTest extends TestCase
|
|||
'POST',
|
||||
'http://localhost:8000/telemetry',
|
||||
$this->callback(function ($options) {
|
||||
return isset($options['json'])
|
||||
&& isset($options['timeout'])
|
||||
&& $options['timeout'] === 5
|
||||
&& isset($options['headers']['Content-Type'])
|
||||
&& $options['headers']['Content-Type'] === 'application/json'
|
||||
&& isset($options['headers']['User-Agent'])
|
||||
&& $options['headers']['User-Agent'] === 'Sylius-Prism/1.0';
|
||||
return isset($options['json']) &&
|
||||
isset($options['timeout']) &&
|
||||
$options['timeout'] === 5 &&
|
||||
isset($options['headers']['Content-Type']) &&
|
||||
$options['headers']['Content-Type'] === 'application/json' &&
|
||||
isset($options['headers']['User-Agent']) &&
|
||||
$options['headers']['User-Agent'] === 'Sylius-Prism/1.0';
|
||||
}),
|
||||
)
|
||||
->willReturn($response);
|
||||
|
|
|
|||
|
|
@ -19,11 +19,17 @@ use Psr\Cache\CacheItemPoolInterface;
|
|||
final class TelemetryCache implements TelemetryCacheInterface
|
||||
{
|
||||
private const CACHE_KEY = 'sylius_telemetry';
|
||||
|
||||
private const CACHE_TTL_SUCCESS = 604800; // 7 days
|
||||
|
||||
private const CACHE_TTL_FAILURE = 259200; // 3 days
|
||||
|
||||
private const RETRY_DELAY = 86400; // 24 hours between retries
|
||||
|
||||
private const MAX_ATTEMPTS = 3;
|
||||
|
||||
private const STATUS_SUCCESS = 'success';
|
||||
|
||||
private const STATUS_FAILED = 'failed';
|
||||
|
||||
public function __construct(
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ final class ValueRangeMapper
|
|||
\PHP_INT_MAX => '20+',
|
||||
];
|
||||
|
||||
public static function mapGmv(int|float $value): string
|
||||
public static function mapGmv(float|int $value): string
|
||||
{
|
||||
return self::mapToRange($value, self::GMV_RANGES);
|
||||
}
|
||||
|
||||
public static function mapAov(int|float $value): string
|
||||
public static function mapAov(float|int $value): string
|
||||
{
|
||||
return self::mapToRange($value, self::AOV_RANGES);
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ final class ValueRangeMapper
|
|||
return self::mapToRange($value, self::CUSTOMER_ORDER_PAYMENT_SHIPMENT_RANGES);
|
||||
}
|
||||
|
||||
public static function mapAvgItems(int|float $value): string
|
||||
public static function mapAvgItems(float|int $value): string
|
||||
{
|
||||
return self::mapToRange($value, self::AVG_ITEMS_RANGES);
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ final class ValueRangeMapper
|
|||
}
|
||||
|
||||
/** @param array<int, string> $ranges */
|
||||
private static function mapToRange(int|float $value, array $ranges): string
|
||||
private static function mapToRange(float|int $value, array $ranges): string
|
||||
{
|
||||
foreach ($ranges as $threshold => $label) {
|
||||
if ($value < $threshold) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ interface TelemetrySenderInterface
|
|||
{
|
||||
/**
|
||||
* @param array<string, mixed> $telemetryData
|
||||
*
|
||||
* @return bool True if sent successfully, false otherwise
|
||||
*/
|
||||
public function send(array $telemetryData): bool;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue