Skip to content
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
59 changes: 24 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,57 @@ on: [push]
jobs:
cs:
name: Code Style
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Run php-cs-fixture
- name: Run php-cs-fixer
env:
PHP_CS_FIXER_FUTURE_MODE: 1
run: bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --no-interaction --diff

phpunit:
name: Unit Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
env:
COMPOSER_MEMORY_LIMIT: "-1"
strategy:
matrix:
include:
# oldest supported versions
- php: 7.2
composer_flags: "--prefer-lowest"
cs_fixer_config: "1.3.*"
symfony_phpunit_remove_return_typehint: 1
- php: 7.3
symfony_version: "4.4.*"
- php: 7.4
symfony_version: "5.1.*"
- php: 7.4
symfony_version: 5.2.*
# most recent versions
- php: 8.0
symfony_version: 5.3.*
- php: 8.0
symfony_version: 5.4.*
- php: 8.0
symfony_version: 6.0.*
- php: 8.1
symfony_version: "6.4.*"
- php: 8.2
symfony_version: "6.4.*"
- php: 8.2
symfony_version: "7.0.*"
- php: 8.2
symfony_version: "7.1.*"
- php: 8.3
symfony_version: "7.1.*"
- php: 8.3
symfony_version: "7.2.*"
- php: 8.4
symfony_version: "7.3.*"
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -69,25 +64,19 @@ jobs:
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Symfony ${{ matrix.symfony_version }}
run: composer require "symfony/framework-bundle:${{ matrix.symfony_version }}" --no-update
if: matrix.symfony_version != ''
- name: Downgrade php-cs-fixer
run: composer require "m6web/php-cs-fixer-config:${{ matrix.cs_fixer_config }}" --no-update
if: matrix.cs_fixer_config != ''
- name: Install Dependencies
run: composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress $COMPOSER_FLAGS
env:
COMPOSER_FLAGS: ${{ matrix.composer_flags }}
run: composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress
- name: Run PHPUnit
run: bin/simple-phpunit
env:
SYMFONY_DEPRECATIONS_HELPER: weak
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: ${{ matrix.symfony_phpunit_remove_return_typehint }}
30 changes: 26 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
<?php

$config = new M6Web\CS\Config\Php71;

$config->getFinder()
$finder = (PhpCsFixer\Finder::create())
->in([
__DIR__
__DIR__,
]);

$config = new class() extends PhpCsFixer\Config {
public function __construct()
{
parent::__construct('customized Bedrock Streaming');
$this->setRiskyAllowed(true);
}

public function getRules(): array
{
// Merge base rules and disable declare_strict_types
return array_merge(
(new M6Web\CS\Config\BedrockStreaming())->getRules(),
[
'declare_strict_types' => false,
'@PHP81Migration' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
]
);
}
};

$config->setFinder($finder);

