Skip to content

Commit

Permalink
add PHP cs fixer to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Apr 20, 2023
1 parent 7c6a29c commit 7b1444c
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 210 deletions.
68 changes: 39 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build

on: [pull_request]
on: [ pull_request ]

jobs:
tests:
Expand All @@ -10,33 +10,43 @@ jobs:
fail-fast: false
matrix:
include:
- php: 7.3
- php: 7.4
SYMFONY_REQUIRE: 5.4.*
- php: 8.0
- php: 8.1
- php: 8.2
- php: 7.3
- php: 7.4
SYMFONY_REQUIRE: 5.4.*
- php: 8.0
- php: 8.1
- php: 8.2

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: none

- name: Configure Composer minimum stability
if: matrix.stability
run: composer config minimum-stability ${{ matrix.stability }}

- name: Install symfony/flex
run: composer global config allow-plugins.symfony/flex true && composer global require symfony/flex

- name: Install dependencies
env:
SYMFONY_REQUIRE: "${{ matrix.SYMFONY_REQUIRE }}"
run: composer update ${{ matrix.composer-flags }} --prefer-dist

- name: Phpunit
run: ./vendor/bin/simple-phpunit
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: none

- name: Configure Composer minimum stability
if: matrix.stability
run: composer config minimum-stability ${{ matrix.stability }}

- name: Install symfony/flex
run: composer global config allow-plugins.symfony/flex true && composer global require symfony/flex

- name: Install dependencies
env:
SYMFONY_REQUIRE: "${{ matrix.SYMFONY_REQUIRE }}"
run: composer update ${{ matrix.composer-flags }} --prefer-dist

- name: Phpunit
run: ./vendor/bin/simple-phpunit

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.php --diff --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
8 changes: 8 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'yoda_style' => false,
])
;
20 changes: 9 additions & 11 deletions src/ClientRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
use Solarium\Client;

