Skip to content

Commit

Permalink
Merge pull request #5 from softonic/compatible-with-psr/cache-2-and-3
Browse files Browse the repository at this point in the history
Added compatibility with psr/cache v2 and v3
  • Loading branch information
xaviapa authored Nov 22, 2023
2 parents 543cff7 + 01c513b commit a9e082b
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 155 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer run-script test
35 changes: 35 additions & 0 deletions .github/workflows/init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Init Project

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
- name: Git Commit/Push Changes
uses: actions/checkout@v3

- name: Substitute placeholders
run: |
name=$(echo ${{ github.event.repository.name }} | sed -e "s/[-_]/ /g" -e "s/\b\(.\)/\u\1/g")
namespace=$(echo ${{ github.event.repository.name }} | sed -e "s/[-_]/ /g" -e "s/\b\(.\)/\u\1/g" -e "s/ //g")
description=$(echo ${{ github.event.repository.description }} | sed -e 's@/@\\/@g')
sed -i -e "s/<PACKAGE-ID>/${{ github.event.repository.name }}/g" -e "s/<DESCRIPTION>/$description/g" -e "s/<NAMESPACE>/$namespace/g" composer.json
sed -i -e "s/<PACKAGE-ID>/${{ github.event.repository.name }}/g" -e "s/<DESCRIPTION>/$description/g" -e "s/<PACKAGE-NAME>/$name/g" README.md
sed -i "s/<PACKAGE-NAME>/$name/g" phpunit.xml
sed -i "s/<AUTHOR>/${{ github.actor }}/g" CODEOWNERS
git rm .github/workflows/init.yml
- name: Git Commit/Push Changes
uses: actions-x/commit@v6
with:
message: Applied template for basic configuration
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/vendor
/build
composer.lock
.php_cs.cache
*.cache
*.lock
vendor
build
9 changes: 4 additions & 5 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
Expand All @@ -15,21 +15,20 @@
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'ordered_imports' => ['importsOrder' => null, 'sortAlgorithm' => 'alpha'],
'ordered_imports' => ['imports_order' => null, 'sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'psr0' => false,
'psr4' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
Expand Down
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2019 Softonic International S.A.
Copyright 2021 Softonic International S.A.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -10,4 +10,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: phpunit
phpunit:
docker-compose run composer run phpunit

.PHONY: tests
tests:
docker-compose run composer run test

.PHONY: debug
debug:
docker-compose run --entrypoint=bash composer

.PHONY: update-dependencies
update-dependencies:
docker-compose run composer update

.PHONY: checkstyle
checkstyle:
docker-compose run composer run checkstyle

.PHONY: fix-checkstyle
fix-checkstyle:
docker-compose run composer run fix-checkstyle
30 changes: 20 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"issues": "https://github.com/softonic/guzzle-proxy-middleware/issues"
},
"require": {
"php": ">=7.1",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"psr/cache": "^1.0"
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.0",
"psr/cache": "^1.0|^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.0",
"friendsofphp/php-cs-fixer": "^2.4",
"friendsofphp/php-cs-fixer": "^3.6",
"squizlabs/php_codesniffer": "^3",
"phpstan/phpstan": "^0.10.1"
"rector/rector": "^0.11.20"
},
"autoload": {
"psr-4": {
Expand All @@ -31,10 +31,20 @@
}
},
"scripts": {
"test": "phpunit --coverage-text; php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
"phpstan": "phpstan analyse -l 7 src --no-interaction --no-progress",
"test": [
"@checkstyle",
"@phpunit"
],
"phpunit": "phpunit --coverage-text",
"phpcs": "php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
"fix-cs": "php-cs-fixer fix -v --diff --allow-risky=yes;"
"checkstyle": [
"php-cs-fixer fix -v --diff --dry-run --allow-risky=yes",
"rector --dry-run"
],
"fix-checkstyle": [
"@php-cs-fixer",
"@rector"
],
"php-cs-fixer": "php-cs-fixer fix -v --diff --allow-risky=yes",
"rector": "rector"
}
}
20 changes: 4 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
version: '3.2'
version: '3.8'

services:
test:
composer:
volumes:
- ./:/app
image: ricc/composer-prestissimo:latest
command: composer run test

fixcs:
volumes:
- ./:/app
image: ricc/composer-prestissimo:latest
command: composer run fix-cs

psysh:
volumes:
- ./:/app
image: ricc/psysh:latest
- ./:/app
image: softonic/composer-rector:latest
18 changes: 10 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
<report>
<clover outputFile="./build/clover.xml"/>
<html outputDirectory="./build/coverage"/>
<text outputFile="./build/coverage.txt" />
</report>
</coverage>

<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/clover.xml"/>
<junit outputFile="./build/report.junit.xml"/>
</logging>

</phpunit>
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();

// Define what rule sets will be applied
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_80);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::PRIVATIZATION);

// get services (needed for register a single rule)
// $services = $containerConfigurator->services();

// register a single rule
// $services->set(TypedPropertyRector::class);
};
4 changes: 3 additions & 1 deletion src/Exceptions/ProxiesNotAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Softonic\Proxy\Guzzle\Middleware\Exceptions;

class ProxiesNotAvailable extends \UnexpectedValueException
use UnexpectedValueException;

class ProxiesNotAvailable extends UnexpectedValueException
{
}
2 changes: 1 addition & 1 deletion src/ProxyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(ProxyInterface $proxy)
public function __invoke(callable $handler)
{
return function (RequestInterface $request, array $options) use ($handler) {
$proxy = $this->proxy->get();
$proxy = $this->proxy->get();
$options['proxy'] = $proxy;

return $handler($request, $options);
Expand Down
34 changes: 5 additions & 29 deletions src/Repositories/ProxyBonanza.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,12 @@ class ProxyBonanza implements ProxyInterface
*/
const CACHE_TTL = 14400;

/**
* @var GuzzleClient
*/
private $client;

/**
* @var CacheItemPoolInterface
*/
private $cache;

/**
* @var string
*/
private $userPackage;

/**
* @var string
*/
private $apiKey;

public function __construct(
GuzzleClient $client,
CacheItemPoolInterface $cache,
string $userPackage,
string $apiKey
private readonly GuzzleClient $client,
private readonly CacheItemPoolInterface $cache,
private readonly string $userPackage,
private readonly string $apiKey
) {
$this->client = $client;
$this->cache = $cache;
$this->userPackage = $userPackage;
$this->apiKey = $apiKey;
}

public function get()
Expand All @@ -72,7 +48,7 @@ protected function getFreshProxyList(): array
throw new ProxiesNotAvailable('Proxy response was not successful');
}

$login = $body['data']['login'];
$login = $body['data']['login'];
$password = $body['data']['password'];

$proxiesList = [];
Expand Down
Loading

0 comments on commit a9e082b

Please sign in to comment.