Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
* Movee to GitHub Actions
* Remove Travis
* Upgrade PHPUnit
* Bump minimum required PHP to 8.0
* Test on PHP 8.1
* Drop old Symfomny versiosn
* Add missing typehints.
  • Loading branch information
ruudk committed Dec 8, 2021
1 parent 005b73f commit c6de072
Show file tree
Hide file tree
Showing 17 changed files with 215 additions and 139 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: CI

on:
pull_request:
branches:
- "*.*"
- master
push:
branches:
- "*.*"
- master

jobs:
tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php-version:
- '8.0'
- '8.1'
symfony-version:
- '5.3.*'
- '5.4.*'
- '6.0.*'
dependencies:
- 'lowest'
- 'highest'
remove-dependencies: [ '' ]
coverage: [ 'none' ]
include:
- php-version: '8.0'
symfony-version: '5.3.*'
dependencies: 'lowest'
remove-dependencies: '--dev symfony/validator doctrine/orm doctrine/annotations'
- php-version: '8.0'
symfony-version: '5.3.*'
dependencies: 'lowest'
coverage: "pcov"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"

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

- name: "Change stability"
if: "matrix.stability != ''"
run: perl -pi -e 's/^}$/,"minimum-stability":"'"${{ matrix.minimum-stability }}"'"}/' composer.json && cat composer.json

- name: "Webonyx GraphQL version"
if: "matrix.graphql-version != ''"
run: composer require "webonyx/graphql-php:${{ matrix.graphql-version }}" --dev --no-update

- name: Remove dependencies
if: "matrix.remove-dependencies != ''"
run: composer remove --no-update ${{ matrix.remove-dependencies }}

- name: "Install dependencies"
uses: ramsey/[email protected]
with:
dependency-versions: ${{ matrix.dependencies }}
env:
SYMFONY_REQUIRE: "${{ matrix.symfony-version }}"

- name: "Run tests"
run: composer test

- name: "Upload coverage results to Coveralls"
if: "matrix.coverage == 'pcov'"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.1/php-coveralls.phar
php php-coveralls.phar --coverage_clover=build/logs/clover.xml -v
coding-standard:
runs-on: ubuntu-20.04
name: Coding Standard
steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
tools: flex
php-version: "8.0"

- name: "Install dependencies"
uses: ramsey/[email protected]

- name: "Check coding standard"
run: composer check-cs

static-analysis:
runs-on: ubuntu-20.04
name: "Static analysis"
strategy:
fail-fast: false
matrix:
php-version:
- '8.0'
- '8.1'
steps:
- name: "Checkout"
uses: "actions/checkout@v2"

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

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies"
uses: ramsey/[email protected]

- name: "Run static-analysis"
run: composer static-analysis
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ phpunit.xml
composer.lock
composer.phar
.php_cs.cache
/.phpunit.result.cache
53 changes: 0 additions & 53 deletions .travis.yml

This file was deleted.