return $config;
2 changes: 1 addition & 1 deletion Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(ServerInterface $server);
/**
* Send metrics data to the configured server
*
* @param array $lines array of string lines to send
* @param array<string> $lines array of string lines to send
*/
public function sendLines(array $lines): void;
}
14 changes: 9 additions & 5 deletions Client/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Server implements ServerInterface
{
/** @var string */
private $name;
/** @phpstan-ignore property.onlyWritten */
private string $name;

/** @var mixed string format udp://.+ */
private $address;
Expand All @@ -18,20 +18,24 @@ class Server implements ServerInterface
/**
* Server constructor.
*
* @param array<string, mixed> $serverConfig
*
* @throws ServerException
*/
public function __construct(string $serverName, array $serverConfig)
{
if ($this->checkServersConfigurations($serverName, $serverConfig)) {
$this->name = $serverName;
$this->address = $serverConfig['address'];
$this->port = intval($serverConfig['port']);
$this->port = (int) $serverConfig['port'];
}
}

/**
* Init the servers defined in the app configuration
*
* @param array<string, mixed> $serverConfig
*
* @throws ServerException
*/
protected function checkServersConfigurations(string $serverName, array $serverConfig): bool
Expand All @@ -40,10 +44,10 @@ protected function checkServersConfigurations(string $serverName, array $serverC
throw new ServerException('No servers have been configured');
}

if (!isset($serverConfig['address']) || !isset($serverConfig['port'])) {
if (!isset($serverConfig['address'], $serverConfig['port'])) {
throw new ServerException($serverName.' : no address or port in the configuration');
}
if (strpos($serverConfig['address'], 'udp://') !== 0) {
if (!str_starts_with($serverConfig['address'], 'udp://')) {
throw new ServerException($serverName.' : address should begin with udp://');
}

Expand Down
2 changes: 2 additions & 0 deletions Client/ServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
interface ServerInterface
{
/**
* @param array<string, mixed> $serverConfig
*
* @throws ServerException
*/
public function __construct(string $serverName, array $serverConfig);
Expand Down
11 changes: 7 additions & 4 deletions Client/UdpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ class UdpClient implements ClientInterface
/** @var int max safe size in bytes of one message to send (max official size is 65507) */
public const MAX_MESSAGE_SIZE = 64000;

/** @var ServerInterface */
protected $server;
protected ServerInterface $server;

/** @var ?bool */
protected $debugEnabled;
protected ?bool $debugEnabled;

public function __construct(ServerInterface $server, ?bool $debugEnabled = false)
{
Expand All @@ -21,6 +19,8 @@ public function __construct(ServerInterface $server, ?bool $debugEnabled = false

/**
* Split metrics to send them group by group
*
* @param array<string> $lines
*/
public function sendLines(array $lines): void
{
Expand All @@ -30,6 +30,9 @@ public function sendLines(array $lines): void
}
}

/**
* @param array<string> $lines
*/
protected function writeLines(array $lines): bool
{
if ($resource = @fsockopen($this->server->getAddress(), $this->server->getPort())) {
Expand Down
31 changes: 14 additions & 17 deletions DataCollector/StatsdDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use M6Web\Bundle\StatsdPrometheusBundle\Exception\MetricException;
use M6Web\Bundle\StatsdPrometheusBundle\Listener\EventListener;
use M6Web\Bundle\StatsdPrometheusBundle\Metric\MetricInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
Expand All @@ -15,7 +14,7 @@
class StatsdDataCollector extends DataCollector
{
/** @var EventListener[] */
private $eventListeners;
private array $eventListeners;

public function __construct()
{
Expand All @@ -36,7 +35,7 @@ public function reset(): void

public function onKernelResponse(ResponseEvent $event): void
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
if (HttpKernelInterface::MAIN_REQUEST === $event->getRequestType()) {
foreach ($this->eventListeners as $serviceId => $eventListener) {
$clientInfo = [
'name' => $serviceId,
Expand All @@ -45,14 +44,12 @@ public function onKernelResponse(ResponseEvent $event): void
$metricHandler = $eventListener->getMetricHandler();

foreach ($metricHandler->getMetrics() as $metric) {
if ($metric instanceof MetricInterface) {
try {
$clientInfo['operations'][] = [
'message' => $metricHandler->getFormattedMetric($metric),
];
$this->data['operations']++;
} catch (MetricException $e) {
}
try {
$clientInfo['operations'][] = [
'message' => $metricHandler->getFormattedMetric($metric),
];
$this->data['operations']++;
} catch (MetricException $e) {
}
}
$this->data['clients'][] = $clientInfo;
Expand All @@ -71,18 +68,18 @@ public function addEventListener(string $serviceId, EventListener $eventListener
/**
* Collect the data
*
* @param Request $request The request object
* @param Response $response The response object
* @param \Throwable $exception A throwable
* @param Request $request The request object
* @param Response $response The response object
* @param \Throwable|null $exception A throwable
*/
public function collect(Request $request, Response $response, \Throwable $exception = null): void
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
}

/**
* Return the list of statsd operations
*
* @return array operations list
* @return array<mixed> operations list
*/
public function getClients(): array
{
Expand All @@ -104,7 +101,7 @@ public function getOperations(): int
*
* @return string data collector name
*/
public function getName()
public function getName(): string
{
return 'statsd';
}
Expand Down
11 changes: 4 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ private function addServersSection(ArrayNodeDefinition $rootNode): void
->scalarNode('address')
->isRequired()
->validate()
->ifTrue(function ($v) {return substr($v, 0, 6) !== 'udp://'; })
->ifTrue(function ($v) {
return substr($v, 0, 6) !== 'udp://';
})
->thenInvalid("address parameter should begin with 'udp://'")
->end()
->end()
Expand Down Expand Up @@ -187,13 +189,8 @@ private function getClientsGroupsEvents()
return $eventsNode;
}

private function getRootNode(TreeBuilder $treeBuilder, $name)
private function getRootNode(TreeBuilder $treeBuilder, string $name): ArrayNodeDefinition
{
// BC layer for symfony/config 4.1 and older
if (!\method_exists($treeBuilder, 'getRootNode')) {
return $treeBuilder->root($name);
}

return $treeBuilder->getRootNode();
}
}
Loading