Skip to content

Commit

Permalink
php 8 + github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
janatjak committed Sep 12, 2022
1 parent e7eb619 commit 9314fb8
Show file tree
Hide file tree
Showing 30 changed files with 105 additions and 215 deletions.
4 changes: 0 additions & 4 deletions .coveralls.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .gitattributes

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests

on: [ push, pull_request ]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: pcov

- name: Composer install
run: composer install --dev --no-progress

- name: Check coding standard
run: vendor/bin/phpcs --standard=PSR12 ./src ./tests

- name: Check phpstan
run: vendor/bin/phpstan

- name: Check tests
run: vendor/bin/tester tests -C --coverage coverage.xml --coverage-src ./src

- name: Upload coverage
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=coverage.xml --json_path=upload.json
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
rm -rf tests/tmp/cache
php vendor/bin/phpstan analyse ./src ./tests --level max
php vendor/bin/phpstan
php vendor/bin/phpcs --standard=PSR12 ./src ./tests
php vendor/bin/tester ./tests
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": "^7.1",
"php": "^8.0",
"ext-json": "*",
"nette/di": "^3.0",
"php-http/client-common": "^2.0",
Expand All @@ -26,7 +26,7 @@
"php-http/message-factory": "^1.0"
},
"require-dev": {
"freezy-bee/nette-caching-psr6": "^1.1",
"freezy-bee/nette-caching-psr6": "^2.0",
"mockery/mockery": "^1.1",
"nette/application": "^3.0",
"nette/bootstrap": "^3.0",
Expand All @@ -36,9 +36,9 @@
"php-http/curl-client": "^2.0",
"php-http/guzzle7-adapter": "^1.0",
"php-http/logger-plugin": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.8",
"squizlabs/php_codesniffer": "^3.0",
"symfony/cache": "^4.0 || ^5.0",
"symfony/cache": "^6.0",
"tracy/tracy": "^2.6"
},
"autoload": {
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
parameters:
checkMissingIterableValueType: false
level: 8
paths:
- src
- tests

checkUninitializedProperties: true
4 changes: 1 addition & 3 deletions src/ClientFactory/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
interface ClientFactory
{
/**
* Input an array of configuration to be able to create a HttpClient.
* @param array $config
* @return HttpClient
* @param array<mixed> $config
*/
public function createClient(array $config = []): HttpClient;
}
4 changes: 0 additions & 4 deletions src/ClientFactory/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
*/
class CurlFactory implements ClientFactory
{
/**
* {@inheritdoc}
* @throws \LogicException
*/
public function createClient(array $config = []): HttpClient
{
if (!class_exists(Client::class)) {
Expand Down
4 changes: 0 additions & 4 deletions src/ClientFactory/Guzzle7Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
*/
class Guzzle7Factory implements ClientFactory
{
/**
* {@inheritdoc}
* @throws LogicException
*/
public function createClient(array $config = []): HttpClient
{
if (!class_exists(Client::class)) {
Expand Down
6 changes: 2 additions & 4 deletions src/ClientFactory/PluginClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class PluginClientFactory
{
/**
* @param Plugin[] $plugins
* @param ClientFactory $factory
* @param array $config config to the client factory
* @param array $pluginClientOptions config forwarded to the PluginClient
* @param bool $debugMode
* @param array<mixed> $config config to the client factory
* @param array<mixed> $pluginClientOptions config forwarded to the PluginClient
* @return PluginClientDecorator|PluginClient
*/
public static function createPluginClient(
Expand Down
26 changes: 11 additions & 15 deletions src/DI/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use InvalidArgumentException;
use Nette\DI\CompilerExtension;
use Nette\DI\ContainerBuilder;
use Nette\DI\Definitions\Definition;
use Nette\DI\Definitions\ServiceDefinition;
use Nette\DI\Definitions\Statement;
use Nette\DI\Helpers;
Expand All @@ -29,11 +30,10 @@
*/
class HttplugExtension extends CompilerExtension
{
/** @var bool */
private $debugMode = false;
private bool $debugMode = false;

/** @var array */
private static $defaults = [
/** @var array<string, mixed> */
private static array $defaults = [
# uses discovery if not specified
'classes' => [
'client' => null,
Expand All @@ -54,16 +54,16 @@ class HttplugExtension extends CompilerExtension
]
];

/** @var array */
private $classes = [
/** @var array<string, string> */
private array $classes = [
'client' => HttpClient::class,
'messageFactory' => MessageFactory::class,
'uriFactory' => UriFactory::class,
'streamFactory' => StreamFactory::class,
];

/** @var array */
private $factoryClasses = [
/** @var array<string, mixed> */
private array $factoryClasses = [
'client' => [HttpClientDiscovery::class, 'find'],
'messageFactory' => [MessageFactoryDiscovery::class, 'find'],
'uriFactory' => [UriFactoryDiscovery::class, 'find'],
Expand Down Expand Up @@ -116,7 +116,7 @@ public function loadConfiguration(): void
/**
* @param ContainerBuilder $containerBuilder
* @param string $clientName
* @param array[] $clientConfig
* @param array<mixed> $clientConfig
*/
private function configureClient(ContainerBuilder $containerBuilder, string $clientName, array $clientConfig): void
{
Expand Down Expand Up @@ -152,18 +152,14 @@ private function configureClient(ContainerBuilder $containerBuilder, string $cli
}

/**
* @param ContainerBuilder $containerBuilder
* @param string $pluginName
* @param string $clientName
* @param array $pluginConfig
* @return ServiceDefinition
* @param array<mixed> $pluginConfig
*/
private function configurePlugin(
ContainerBuilder $containerBuilder,
string $pluginName,
string $clientName,
array $pluginConfig
): ServiceDefinition {
): Definition {

$creator = 'FreezyBee\Httplug\DI\Plugin\\' . ucfirst($pluginName);

Expand Down
2 changes: 1 addition & 1 deletion src/DI/IClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IClientProvider
* plugins:
* ...
* @return array
* @return array<mixed>
*/
public function getClientConfigs(): array;
}
11 changes: 2 additions & 9 deletions src/DI/Plugin/AddHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Http\Client\Common\Plugin\AddHostPlugin;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceDefinition;
use Nette\DI\Definitions\Definition;
use Nette\StaticClass;
use Psr\Http\Message\UriInterface;

Expand All @@ -17,19 +17,12 @@ class AddHost implements IPluginServiceDefinitonCreator
{
use StaticClass;

/**
* @param ContainerBuilder $containerBuilder
* @param string $extensionName
* @param string $clientName
* @param array $pluginConfig
* @return ServiceDefinition
*/
public static function createPluginServiceDefinition(
ContainerBuilder $containerBuilder,
string $extensionName,
string $clientName,
array $pluginConfig
): ServiceDefinition {
): Definition {

$uriServiceDef = $containerBuilder
->addDefinition("$extensionName.client.$clientName.plugin.addHost.uri")
Expand Down
12 changes: 2 additions & 10 deletions src/DI/Plugin/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Http\Message\Authentication\Wsse;
use InvalidArgumentException;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceDefinition;
use Nette\DI\Definitions\Definition;
use Nette\StaticClass;

/**
Expand All @@ -20,20 +20,12 @@ class Authentication implements IPluginServiceDefinitonCreator
{
use StaticClass;

/**
* @param ContainerBuilder $containerBuilder
* @param string $extensionName
* @param string $clientName
* @param array $pluginConfig
* @return ServiceDefinition
* @throws InvalidArgumentException
*/
public static function createPluginServiceDefinition(
ContainerBuilder $containerBuilder,
string $extensionName,
string $clientName,
array $pluginConfig
): ServiceDefinition {
): Definition {
$type = $pluginConfig['type'] ?? null;

if ($type === null) {
Expand Down
15 changes: 5 additions & 10 deletions src/DI/Plugin/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Http\Client\Common\Plugin\CachePlugin;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceDefinition;
use Nette\DI\Definitions\Definition;
use Nette\StaticClass;
use Nette\Utils\Strings;

/**
* @author Jakub Janata <[email protected]>
Expand All @@ -16,19 +17,12 @@ class Cache implements IPluginServiceDefinitonCreator
{
use StaticClass;

/**
* @param ContainerBuilder $containerBuilder
* @param string $extensionName
* @param string $clientName
* @param array[] $pluginConfig
* @return ServiceDefinition
*/
public static function createPluginServiceDefinition(
ContainerBuilder $containerBuilder,
string $extensionName,
string $clientName,
array $pluginConfig
): ServiceDefinition {
): Definition {

$args = [];

Expand All @@ -44,7 +38,8 @@ public static function createPluginServiceDefinition(

$config = [];
foreach ($pluginConfig['config'] as $key => $value) {
$config[strtolower(preg_replace('#(.)(?=[A-Z])#', '$1_', $key) ?: '')] = $value;
$newKey = Strings::replace($key, '#(.)(?=[A-Z])#', '$1_');
$config[strtolower($newKey)] = $value;
}
$args['config'] = $config;

Expand Down
11 changes: 2 additions & 9 deletions src/DI/Plugin/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Http\Client\Common\Plugin\CookiePlugin;
use Http\Message\CookieJar;
use Nette\DI\ContainerBuilder;
use Nette\DI\ServiceDefinition;
use Nette\DI\Definitions\Definition;
use Nette\StaticClass;

/**
Expand All @@ -17,19 +17,12 @@ class Cookie implements IPluginServiceDefinitonCreator
{
use StaticClass;

/**
* @param ContainerBuilder $containerBuilder
* @param string $extensionName
* @param string $clientName
* @param array $pluginConfig
* @return ServiceDefinition
*/
public static function createPluginServiceDefinition(
ContainerBuilder $containerBuilder,
string $extensionName,
string $clientName,
array $pluginConfig
): ServiceDefinition {
): Definition {

$cookieJar = $pluginConfig['cookieJar'] ?? new CookieJar();

Expand Down
Loading

0 comments on commit 9314fb8

Please sign in to comment.