Skip to content

Commit

Permalink
Merge pull request #72 from sadikoff/sf6_prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
laupiFrpar committed Apr 14, 2022
2 parents a1698b6 + 5d87c00 commit 1810780
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 125 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Bundle CI
on:
push:
branches: ['main']
pull_request:
schedule:
- cron: '0 */12 * * *'

jobs:
static-analysis:
name: Static Analysis
runs-on: ubuntu-18.04

steps:
- name: "Checkout code"
uses: "actions/checkout@v2"

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

- name: "Validate composer.json"
run: "composer validate --strict --no-check-lock"

- name: "Composer install"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--prefer-stable"
dependency-versions: 'highest'

- name: Install PHP-CS-Fixer
run: composer global require friendsofphp/php-cs-fixer --prefer-dist --no-progress

- name: Running php-cs-fixer
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config $GITHUB_WORKSPACE/.php-cs-fixer.dist.php --diff --dry-run

tests:
name: "Tests ${{ matrix.php-version }} ${{ matrix.dependency-versions }} deps ${{ matrix.dependency-versions }}"
runs-on: ubuntu-18.04

strategy:
fail-fast: false
matrix:
# normal, highest, non-dev installs
php-version: ['8.0', '8.1']
composer-options: ['--prefer-stable']
dependency-versions: ['highest']
include:
# testing lowest PHP version with lowest dependencies
- php-version: '8.0'
dependency-versions: 'lowest'
composer-options: '--prefer-lowest'

steps:
- name: "Checkout code"
uses: "actions/checkout@v2"

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

- name: Install Global Dependencies
run: |
composer global require --no-progress --no-scripts --no-plugins symfony/flex >=1.x
- name: "Composer install"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependency-versions }}"
composer-options: "--prefer-dist --no-progress"

- name: All Tests
run: vendor/bin/simple-phpunit -c $GITHUB_WORKSPACE/phpunit.xml.dist
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ xcuserdata
# svn & cvs
.svn
CVS
.php_cs.cache

vendor

composer.lock
*.sublime-workspace
.phpunit.result.cache
phpunit.xml
.php-cs-fixer.cache
4 changes: 2 additions & 2 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
exit(0);
}

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

return PhpCsFixer\Config::create()
return (new \PhpCsFixer\Config())
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
Expand Down
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

21 changes: 9 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@
"source": "https://github.com/laupiFrpar/LopiPusherBundle"
},
"require": {
"php": ">=7.2",
"php": ">=8.0.2",
"ext-json": "*",
"pusher/pusher-php-server": "^4.0",
"symfony/config": "^3.4|^4.4|^5.0",
"symfony/dependency-injection": "^3.4|^4.4|^5.0",
"symfony/http-kernel": "^3.4|^4.4|^5.0"
"pusher/pusher-php-server": "^7.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"symfony/framework-bundle": "^3.4|^4.4|^5.0",
"symfony/phpunit-bridge": "^3.4|^4.4|^5.0",
"symfony/twig-bundle": "^3.4|^4.4|^5.0"
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/twig-bundle": "^5.4|^6.0",
"friendsofphp/php-cs-fixer": "^3.8"
},
"autoload": {
"psr-4": { "Lopi\\Bundle\\PusherBundle\\": "src/" }
},
"autoload-dev": {
"psr-4": { "Lopi\\Bundle\\PusherBundle\\Tests\\": "tests/" }
},
"conflict": {
"twig/twig": "<2.7"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 22 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<!-- <server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />-->
</php>
bootstrap="vendor/autoload.php">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<!-- <server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />-->
</php>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
4 changes: 1 addition & 3 deletions src/Authenticator/ChannelAuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ interface ChannelAuthenticatorInterface
/**
* @param string $socketId The socket ID
* @param string $channelName The channel name
*
* @return bool
*/
public function authenticate($socketId, $channelName);
public function authenticate(string $socketId, string $channelName): bool;
}
8 changes: 2 additions & 6 deletions src/Authenticator/ChannelAuthenticatorPresenceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ interface ChannelAuthenticatorPresenceInterface extends ChannelAuthenticatorInte
{
/**
* Returns an optional array of user info.
*
* @return array
*/
public function getUserInfo();
public function getUserInfo(): array;

/**
* Return the user id when authenticated, used for presence channels.
*
* @return string
*/
public function getUserId();
public function getUserId(): string;
}
23 changes: 11 additions & 12 deletions src/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
*/
class AuthController
{
private $configuration;
private $authenticator;

public function __construct(PusherConfiguration $configuration, ChannelAuthenticatorInterface $authenticator)
{
$this->configuration = $configuration;
$this->authenticator = $authenticator;
public function __construct(
private PusherConfiguration $configuration,
private ChannelAuthenticatorInterface $authenticator
) {
}

/**
Expand Down Expand Up @@ -67,12 +64,14 @@ public function authAction(Request $request): Response
}

/**
* Perform channel autentication.
* Perform channel authentication.
*
* @param string $socketId The socket id
* @param string $channelName name of the channel to validate
*
* @return array response auth data or null on access denied
* @return array|null response auth data or null on access denied
*
* @throws \JsonException
*/
private function authenticateChannel(string $socketId, string $channelName): ?array
{
Expand All @@ -83,11 +82,11 @@ private function authenticateChannel(string $socketId, string $channelName): ?ar
return null;
}

if (0 === strpos($channelName, 'presence') && $this->authenticator instanceof ChannelAuthenticatorPresenceInterface) {
if ($this->authenticator instanceof ChannelAuthenticatorPresenceInterface && str_starts_with($channelName, 'presence')) {
$responseData['channel_data'] = json_encode([
'user_id' => $this->authenticator->getUserId(),
'user_info' => $this->authenticator->getUserInfo(),
]);
], \JSON_THROW_ON_ERROR);
$data .= ':'.$responseData['channel_data'];
}

Expand All @@ -101,7 +100,7 @@ private function authenticateChannel(string $socketId, string $channelName): ?ar
*
* @param string $data The data to hash
*/
private function getCode($data): string
private function getCode(string $data): string
{
return hash_hmac('sha256', $data, $this->configuration->getSecret());
}
Expand Down
11 changes: 2 additions & 9 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('lopi_pusher');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root('lopi_pusher', 'array');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->validate()
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/LopiPusherExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.xml');

$pusherConfigurationDefinition = $container->getDefinition('lopi_pusher.pusher_configuration');
Expand Down
4 changes: 4 additions & 0 deletions src/LopiPusherBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
*/
class LopiPusherBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
8 changes: 4 additions & 4 deletions src/PusherConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

final class PusherConfiguration
{
private $authKey;
private $secret;
private $appId;
private $options;
private string $authKey;
private string $secret;
private string $appId;
private array $options;

public function __construct(array $config)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/IntegrationTests/PusherAutowireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class PusherAutowireTest extends TestCase
/**
* @doesNotPerformAssertions
*/
public function testPusherIsAutowiredByContainer()
public function testPusherIsAutowiredByContainer(): void
{
$builder = new ContainerBuilder();
$builder->autowire(PusherAutowireClass::class)
Expand Down
Loading

0 comments on commit 1810780

Please sign in to comment.