Skip to content

Commit

Permalink
Merge pull request #103 from PavelJurasek/php8
Browse files Browse the repository at this point in the history
Podpora PHP 8
  • Loading branch information
Spamercz authored Aug 18, 2021
2 parents 3faabce + 6a25b6d commit 494a5a6
Show file tree
Hide file tree
Showing 21 changed files with 342 additions and 323 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Package CI

on:
pull_request:

jobs:
checks:
name: Checks
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 7.4, 8.0 ]
redis-version: [4, 5, 6]
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: redis

- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}

- run: composer update --no-interaction --no-suggest --no-progress --prefer-dist

- if: matrix.php == '8.0'
run: make phpcs

- if: matrix.php == '8.0'
run: make lint

- if: matrix.php == '8.0'
run: make phpstan

- run: make run-tests

- if: matrix.php == '8.0'
run: make coveralls || true
67 changes: 0 additions & 67 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
phpcs:
vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src tests

lint:
vendor/bin/parallel-lint -e php,phpt --exclude vendor .

phpstan:
vendor/bin/phpstan analyse -l 2 -c phpstan.neon src tests/KdybyTests

run-tests:
vendor/bin/tester -s -C ./tests/KdybyTests/

coveralls:
vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml
20 changes: 7 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@
"issues": "https://github.com/kdyby/redis/issues"
},
"require": {
"php": ">=7.1",
"php": ">=7.4",
"ext-redis": "*",
"nette/di": "~2.4.10 || ~3.0",
"nette/di": "~3.0",
"nette/caching": "~3.0",
"nette/http": "~2.4.7 || ~3.0",
"nette/http": "~3.0",
"nette/utils": "~3.0"
},
"suggest": {
"ext-redis": "The php redis extension https://github.com/nicolasff/phpredis/ is required for connecting to redis server"
},
"require-dev": {
"nette/bootstrap": "~2.4 || ~3.0",
"nette/bootstrap": "~3.0",
"nette/deprecated": "~3.0",
"nette/php-generator": "~3.0",
"tracy/tracy": "~2.4",

"kdyby/coding-standard": "dev-master",
"slevomat/coding-standard": "dev-master",
"nette/tester": "^2.3.1",
"phpstan/phpstan": "^0.12",
"php-parallel-lint/php-parallel-lint": "dev-master",
"php-coveralls/php-coveralls": "^2.1",
"typo3/class-alias-loader": "^1.0"
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
"psr-4": {
Expand All @@ -51,14 +49,10 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
},
"typo3/class-alias-loader": {
"class-alias-maps": [
"src/Kdyby/Redis/DI/ClassAliasMap.php"
]
}
}
}
10 changes: 1 addition & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@ parameters:
- '#Result of function usleep \(void\) is used.#'
- '#Constant TEMP_DIR not found.#'
- '#Unsafe usage of new static\(\).#'
-
message: '#Negated boolean expression is always true.#'
path: src/Kdyby/Redis/ExclusiveLock.php

excludes_analyse:
- src/Kdyby/Redis/DI/ClassAliasMap.php
# PhpRedisDriverOld can't be verified because it overrides class Redis from phpredis older than 4.0
- src/Kdyby/Redis/Driver/PhpRedisDriverOld.php

reportUnmatchedIgnoredErrors: FALSE
reportUnmatchedIgnoredErrors: TRUE
8 changes: 6 additions & 2 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Kdyby/Console">
<rule ref="vendor/kdyby/coding-standard/ruleset.xml"/>
<ruleset name="Kdyby/Redis">
<rule ref="SlevomatCodingStandard.Files.LineLength">
<properties>
<property name="lineLengthLimit" value="260"></property>
</properties>
</rule>
</ruleset>
14 changes: 0 additions & 14 deletions src/Kdyby/Redis/DI/ClassAliasMap.php

This file was deleted.

79 changes: 79 additions & 0 deletions src/Kdyby/Redis/DI/Config/ClientSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php declare(strict_types = 1);

namespace Kdyby\Redis\DI\Config;