26 changes: 14 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@
],
"autoload": {
"psr-4": {
"Overblog\\DataLoaderBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
"Overblog\\DataLoaderBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Overblog\\DataLoaderBundle\\": "tests/"
}
},
"config" : {
"bin-dir": "bin",
"sort-packages": true
},
"require": {
"php": ">=5.5",
"overblog/dataloader-php": "^0.5.0",
"symfony/dependency-injection": "^2.7 || ^3.1 || ^4.0"
"php": "^8.0",
"overblog/dataloader-php": "^0.7.0",
"symfony/dependency-injection": "^5.3 || ^6.0"
},
"require-dev": {
"phpunit/phpunit": "^4.1 || ^5.5 || ^6.0",
"phpunit/phpunit": "^9.5.10",
"react/promise": "^2.5",
"sensio/framework-extra-bundle": "^3.0",
"symfony/phpunit-bridge": "^2.7 || ^3.1 || ^4.0",
"symfony/yaml": "^2.7 || ^3.1 || ^4.0"
"sensio/framework-extra-bundle": "^6.2",
"symfony/phpunit-bridge": "^6.0",
"symfony/yaml": "^5.3 || ^6.0"
},
"extra": {
"branch-alias": {
Expand Down
12 changes: 0 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand All @@ -17,17 +16,6 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>

<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@

namespace Overblog\DataLoaderBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
const SERVICE_CALLABLE_NOTATION_REGEX = '/^@(?<service_id>[a-z0-9\._]+)(?:\:(?<method>[a-zA-Z_\x7f-\xff][a-z0-9_\x7f-\xff]*))?$/i';
const PHP_CALLABLE_NOTATION_REGEX = '/^(?<function>(?:\\\\?[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*)+)(?:\:\:(?<method>[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*))?$/i';
public const SERVICE_CALLABLE_NOTATION_REGEX = '/^@(?<service_id>[a-z0-9\._]+)(?:\:(?<method>[a-zA-Z_\x7f-\xff][a-z0-9_\x7f-\xff]*))?$/i';
public const PHP_CALLABLE_NOTATION_REGEX = '/^(?<function>(?:\\\\?[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*)+)(?:\:\:(?<method>[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*))?$/i';

public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('overblog_dataloader');
$rootNode
$treeBuilder = new TreeBuilder('overblog_dataloader');
$treeBuilder
->getRootNode()
->children()
->arrayNode('defaults')
->isRequired()
Expand All @@ -42,7 +43,7 @@ public function getConfigTreeBuilder()
->scalarNode('alias')
->validate()
->ifTrue(function ($alias) {
return !preg_match('/[a-z0-9_\.]+/i', $alias);
return $alias !== null && !preg_match('/[a-z0-9_\.]+/i', $alias);
})
->thenInvalid('%s is not a valid service alias.')
->end()
Expand All @@ -59,10 +60,12 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

private function addOptionsSection()
private function addOptionsSection() : NodeDefinition
{
$builder = new TreeBuilder();
$node = $builder->root('options');
$builder = new TreeBuilder('options');

$node = $builder->getRootNode();

$node
->children()
->booleanNode('batch')->defaultTrue()->end()
Expand All @@ -75,14 +78,19 @@ private function addOptionsSection()
return $node;
}

private function addCallableSection($name)
private function addCallableSection($name) : NodeDefinition
{
$builder = new TreeBuilder();
$node = $builder->root($name, 'scalar');
$builder = new TreeBuilder($name, 'scalar');

$node = $builder->getRootNode();

$node
->validate()
->ifTrue(function ($batchLoadFn) {
if ($batchLoadFn === null) {
return false;
}

if (preg_match(self::SERVICE_CALLABLE_NOTATION_REGEX, $batchLoadFn)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class OverblogDataLoaderExtension extends Extension
final class OverblogDataLoaderExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services.yaml');

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
Expand Down Expand Up @@ -57,22 +57,22 @@ public function load(array $configs, ContainerBuilder $container)
}
}

public function getAlias()
public function getAlias(): string
{
return 'overblog_dataloader';
}

private function generateDataLoaderServiceIDFromName($name, ContainerBuilder $container)
private function generateDataLoaderServiceIDFromName($name, ContainerBuilder $container) : string
{
return sprintf('%s.%s_loader', $this->getAlias(), $container->underscore($name));
}

private function generateDataLoaderOptionServiceIDFromName($name, ContainerBuilder $container)
private function generateDataLoaderOptionServiceIDFromName($name, ContainerBuilder $container): string
{
return sprintf('%s_option', $this->generateDataLoaderServiceIDFromName($name, $container));
}

private function buildOptionsParams(array $options)
private function buildOptionsParams(array $options) : array
{
$optionsParams = [];

Expand All @@ -85,10 +85,14 @@ private function buildOptionsParams(array $options)
return $optionsParams;
}

private function buildCallableFromScalar($scalar)
private function buildCallableFromScalar($scalar): mixed
{
$matches = null;

if ($scalar === null) {
return null;
}

if (preg_match(Configuration::SERVICE_CALLABLE_NOTATION_REGEX, $scalar, $matches)) {
$function = new Reference($matches['service_id']);
if (empty($matches['method'])) {
Expand Down
Loading

0 comments on commit c6de072

Please sign in to comment.