Skip to content

Commit

Permalink
Add PHP-CS-Fixer to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmollenhour committed Jan 18, 2023
1 parent dd4fe9b commit 6bc6f63
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
- name: Run PHPUnit test suite
run: composer run-script test

- name: Run PHP CS Fixer
run: composer run-script php-cs-fixer -- --dry-run
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.4.0|configurator
* you can change this configuration by importing this file.
*/
$config = new PhpCsFixer\Config();
return $config
->setRules([
'@PSR12' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in([
'Cm/',
'tests/',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
);
40 changes: 20 additions & 20 deletions Cm/Cache/Backend/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@
*/
class Cm_Cache_Backend_Redis extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
const SET_IDS = 'zc:ids';
const SET_TAGS = 'zc:tags';
public const SET_IDS = 'zc:ids';
public const SET_TAGS = 'zc:tags';

const PREFIX_KEY = 'zc:k:';
const PREFIX_TAG_IDS = 'zc:ti:';
public const PREFIX_KEY = 'zc:k:';
public const PREFIX_TAG_IDS = 'zc:ti:';

const FIELD_DATA = 'd';
const FIELD_MTIME = 'm';
const FIELD_TAGS = 't';
const FIELD_INF = 'i';
public const FIELD_DATA = 'd';
public const FIELD_MTIME = 'm';
public const FIELD_TAGS = 't';
public const FIELD_INF = 'i';

const MAX_LIFETIME = 2592000; /* Redis backend limit */
const COMPRESS_PREFIX = ":\x1f\x8b";
const DEFAULT_CONNECT_TIMEOUT = 2.5;
const DEFAULT_CONNECT_RETRIES = 1;
public const MAX_LIFETIME = 2592000; /* Redis backend limit */
public const COMPRESS_PREFIX = ":\x1f\x8b";
public const DEFAULT_CONNECT_TIMEOUT = 2.5;
public const DEFAULT_CONNECT_RETRIES = 1;

const LUA_SAVE_SH1 = '1617c9fb2bda7d790bb1aaa320c1099d81825e64';
const LUA_CLEAN_SH1 = '39383dcf36d2e71364a666b2a806bc8219cd332d';
const LUA_GC_SH1 = '6990147f5d1999b936dac3b6f7e5d2071908bcf3';
public const LUA_SAVE_SH1 = '1617c9fb2bda7d790bb1aaa320c1099d81825e64';
public const LUA_CLEAN_SH1 = '39383dcf36d2e71364a666b2a806bc8219cd332d';
public const LUA_GC_SH1 = '6990147f5d1999b936dac3b6f7e5d2071908bcf3';

/** @var Credis_Client */
protected $_redis;
Expand Down Expand Up @@ -1294,15 +1294,15 @@ protected function _encodeData($data, $level)
if ($this->_compressionLib && $level !== 0 && strlen($data) >= $this->_compressThreshold) {
switch($this->_compressionLib) {
case 'snappy': $data = snappy_compress($data);
break;
break;
case 'lzf': $data = lzf_compress($data);
break;
break;
case 'l4z': $data = lz4_compress($data, $level);
break;
break;
case 'zstd': $data = zstd_compress($data, $level);
break;
break;
case 'gzip': $data = gzcompress($data, $level);
break;
break;
default: throw new CredisException("Unrecognized 'compression_lib'.");
}
if (! $data) {
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM php:8.1-alpine
COPY --from=composer /usr/bin/composer /usr/bin/composer
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ As this backend uses [Credis](https://github.com/colinmollenhour/credis) there a

Add the package as a dependency to your project with Composer.

```
$ composer require colinmollenhour/cache-backend-redis
```shell
composer require colinmollenhour/cache-backend-redis
```

### modman

It is not the recommended method, but you may install via [modman](https://github.com/colinmollenhour/modman):

* `modman clone https://github.com/colinmollenhour/Cm_Cache_Backend_Redis`
```shell
modman clone https://github.com/colinmollenhour/Cm_Cache_Backend_Redis
```

# CONFIGURATION

Expand Down Expand Up @@ -218,15 +220,22 @@ to read from rather than using md5 hash of the keys.

Please feel free to send Pull Requests to give back your improvements to the community!

You can run the unit tests locally with just Docker installed like so:
You can run the unit tests locally with just Docker installed using a simple alias:

```shell
alias cm-cache-backend-redis='docker run --rm -it -e REDIS_SERVER=host.docker.internal -u $(id -u):$(id -g) -v ${COMPOSER_HOME:-$HOME/.composer}:/tmp -v $(pwd):/app --workdir /app cm-cache-backend-redis'
docker build . -t cm-cache-backend-redis
```
$ docker run --rm -it -u $(id -u):$(id -g) -v ${COMPOSER_HOME:-$HOME/.composer}:/tmp -v $(pwd):/app composer install
$ docker run --rm -d -p 6379 redis
$ docker run --rm -v $(pwd):/app --workdir /app -e REDIS_SERVER=host.docker.internal php:8.2-cli ./vendor/bin/phpunit tests

Then start a Redis server, install Composer dependencies and run tests like so:
```shell
docker run --rm -d -p 6379 --name cm-cache-backend-redis redis
cm-cache-backend-redis composer install
cm-cache-backend-redis composer run-script test
cm-cache-backend-redis composer run-script php-cs-fixer -- --dry-run
```

```
@copyright Copyright (c) 2022 Colin Mollenhour (http://colin.mollenhour.com)
@copyright Copyright (c) 2022 Colin Mollenhour
This project is licensed under the "New BSD" license (see source).
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
},
"scripts": {
"test": "vendor/bin/phpunit tests",
"php-cs-fixer": "php-cs-fixer --rules=@PSR2"
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff"
}
}
4 changes: 3 additions & 1 deletion tests/CommonBackendTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
use PHPUnit\Framework\TestCase;

abstract class CommonBackendTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/CommonExtendedBackendTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require_once 'vendor/autoload.php';
require_once 'CommonBackendTest.php';

Expand Down
2 changes: 1 addition & 1 deletion tests/RedisBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
class RedisBackendTest extends CommonExtendedBackendTest
{
const LUA_MAX_C_STACK = 1000;
public const LUA_MAX_C_STACK = 1000;

protected $forceStandalone = false;

Expand Down

0 comments on commit 6bc6f63

Please sign in to comment.