Skip to content

Commit

Permalink
Merge pull request #63 from thibaudgirard/feat/make-amqp-v2-compatible
Browse files Browse the repository at this point in the history
feat(amqp): make amqp v2 compatible
  • Loading branch information
thibaudgirard authored Mar 12, 2024
2 parents ffe058e + 9b53ac6 commit 968a190
Show file tree
Hide file tree
Showing 44 changed files with 729 additions and 530 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,44 @@ name: Continuous Integration
on: [push, pull_request]

jobs:
tests:
name: Tests
tests-old-versions:
name: Tests old versions
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1' ]
symfony-version: ['^4.4', '^5.0']
php-version: ['8.0', '8.1', '8.2' , '8.3' ]
fail-fast: false
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug2
extensions: amqp
extensions: amqp-2
- name: Install symfony v5.4
env:
SYMFONY_VERSION: '^5.4'
run: composer require symfony/symfony:$SYMFONY_VERSION --no-update
- name: Install dependencies
run: composer update --prefer-dist --no-interaction
- name: Unit tests
run: bin/atoum

tests-current-versions:
name: Tests current versions
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.2' , '8.3' ]
symfony-version: ['^6.4', '^7.0']
fail-fast: false
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
extensions: amqp-2
- name: Install symfony version from matrix
env:
SYMFONY_VERSION: ${{ matrix.symfony-version }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor/
/composer.lock
bin/
var
48 changes: 48 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__.'/src',
]);

$config = new class() extends PhpCsFixer\Config {
public function __construct()
{
parent::__construct('Bedrock Streaming');

$this->setRiskyAllowed(true);
}

public function getRules(): array
{
return array_merge((new M6Web\CS\Config\BedrockStreaming())->getRules(), [
'no_unreachable_default_argument_value' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arrays', 'arguments', 'parameters'],
],
'native_function_invocation' => [
'include' => ['@compiler_optimized']
],
'simplified_null_return' => false,
'void_return' => true,
'phpdoc_order' => true,
'phpdoc_types_order' => false,
'no_superfluous_phpdoc_tags' => true,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'static',
],
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false
],
]);
}
};

$config
->setFinder($finder)
->setCacheFile('var/cache/tools/.php-cs-fixer.cache');

return $config;
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
SOURCE_DIR = $(shell pwd)
BIN_DIR ?= ${SOURCE_DIR}/bin

define printSection
@printf "\033[36m\n==================================================\033[0m\n"
@printf "\033[36m $1 \033[0m"
@printf "\033[36m\n==================================================\033[0m\n"
endef

.PHONY: all
all: install ci

.PHONY: ci
ci: quality test

.PHONY: install
install: clean-vendor composer-install

.PHONY: quality
quality: cs-ci phpstan

.PHONY: test
test: atoum

.PHONY: clean-vendor
clean-vendor:
$(call printSection,CLEAN VENDOR)
rm -rf ${SOURCE_DIR}/vendor

.PHONY: phpstan
phpstan: phpstan-cache-clear
$(call printSection,PHPSTAN)
${BIN_DIR}/phpstan.phar analyse --memory-limit=1G

.PHONY: phpstan-cache-clear
phpstan-cache-clear:
${BIN_DIR}/phpstan.phar clear-result-cache

composer-install:
$(call printSection,COMPOSER INSTALL)
composer --no-interaction install --ansi --no-progress --prefer-dist

atoum:
$(call printSection,TESTING)
${BIN_DIR}/atoum --no-code-coverage --verbose

.PHONY: cs
cs: composer-install
${BIN_DIR}/php-cs-fixer fix --dry-run --stop-on-violation --diff

.PHONY: cs-fix
cs-fix: composer-install
${BIN_DIR}/php-cs-fixer fix

.PHONY: cs-ci
cs-ci: composer-install
$(call printSection,PHPCS)
${BIN_DIR}/php-cs-fixer fix --dry-run --using-cache=no --verbose
1 change: 0 additions & 1 deletion bin/atoum

This file was deleted.

119 changes: 119 additions & 0 deletions bin/atoum
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env php
<?php

/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../vendor/atoum/atoum/bin/atoum)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/

namespace Composer;

$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/vendor/autoload.php';

if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;

public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;

return (bool) $this->handle;
}

public function stream_read($count)
{
$data = fread($this->handle, $count);

if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}

$this->position += strlen($data);

return $data;
}

public function stream_cast($castAs)
{
return $this->handle;
}

public function stream_close()
{
fclose($this->handle);
}

public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}

public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}

return false;
}

public function stream_tell()
{
return $this->position;
}

public function stream_eof()
{
return feof($this->handle);
}

public function stream_stat()
{
return array();
}

public function stream_set_option($option, $arg1, $arg2)
{
return true;
}

public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}

return false;
}
}
}

if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/vendor/atoum/atoum/bin/atoum');
}
}

return include __DIR__ . '/..'.'/vendor/atoum/atoum/bin/atoum';
1 change: 0 additions & 1 deletion bin/coke

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpcs

This file was deleted.

19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
"autoload" : {
"psr-4": { "M6Web\\Bundle\\": "src/" }
},
"config": {
"bin-dir": "bin"
},
"require" : {
"php": ">=7.4",
"ext-amqp": "*",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0",
"symfony/yaml": "^4.4 || ^5.0",
"php": "^8.0",
"ext-amqp": ">=2.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || 6.4 || ^7.0",
"twig/twig": "^2.13 || ^3.0"
},
"require-dev" : {
"atoum/atoum": "~4.0",
"m6web/coke": "^2.2",
"m6web/symfony2-coding-standard": "^3.3"
"m6web/php-cs-fixer-config": "^3.2",
"phpstan/phpstan": "^1.10"
},
"suggest": {
"ocramius/proxy-manager": "Required for lazy connections"
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
paths:
- 'src'
excludePaths:
- 'src/AmqpBundle/Tests'
- 'src/AmqpBundle/Sandbox'
- 'src/AmqpBundle/DependencyInjection'

level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false

ignoreErrors:
- '#Unable to resolve the template type T in call to method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\)#'
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
]);
Loading

0 comments on commit 968a190

Please sign in to comment.