Skip to content

Commit

Permalink
feature #54 Allow php8 (sadikoff)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.1.x-dev branch.

Discussion
----------

Allow php8

Finally, allow php8!

Commits
-------

8fd414c get back simple-phpunit
99f802e Update phpunit.xml.dist
03c7ac4 fix missing test kernel var
7c59028 Allow php8 step 3
88b9a4f Merge remote-tracking branch 'upstream/master' into allow_8.0
912cea7 Allow php8 step 2
10aab91 Allow php8
  • Loading branch information
weaverryan committed Jan 19, 2022
2 parents 86ca5f9 + 8fd414c commit ad8a8c3
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 98 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build

on:
pull_request: ~
push: ~

jobs:
phpstan:
runs-on: ubuntu-20.04
name: PHPStan
steps:
- name: Checkout
uses: actions/checkout@v2
- name: PHPStan
uses: docker://oskarstark/phpstan-ga
env:
REQUIRE_DEV: true
with:
args: analyse
cs-fixer:
runs-on: ubuntu-20.04
name: PHP-CS-Fixer
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Fix CS
uses: docker://oskarstark/php-cs-fixer-ga
tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
include:
- description: 'Symfony 4.4'
php: '7.3'
composer_option: '--prefer-lowest'
- description: 'Symfony 5.3'
php: '7.4'
symfony: 5.3.*
- description: 'Symfony 6.0'
php: '8.0'
symfony: 6.0.*-dev
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: |
sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json;
if: contains(matrix.symfony, '-dev')
- run: composer config minimum-stability dev
- run: composer config prefer-stable true
if: matrix.symfony
- run: composer update --no-interaction --no-progress --ansi ${{ matrix.composer_option }}
- run: vendor/bin/simple-phpunit
22 changes: 22 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer

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

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'ordered_imports' => true,
'declare_strict_types' => false,
'native_function_invocation' => ['include' => ['@all']],
'final_class' => true,
'php_unit_mock_short_will_return' => true,
])
->setFinder($finder)
;
33 changes: 0 additions & 33 deletions .php_cs.dist

This file was deleted.

30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
],

"require": {
"php": "^7.2.5",
"php": ">=7.2.5",
"ext-json": "*",
"symfony/http-client": "^4.4|^5.0"
"symfony/http-client": "^4.4 || ^5.0 || ^6.0"
},

"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"symfony/framework-bundle": "^4.4 | ^5.0",
"symfony/phpunit-bridge": "^5.0",
"phpstan/phpstan": "^1.2",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.0 | ^6.0",
"twig/twig": "^2.10|^3.0"
},

Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
parameters:
ignoreErrors:
-
message: "#has parameter \\$parameters with no value type specified in iterable type array\\.$#"
count: 1
path: src/Helper/DisqusHelper.php
-
message: "#has parameter \\$configs with no value type specified in iterable type array\\.$#"
count: 1
path: src/DependencyInjection/KnpDisqusExtension.php
-
message: "#Symfony\\Component\\Config\\Definition\\ConfigurationInterface|null given\\.$#"
count: 1
path: src/DependencyInjection/KnpDisqusExtension.php
-
message: "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php
-
message: "#return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/DisqusClientInterface.php
-
message: "#has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/DisqusClientInterface.php
-
message: "#type has no value type specified in iterable type array\\.$#"
count: 4
path: src/Client/DisqusClient.php
-
message: "#has parameter (\\$options|\\$parameters) with no value type specified in iterable type array\\.$#"
count: 3
path: src/Client/DisqusClient.php
-
message: "#values of function sprintf expects bool\\\\|float\\\\|int\\\\|string\\\\|null, array\\\\|string given\\.$#"
count: 1
path: src/Client/DisqusClient.php
-
message: "#return type has no value type specified in iterable type array\\.$#"
count: 3
path: src/Model/DisqusConfig.php
-
message: "#\\$string of function base64_encode expects string, string|false given\\.$#"
count: 1
path: src/Model/DisqusConfig.php
-
message: "#has parameter \\$(content|parameters|options) with no value type specified in iterable type array\\.$#"
count: 4
path: src/Model/DisqusConfig.php
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
includes:
- phpstan-baseline.neon
17 changes: 4 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,16 @@
<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" />-->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<!-- <server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />-->
</php>


<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/IntegrationTests</directory>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
Expand Down
28 changes: 24 additions & 4 deletions src/Client/DisqusClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@

use Knp\Bundle\DisqusBundle\Model\DisqusConfig;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class DisqusClient implements DisqusClientInterface
{
/**
* @var DisqusConfig
*/
private $config;
/**
* @var HttpClientInterface
*/
private $httpClient;

/**
* @var array
*/
private $options = [
'since' => null,
'cursor' => null,
Expand Down Expand Up @@ -134,10 +149,15 @@ private function setOptions(array $options): array
return array_merge($this->options, $options);
}

private function request(string $url, string $method = 'GET'): ?array
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
private function request(string $url, string $method = 'GET'): array
{
$response = $this->httpClient->request($method, $url);

return $response->toArray();
return $this->httpClient->request($method, $url)->toArray();
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/TwigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class TwigPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (false !== $container->hasDefinition('twig')) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('knp_disqus');
$rootNode = $treeBuilder->getRootNode();
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/KnpDisqusExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

class KnpDisqusExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__, 2).'/config'));
$loader->load('services.xml');

$configuration = $this->getConfiguration($configs, $container);
Expand Down
11 changes: 10 additions & 1 deletion src/Helper/DisqusHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@

class DisqusHelper implements RuntimeExtensionInterface
{
/**
* @var Environment
*/
private $twig;
/**
* @var DisqusConfig
*/
private $config;
/**
* @var DisqusClientInterface
*/
private $disqus;

public function __construct(Environment $twig, DisqusConfig $config, DisqusClientInterface $disqus)
Expand All @@ -29,7 +38,7 @@ public function __construct(Environment $twig, DisqusConfig $config, DisqusClien
$this->disqus = $disqus;
}

public function render(string $shortname, array $parameters = [], $template = '@KnpDisqus/list.html.twig')
public function render(string $shortname, array $parameters = [], string $template = '@KnpDisqus/list.html.twig'): string
{
try {
$content = $this->disqus->fetch($shortname, $parameters);
Expand Down
7 changes: 6 additions & 1 deletion src/KnpDisqusBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
*/
class KnpDisqusBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new TwigPass());
}

public function getPath(): string
{
return \dirname(__DIR__);
}
}
Loading

0 comments on commit ad8a8c3

Please sign in to comment.