class ClientSchema implements \Nette\Schema\Schema
{

private \Nette\DI\ContainerBuilder $builder;


public function __construct(\Nette\DI\ContainerBuilder $builder)
{
$this->builder = $builder;
}

public function normalize($value, \Nette\Schema\Context $context)
{
if (\array_key_exists('host', $value) && $value['host'][0] === '/') {
$value['port'] = NULL; // sockets have no ports

} elseif ( ! \array_key_exists('port', $value)) {
$value['port'] = \Kdyby\Redis\RedisClient::DEFAULT_PORT;
}

return $value;
}


public function merge($value, $base)
{
return \Nette\Schema\Helpers::merge($value, $base);
}


public function complete($value, \Nette\Schema\Context $context)
{
$value = $this->expandParameters($value);

$value = $this->getSchema()->complete($value, $context);

return $value;
}


public function completeDefault(\Nette\Schema\Context $context)
{

}

private function expandParameters(array $config): array
{
$params = $this->builder->parameters;
if (isset($config['parameters'])) {
foreach ((array) $config['parameters'] as $k => $v) {
$v = \explode(' ', \is_int($k) ? $v : $k);
$params[\end($v)] = $this->builder::literal('$' . \end($v));
}
}
return \Nette\DI\Helpers::expand($config, $params);
}

private function getSchema(): \Nette\Schema\Schema
{
return \Nette\Schema\Expect::structure([
'host' => \Nette\Schema\Expect::string('127.0.0.1'),
'port' => \Nette\Schema\Expect::int()->nullable(),
'timeout' => \Nette\Schema\Expect::int(10),
'database' => \Nette\Schema\Expect::int(0),
'auth' => \Nette\Schema\Expect::string()->nullable(),
'persistent' => \Nette\Schema\Expect::bool(FALSE),
'connectionAttempts' => \Nette\Schema\Expect::int(1),
'lockDuration' => \Nette\Schema\Expect::int(15),
'lockAcquireTimeout' => \Nette\Schema\Expect::bool(FALSE),
'debugger' => \Nette\Schema\Expect::bool($this->builder->parameters['debugMode']),
'versionCheck' => \Nette\Schema\Expect::bool(TRUE),
]);
}

}
98 changes: 98 additions & 0 deletions src/Kdyby/Redis/DI/Config/RedisSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php declare(strict_types = 1);

namespace Kdyby\Redis\DI\Config;

class RedisSchema implements \Nette\Schema\Schema
{

private \Nette\DI\ContainerBuilder $builder;

private ?\Nette\Schema\Schema $schema = NULL;


public function __construct(\Nette\DI\ContainerBuilder $builder)
{
$this->builder = $builder;
}

public function normalize($value, \Nette\Schema\Context $context)
{
$keys = [
'host',
'port',
'timeout',
'database',
'auth',
'persistent',
'connectionAttempts',
'lockDuration',
'lockAcquireTimeout',
'debugger',
'versionCheck',
];

$client = [];

foreach ($keys as $key) {
if (\array_key_exists($key, $value)) {
$client[$key] = $value[$key];
unset($value[$key]);
}
}

$value['clients'][NULL] = $client;

return $this->getSchema()->normalize($value, $context);
}


public function merge($value, $base)
{
return \Nette\Schema\Helpers::merge($value, $base);
}


public function complete($value, \Nette\Schema\Context $context)
{
$value = $this->expandParameters($value);

$value = $this->getSchema()->complete($value, $context);

return $value;
}


public function completeDefault(\Nette\Schema\Context $context)
{

}

private function expandParameters(array $config): array
{
$params = $this->builder->parameters;
if (isset($config['parameters'])) {
foreach ((array) $config['parameters'] as $k => $v) {
$v = \explode(' ', \is_int($k) ? $v : $k);
$params[\end($v)] = $this->builder::literal('$' . \end($v));
}
}
return \Nette\DI\Helpers::expand($config, $params);
}

private function getSchema(): \Nette\Schema\Schema
{
if ($this->schema === NULL) {
$this->schema = \Nette\Schema\Expect::structure([
'journal' => \Nette\Schema\Expect::bool(FALSE),
'storage' => \Nette\Schema\Expect::bool(FALSE),
'session' => \Nette\Schema\Expect::bool(FALSE),
'clients' => \Nette\Schema\Expect::arrayOf(
new \Kdyby\Redis\DI\Config\ClientSchema($this->builder)
)->default([]),
]);
}

return $this->schema;
}

}
Loading

0 comments on commit 494a5a6

Please sign in to comment.