Skip to content

Commit

Permalink
Merge pull request #91 from ackintosh/feature/php-cs-in-github-actions
Browse files Browse the repository at this point in the history
Run php-cs-fixer in GitHub Actions workflow
  • Loading branch information
ackintosh committed Dec 1, 2021
2 parents a11f1c4 + dabca4a commit 8703115
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 39 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code style check

on:
push:
branches:
- master
pull_request:

jobs:
phpcs:
name: Code style check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# https://github.com/shivammathur/setup-php
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: composer
env:
fail-fast: true

- name: Update dependencies with composer
run: composer update

- name: Run php-cs-fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff .
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:

# https://github.com/php-coveralls/php-coveralls#github-actions
- name: Upload coverage results to Coveralls
# NOTE: For now we would run this step only on php7.4 due to the error on php8.
# https://github.com/ackintosh/ganesha/runs/4375377952?check_suite_focus=true
# > PHP Fatal error: Declaration of PhpCoveralls\Bundle\CoverallsBundle\Console\Application::getDefinition() must be compatible with ...
if: ${{ matrix.php-version == '7.4' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ GTAGS
.DS_Store
.idea
/tmp

.php-cs-fixer.cache
6 changes: 2 additions & 4 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
->in(__DIR__)
;

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
$config = new PhpCsFixer\Config();
return $config->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
])
->setFinder($finder)
;

return $config;
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ before_script:

script:
- vendor/bin/phpunit

jobs:
include:
- stage: Coding Standards
php: 7.3
install:
- travis_retry wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer
script:
- php php-cs-fixer -v --diff fix --config=.php_cs.dist --dry-run --no-interaction
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"php-coveralls/php-coveralls": "~2.0",
"predis/predis": "^1.1",
"guzzlehttp/guzzle": "~6.5",
"friendsofphp/php-cs-fixer": "^v3.1.0",
"vimeo/psalm" : "*",
"ext-redis": "~5.1",
"ext-memcached": "~3.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/server/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
$url = 'http://'.$_SERVER['HTTP_HOST'].'/server/redirect.php?redirects='.$redirects.'&current='.++$current;
header('Status: 301 Moved Permanently', false, 301);
header('Location: '.$url);
exit;
exit;
1 change: 0 additions & 1 deletion src/Ganesha/Context.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Ackintosh\Ganesha;


use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface;
use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface;
use Ackintosh\Ganesha\Storage\AdapterInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Ganesha/HttpClient/FailureDetectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function isFailureResponse(ResponseInterface $response, array $requestOpt
* @return string[]
*/
public function getOptionKeys(): array;
}
}
2 changes: 1 addition & 1 deletion src/Ganesha/HttpClient/HostTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public static function extractHostFromUrl(string $url): string

return $host;
}
}
}
2 changes: 1 addition & 1 deletion src/Ganesha/HttpClient/TransportFailureDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function isFailureResponse(ResponseInterface $response, array $requestOpt
return true;
}
}
}
}
4 changes: 3 additions & 1 deletion src/Ganesha/Storage/Adapter/Apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public function reset(): void
{
$keyPrefix = preg_quote($this->storageKeys->prefix(), '/');
$keySuffixes = array_map(
function (string $s) { return preg_quote($s, '/'); },
function (string $s) {
return preg_quote($s, '/');
},
[
$this->storageKeys->success(),
$this->storageKeys->failure(),
Expand Down
2 changes: 1 addition & 1 deletion src/Ganesha/Storage/Adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function reset(): void

/**
* @param string $service
*
*
* @throws StorageException
*/
private function removeExpiredElements(string $service): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Ackintosh/Ganesha/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public function withCountStrategy()
Builder::withCountStrategy()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected function setUp(): void
*/
abstract protected function getRedisConnection();

private function createAdapterWithMock(MockObject $mock): Redis {
private function createAdapterWithMock(MockObject $mock): Redis
{
$adapter = new Redis($mock);
$adapter->setContext($this->context);
return $adapter;
Expand Down
32 changes: 25 additions & 7 deletions tests/Ackintosh/Ganesha/Strategy/Count/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,31 @@ class BuilderTest extends TestCase
public function storageKeys()
{
$storageKeys = new class implements StorageKeysInterface {
public function prefix(): string { return "test"; }
public function success(): string { return "test"; }
public function failure(): string { return "test"; }
public function rejection(): string { return "test"; }
public function lastFailureTime(): string { return "test"; }
public function status(): string { return "test"; }
public function prefix(): string
{
return "test";
}
public function success(): string
{
return "test";
}
public function failure(): string
{
return "test";
}
public function rejection(): string
{
return "test";
}
public function lastFailureTime(): string
{
return "test";
}
public function status(): string
{
return "test";
}
};
$this->assertInstanceOf('Ackintosh\Ganesha\Strategy\Count\Builder', (new Builder)->storageKeys($storageKeys));
}
}
}
32 changes: 25 additions & 7 deletions tests/Ackintosh/Ganesha/Strategy/Rate/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,31 @@ class BuilderTest extends TestCase
public function storageKeys()
{
$storageKeys = new class implements StorageKeysInterface {
public function prefix(): string { return "test"; }
public function success(): string { return "test"; }
public function failure(): string { return "test"; }
public function rejection(): string { return "test"; }
public function lastFailureTime(): string { return "test"; }
public function status(): string { return "test"; }
public function prefix(): string
{
return "test";
}
public function success(): string
{
return "test";
}
public function failure(): string
{
return "test";
}
public function rejection(): string
{
return "test";
}
public function lastFailureTime(): string
{
return "test";
}
public function status(): string
{
return "test";
}
};
$this->assertInstanceOf('Ackintosh\Ganesha\Strategy\Rate\Builder', (new Builder)->storageKeys($storageKeys));
}
}
}
6 changes: 4 additions & 2 deletions tests/Ackintosh/Ganesha/Traits/BuildGaneshaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class BuildGaneshaTest extends TestCase
/**
* @test
*/
public function validateThrowsExceptionWhenRequirementsAreNotSatisfied() {
public function validateThrowsExceptionWhenRequirementsAreNotSatisfied()
{
$this->expectExceptionMessage('adapter is required');
$this->expectException(\LogicException::class);

Expand All @@ -21,7 +22,8 @@ public function validateThrowsExceptionWhenRequirementsAreNotSatisfied() {
/**
* @test
*/
public function validateThrowsExceptionWhenAdapterRequirementsAreNotSatisfied() {
public function validateThrowsExceptionWhenAdapterRequirementsAreNotSatisfied()
{
$this->expectExceptionMessage("Ackintosh\Ganesha\Storage\Adapter\Redis doesn't support expected Strategy: supportCountStrategy");
$this->expectException(\InvalidArgumentException::class);

Expand Down

0 comments on commit 8703115

Please sign in to comment.