/**
* Class ClientRegistry
* Class ClientRegistry.
*
* Service to access all the clients configured by the bundle
*
* @package Nelmio\SolariumBundle
*/
class ClientRegistry
{
Expand All @@ -28,7 +26,7 @@ public function __construct(array $clients, $defaultClientName)
/**
* Gets the default client name.
*
* @return string The default client name.
* @return string the default client name
*/
public function getDefaultClientName()
{
Expand All @@ -38,10 +36,11 @@ public function getDefaultClientName()
/**
* Gets the named client.
*
* @param string $name The client name (null for the default one).
* @param string $name the client name (null for the default one)
*
* @throws \InvalidArgumentException
* @return Client
*
* @throws \InvalidArgumentException
*/
public function getClient($name = null)
{
Expand All @@ -53,13 +52,13 @@ public function getClient($name = null)
return $this->clients[$name];
}

throw new \InvalidArgumentException(($name === null ? 'default client' : 'client ' . $name) . ' not configured');
throw new \InvalidArgumentException(($name === null ? 'default client' : 'client '.$name).' not configured');
}

/**
* Gets an array of all registered clients.
*
* @return array An array of Client instances.
* @return array an array of Client instances
*/
public function getClients()
{
Expand All @@ -69,11 +68,10 @@ public function getClients()
/**
* Gets all client names.
*
* @return array An array of client names.
* @return array an array of client names
*/
public function getClientNames()
{
return array_keys($this->clients);
}

}
}
12 changes: 6 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('default_endpoint')->end()
->arrayNode('load_balancer')
->addDefaultsIfNotSet()
->treatFalseLike(array('enabled' => false))
->treatTrueLike(array('enabled' => true))
->treatNullLike(array('enabled' => true))
->treatFalseLike(['enabled' => false])
->treatTrueLike(['enabled' => true])
->treatNullLike(['enabled' => true])
->beforeNormalization()
->ifArray()
->then(function($v) {
->then(function ($v) {
$v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;

return $v;
Expand All @@ -93,7 +93,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->always(function (array $endpoints) {
// the values should be the weight and the keys the endpoints name
// handle the case where people just list the endpoints like [endpoint1, endpoint2]
$normalizedEndpoints = array();
$normalizedEndpoints = [];
foreach ($endpoints as $name => $weight) {
if (!is_string($name)) {
$name = $weight;
Expand All @@ -109,7 +109,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')->end()
->end()
->arrayNode('blocked_query_types')
->defaultValue(array(Client::QUERY_UPDATE))
->defaultValue([Client::QUERY_UPDATE])
->beforeNormalization()
->ifString()
->then($this->getNormalizeListToArrayClosure())
Expand Down
36 changes: 17 additions & 19 deletions src/DependencyInjection/NelmioSolariumExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function load(array $configs, ContainerBuilder $container)

$defaultClient = $config['default_client'];
if (!count($config['clients'])) {
$config['clients'][$defaultClient] = array();
$config['clients'][$defaultClient] = [];
} elseif (count($config['clients']) === 1) {
$defaultClient = key($config['clients']);
}

// Configure the Solarium endpoints
$endpointReferences = $this->configureEndpoints($config['endpoints'], $container);

$clients = array();
$clients = [];
foreach ($config['clients'] as $name => $clientOptions) {
$clientName = sprintf('solarium.client.%s', $name);

Expand All @@ -73,10 +73,10 @@ public function load(array $configs, ContainerBuilder $container)

$options = [];

//If some specific endpoints are given
// If some specific endpoints are given
if ($endpointReferences) {
if (isset($clientOptions['endpoints']) && !empty($clientOptions['endpoints'])) {
$endpoints = array();
$endpoints = [];
foreach ($clientOptions['endpoints'] as $endpointName) {
if (isset($endpointReferences[$endpointName])) {
$endpoints[] = $endpointReferences[$endpointName];
Expand All @@ -89,7 +89,6 @@ public function load(array $configs, ContainerBuilder $container)
$options['endpoint'] = $endpoints;
}


if (isset($clientOptions['adapter_service'])) {
$adapterName = $clientOptions['adapter_service'];
} else {
Expand All @@ -103,26 +102,25 @@ public function load(array $configs, ContainerBuilder $container)
$clientDefinition->setArguments([
new Reference($adapterName),
new Reference('event_dispatcher'),
$options
$options,
]);

// Configure the Load-Balancer for the current client
$this->configureLoadBalancerForClient($clientName, $clientOptions, $clientDefinition, $container);

//Default endpoint
// Default endpoint
if (isset($clientOptions['default_endpoint'], $endpointReferences[$clientOptions['default_endpoint']])) {
$clientDefinition->addMethodCall('setDefaultEndpoint', array($clientOptions['default_endpoint']));
$clientDefinition->addMethodCall('setDefaultEndpoint', [$clientOptions['default_endpoint']]);
}

//Add the optional adapter class
// Add the optional adapter class
if (isset($clientOptions['adapter_class'])) {
$clientDefinition->addMethodCall('setAdapter', array($clientOptions['adapter_class']));
$clientDefinition->addMethodCall('setAdapter', [$clientOptions['adapter_class']]);
}

// Configure the Plugins for the current client
$this->configurePluginsForClient($clientOptions, $clientDefinition);


if ($isDebug) {
// If debug, associate the logger to this client
$this->configureLoggerForClient($clientName, $container);
Expand All @@ -139,14 +137,14 @@ public function load(array $configs, ContainerBuilder $container)

private function configureEndpoints(array $endpoints, ContainerBuilder $container): array
{
$endpointReferences = array();
$endpointReferences = [];
foreach ($endpoints as $name => $endpointOptions) {
$endpointName = sprintf('solarium.client.endpoint.%s', $name);
$endpointOptions['key'] = $name;

$container
->setDefinition($endpointName, new Definition(Endpoint::class))
->setArguments(array($endpointOptions));
->setArguments([$endpointOptions]);
$endpointReferences[$name] = new Reference($endpointName);
}

Expand All @@ -156,7 +154,7 @@ private function configureEndpoints(array $endpoints, ContainerBuilder $containe
private function configureLoggerForClient(string $clientName, ContainerBuilder $container): void
{
$logger = new Reference('solarium.data_collector');
$container->getDefinition($clientName)->addMethodCall('registerPlugin', array($clientName . '.logger', $logger));
$container->getDefinition($clientName)->addMethodCall('registerPlugin', [$clientName.'.logger', $logger]);
}

private function configureLoadBalancerForClient(
Expand All @@ -168,19 +166,19 @@ private function configureLoadBalancerForClient(
if (isset($clientOptions['load_balancer']) && $clientOptions['load_balancer']['enabled']) {
$loadBalancerDefinition = new Definition(Loadbalancer::class);
$loadBalancerDefinition
->addMethodCall('addEndpoints', array($clientOptions['load_balancer']['endpoints']))
->addMethodCall('addEndpoints', [$clientOptions['load_balancer']['endpoints']])
;
if (isset($clientOptions['load_balancer']['blocked_query_types'])) {
$loadBalancerDefinition
->addMethodCall('setBlockedQueryTypes', array($clientOptions['load_balancer']['blocked_query_types']))
->addMethodCall('setBlockedQueryTypes', [$clientOptions['load_balancer']['blocked_query_types']])
;
}

$loadBalancerName = $clientName . '.load_balancer';
$loadBalancerName = $clientName.'.load_balancer';
$container->setDefinition($loadBalancerName, $loadBalancerDefinition);

$clientDefinition
->addMethodCall('registerPlugin', array('loadbalancer', new Reference($loadBalancerName)))
->addMethodCall('registerPlugin', ['loadbalancer', new Reference($loadBalancerName)])
;
}
}
Expand All @@ -194,7 +192,7 @@ private function configurePluginsForClient(array $clientOptions, Definition $cli
} else {
$plugin = new Reference($pluginOptions['plugin_service']);
}
$clientDefinition->addMethodCall('registerPlugin', array($pluginName, $plugin));
$clientDefinition->addMethodCall('registerPlugin', [$pluginName, $plugin]);
}
}
}
Expand Down
Loading

0 comments on commit 7b1444c

Please sign in to comment.