diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 00000000..fa081759 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,6 @@ +[codespell] +skip=./.git +check-hidden= +check-filenames= +builtin=clear,rare,informal,usage,code,names +ignore-words-list=master,masters,slave,slaves,whitelist,cas,exat,smove diff --git a/.editorconfig b/.editorconfig index 7bb97fee..0764720b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,3 @@ -# http://editorconfig.org - root = true [*] @@ -9,9 +7,18 @@ indent_size = 4 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true +block_comment_start = /* +block_comment = * +block_comment_end = */ [*.php] max_line_length = 150 [*.{md,yml,yaml,neon}] indent_size = 2 + +[tests/**.php] +max_line_length = unset + +[{src/ClientInterface.php,src/ClientContextInterface.php}] +max_line_length = unset diff --git a/.gitattributes b/.gitattributes index bacce2e2..bab718b3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,16 @@ * text=auto -/tests export-ignore -/.github export-ignore +/.github/ export-ignore +/examples/ export-ignore +/tests/ export-ignore +/.codespellrc export-ignore linguist-language=INI /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.php_cs.dist export-ignore +/.php-cs-fixer.dist.php export-ignore +/CHANGELOG.md export-ignore linguist-documentation +/CONTRIBUTING.md export-ignore linguist-documentation +/FAQ.md export-ignore linguist-documentation +/VERSION export-ignore /phpunit.xml.dist export-ignore +/phpstan.dist.neon export-ignore diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ca74eddc..11cdd3b0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -19,10 +19,10 @@ Steps to reproduce the behavior: A clear and concise description of what you expected to happen. **Versions (please complete the following information):** - - Predis: [e.g. 1.1.2] - - PHP [e.g. 8.0.0] - - Redis Server [e.g. 6.0.0] - - OS [e.g. Ubuntu 20.10] +- Predis: [e.g. 1.1.2] +- PHP [e.g. 8.0.0] +- Redis Server [e.g. 6.0.0] +- OS [e.g. Ubuntu 20.10] **Code sample** If applicable, a small snippet of code that reproduces the issue. diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml deleted file mode 100644 index 94223747..00000000 --- a/.github/workflows/coding-standards.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Linters - -on: - push: - branches: - - main - - v2.** - pull_request: - -jobs: - - php-cs-fixer: - name: PHP CS Fixer - runs-on: ubuntu-latest - - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup PHP with Composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - tools: php-cs-fixer - - - name: Run php-cs-fixer - run: php-cs-fixer fix --diff --dry-run --allow-risky=yes --using-cache=no - - phpstan: - name: PHPStan - runs-on: ubuntu-latest - - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup PHP with Composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - tools: phpstan - coverage: none - - - name: Get Composer cache directory - id: composer-cache - run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT - - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.directory }} - key: tests-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: tests-php-${{ matrix.php }}-composer - - - name: Install Composer dependencies - run: composer install --ansi --no-progress --prefer-dist ${{ matrix.php == '8.0' && '--ignore-platform-reqs' || '' }} - - - name: Run PHPStan - run: phpstan analyse diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 00000000..25e72678 --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,164 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow + +name: Linters + +on: + push: + branches: + - main + - v2.** + pull_request: null + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + + byte_level: + name: Byte-level + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check file permissions + run: test "$(find . -type f -not -path './.git/*' -executable)" = "./bin/create-command-test" + + - name: "Find non-printable ASCII characters" + run: | + ! LC_ALL=C.UTF-8 find . -type f -name '*.php' -print0 \ + | xargs --null -- grep --perl-regexp --with-filename --line-number '[^ -~ü]' + + syntax_errors: + name: Syntax errors + runs-on: ubuntu-latest + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + coverage: none + tools: parallel-lint + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check source code for syntax errors + run: composer exec -- parallel-lint bin/ examples/ src/ tests/ + + static_analysis: + name: Static Analysis + needs: + - byte_level + - syntax_errors + runs-on: ubuntu-latest + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.2" + coverage: none + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Validate Composer configuration + run: composer validate --no-interaction --strict + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + + - name: Check PSR-4 mapping + run: composer dump-autoload --no-interaction --optimize --strict-psr + + - name: Perform static analysis + run: composer run phpstan + + coding_standards: + name: Coding Standards + needs: + - byte_level + - syntax_errors + runs-on: ubuntu-latest + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + coverage: none + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check EditorConfig configuration + run: test -f .editorconfig + + - name: Check adherence to EditorConfig + uses: greut/eclint-action@v0 + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + + - name: Check coding style + run: composer exec -- php-cs-fixer fix --diff --dry-run --allow-risky=yes --using-cache=no + + - name: Search for TODO-s and FIXME-s + run: | + ! git grep --extended-regexp --ignore-case '\b(TODO|FIXME)\b' -- ':/' ':!tests/*' ':!*/linters\.yml' + + exported_files: + name: Exported files + needs: + - byte_level + - syntax_errors + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check exported files + run: | + EXPECTED="LICENSE,README.md,autoload.php,composer.json" + CURRENT="$( + git archive HEAD \ + | tar --list --exclude="src" --exclude="src/*" --exclude="bin" --exclude="bin/*" \ + | paste --serial --delimiters="," + )" + echo "CURRENT =${CURRENT}" + echo "EXPECTED=${EXPECTED}" + test "${CURRENT}" = "${EXPECTED}" + + spelling: + name: Spelling + needs: + - byte_level + - syntax_errors + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-codespell + + - name: Install codespell + run: pip install --user 'codespell>=2.2' + + - name: Search for misspellings + run: $(python -m site --user-base)/bin/codespell diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index bdf32b95..f09d6f06 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -5,6 +5,10 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: update_release_draft: @@ -16,6 +20,6 @@ jobs: - uses: release-drafter/release-drafter@v5 with: - config-name: release-drafter-config.yml + config-name: release-drafter-config.yml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3ba0c658..f26de2b9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,10 +7,14 @@ on: - v2.** pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: predis: - name: PHP ${{ matrix.php }} (Redis ${{ matrix.redis }}) + name: PHP ${{ matrix.php }} Redis ${{ matrix.redis }} runs-on: ubuntu-latest strategy: @@ -24,11 +28,11 @@ jobs: - '8.1' - '8.2' redis: - - 3 - - 4 - - 5 - - 6 - - 7 + - '3' + - '4' + - '5' + - '6' + - '7' services: redis: @@ -39,29 +43,33 @@ jobs: steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v3 - name: Setup PHP with Composer and extensions + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - - - name: Get Composer cache directory - id: composer-cache - run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT - - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.directory }} - key: tests-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: tests-php-${{ matrix.php }}-composer + coverage: ${{ (matrix.php == '8.1' && matrix.redis == '7') && 'xdebug' || 'none' }} - name: Install Composer dependencies - env: - PHP_VERSION: ${{ matrix.php }} - run: composer install --ansi --no-progress --prefer-dist $(if [ "$PHP_VERSION" == "8.0" ]; then echo "--ignore-platform-reqs"; fi;) + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + composer-options: ${{ matrix.php == '8.0' && '--ignore-platform-reqs' || '' }} - name: Run PHPUnit tests - run: vendor/bin/phpunit + if: ${{ matrix.php != '8.1' || matrix.redis != '7' }} + run: vendor/bin/phpunit --verbose + + - name: Run PHPUnit tests with coverage + if: ${{ matrix.php == '8.1' && matrix.redis == '7' }} + run: vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml --coverage-filter src + + - name: Send coverage to Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: ${{ env.COVERALLS_REPO_TOKEN && matrix.php == '8.1' && matrix.redis == '7' }} + run: | + wget "https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.3/php-coveralls.phar" + php ./php-coveralls.phar -v diff --git a/.gitignore b/.gitignore index f6436174..a301785c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/build /vendor .php-version .php_cs.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index c681d6d9..f39b8ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,7 @@ - `cluster`: string value (`predis`, `redis`), callable returning an aggregate connection. - `replication`: string value (`predis`, `sentinel`), callable returning an - aggregate connection. + aggregate connection. - `commands`: command factory, named array mapping command IDs to PHP classes, callable returning a command factory or a named array. - `connections`: connection factory, callable object returning a connection @@ -82,7 +82,7 @@ acting as initializer instead of an aggregate connection instance. - The `connections` client option now accepts certain string values identifying - certain combinations of configurations for the connection factory. Currenlty + certain combinations of configurations for the connection factory. Currently this is used to provide a short way to configure Predis to load our phpiredis based connection backends simply, accepted values are: @@ -107,7 +107,7 @@ supported by the redis-sentinel backend due to its dynamic nature (connections are retrieved and initialized at runtime from sentinels) but it is possible to get a single connection from the pool by using its ID. It is also possible to - retrive a connection by role using the method getConnectionByRole(). + retrieve a connection by role using the method getConnectionByRole(). - The concept of connection ID (ip:port pair) and connection alias (the `alias` parameter) in `Predis\Connection\Cluster\PredisCluster` has been separated. diff --git a/FAQ.md b/FAQ.md index 152f534a..ed96cf31 100644 --- a/FAQ.md +++ b/FAQ.md @@ -4,7 +4,7 @@ ________________________________________________ ### What is the point of Predis? ### The main point of Predis is about offering a highly customizable and extensible client for Redis, -that can be easily extended by developers while still being reasonabily fast. With Predis you can +that can be easily extended by developers while still being reasonably fast. With Predis you can swap almost any class with your own custom implementation: you can have custom connection classes, new distribution strategies for client-side sharding, or handlers to replace or add Redis commands. All of this can be achieved without messing with the source code of the library and directly in your diff --git a/bin/create-command-test b/bin/create-command-test index c678cdc6..262bd53d 100755 --- a/bin/create-command-test +++ b/bin/create-command-test @@ -117,7 +117,7 @@ class CommandTestCaseGenerator protected function getTestRealm() { if (empty($this->options['realm'])) { - throw new RuntimeException('Invalid value for realm has been sepcified (empty).'); + throw new RuntimeException('Invalid value for realm has been specified (empty).'); } return $this->options['realm']; diff --git a/examples/debuggable_connection.php b/examples/debuggable_connection.php index 94ba1786..f0893dc4 100644 --- a/examples/debuggable_connection.php +++ b/examples/debuggable_connection.php @@ -14,7 +14,7 @@ require __DIR__ . '/shared.php'; // This is an example of how you can easily extend an existing connection class // and trace the execution of commands for debugging purposes. This can be quite -// useful as a starting poing to understand how your application interacts with +// useful as a starting point to understand how your application interacts with // Redis. use Predis\Command\CommandInterface; @@ -81,13 +81,13 @@ var_export($client->getConnection()->getDebugBuffer()); /* OUTPUT: array ( - 0 => 'SELECT 15 -> 127.0.0.1:6379 [0.0008s]', - 1 => 'SELECT 15 <- 127.0.0.1:6379 [0.001s]', - 2 => 'SET foo -> 127.0.0.1:6379 [0.001s]', - 3 => 'SET foo <- 127.0.0.1:6379 [0.0011s]', - 4 => 'GET foo -> 127.0.0.1:6379 [0.0013s]', - 5 => 'GET foo <- 127.0.0.1:6379 [0.0015s]', - 6 => 'INFO -> 127.0.0.1:6379 [0.0019s]', - 7 => 'INFO <- 127.0.0.1:6379 [0.0022s]', + 0 => 'SELECT 15 -> 127.0.0.1:6379 [0.0008s]', + 1 => 'SELECT 15 <- 127.0.0.1:6379 [0.001s]', + 2 => 'SET foo -> 127.0.0.1:6379 [0.001s]', + 3 => 'SET foo <- 127.0.0.1:6379 [0.0011s]', + 4 => 'GET foo -> 127.0.0.1:6379 [0.0013s]', + 5 => 'GET foo <- 127.0.0.1:6379 [0.0015s]', + 6 => 'INFO -> 127.0.0.1:6379 [0.0019s]', + 7 => 'INFO <- 127.0.0.1:6379 [0.0022s]', ) */ diff --git a/examples/executing_redis_commands.php b/examples/executing_redis_commands.php index 8acd5241..6841a011 100644 --- a/examples/executing_redis_commands.php +++ b/examples/executing_redis_commands.php @@ -38,10 +38,11 @@ var_export($response); echo PHP_EOL; /* OUTPUT: array ( - 0 => '1st user', - 1 => '2nd user', - 2 => '3rd user', -) */ + 0 => '1st user', + 1 => '2nd user', + 2 => '3rd user', +) +*/ // Predis can also send "raw" commands to Redis. The difference between sending // commands to Redis the usual way and the "raw" way is that in the latter case @@ -55,7 +56,8 @@ var_export($response); echo PHP_EOL; /* OUTPUT: array ( - 0 => '1st user', - 1 => '2nd user', - 2 => '3rd user', -) */ + 0 => '1st user', + 1 => '2nd user', + 2 => '3rd user', +) +*/ diff --git a/examples/key_prefixing.php b/examples/key_prefixing.php index 422cebb3..23d92015 100644 --- a/examples/key_prefixing.php +++ b/examples/key_prefixing.php @@ -23,15 +23,15 @@ $client->mset(['foo' => 'bar', 'lol' => 'wut']); var_export($client->mget('foo', 'lol')); /* array ( - 0 => 'bar', - 1 => 'wut', + 0 => 'bar', + 1 => 'wut', ) */ var_export($client->keys('*')); /* array ( - 0 => 'nrk:foo', - 1 => 'nrk:lol', + 0 => 'nrk:foo', + 1 => 'nrk:lol', ) */ diff --git a/examples/lua_scripting_abstraction.php b/examples/lua_scripting_abstraction.php index 88b53a83..eb0b677b 100644 --- a/examples/lua_scripting_abstraction.php +++ b/examples/lua_scripting_abstraction.php @@ -37,11 +37,11 @@ local cmd, insert = redis.call, table.insert local increment, results = ARGV[1], { } for idx, key in ipairs(KEYS) do - if cmd('exists', key) == 1 then - insert(results, idx, cmd('incrby', key, increment)) - else - insert(results, idx, false) - end + if cmd('exists', key) == 1 then + insert(results, idx, cmd('incrby', key, increment)) + else + insert(results, idx, false) + end end return results @@ -61,8 +61,8 @@ var_export($client->increxby('foo', 'foofoo', 'foobar', 50)); /* array ( - 0 => 60, - 1 => NULL, - 2 => 150, + 0 => 60, + 1 => NULL, + 2 => 150, ) */ diff --git a/examples/pipelining_commands.php b/examples/pipelining_commands.php index dafcf576..a42832a3 100644 --- a/examples/pipelining_commands.php +++ b/examples/pipelining_commands.php @@ -31,16 +31,16 @@ var_export($responses); /* OUTPUT: array ( - 0 => Predis\Response\Status::__set_state(array( - 'payload' => 'OK', - )), - 1 => 10, - 2 => 40, - 3 => true, - 4 => '40', - 5 => array ( - 0 => NULL, - 1 => '40', - ), + 0 => Predis\Response\Status::__set_state(array( + 'payload' => 'OK', + )), + 1 => 10, + 2 => 40, + 3 => true, + 4 => '40', + 5 => array ( + 0 => NULL, + 1 => '40', + ), ) */ diff --git a/examples/redis_collections_iterators.php b/examples/redis_collections_iterators.php index 177de016..bd53c25a 100644 --- a/examples/redis_collections_iterators.php +++ b/examples/redis_collections_iterators.php @@ -48,9 +48,9 @@ foreach (new Iterator\Keyspace($client, 'predis:*') as $key) { /* OUTPUT Scan the keyspace matching only our prefixed keys: - - predis:zset - - predis:set - - predis:hash + - predis:zset + - predis:set + - predis:hash */ // === Set iterator based on SSCAN === @@ -61,11 +61,11 @@ foreach (new Iterator\SetKey($client, 'predis:set') as $member) { /* OUTPUT Scan members of `predis:set`: - - member:1 - - member:4 - - member:0 - - member:3 - - member:2 + - member:1 + - member:4 + - member:0 + - member:3 + - member:2 */ // === Sorted set iterator based on ZSCAN === @@ -76,11 +76,11 @@ foreach (new Iterator\SortedSetKey($client, 'predis:zset') as $member => $rank) /* OUTPUT Scan members and ranks of `predis:zset`: - - member:4 [rank: -4] - - member:3 [rank: -3] - - member:2 [rank: -2] - - member:1 [rank: -1] - - member:0 [rank: 0] + - member:4 [rank: -4] + - member:3 [rank: -3] + - member:2 [rank: -2] + - member:1 [rank: -1] + - member:0 [rank: 0] */ // === Hash iterator based on HSCAN === @@ -91,9 +91,9 @@ foreach (new Iterator\HashKey($client, 'predis:hash') as $field => $value) { /* OUTPUT Scan fields and values of `predis:hash`: - - field:0 => value:0 - - field:1 => value:1 - - field:2 => value:2 - - field:3 => value:3 - - field:4 => value:4 + - field:0 => value:0 + - field:1 => value:1 + - field:2 => value:2 + - field:3 => value:3 + - field:4 => value:4 */ diff --git a/examples/shared.php b/examples/shared.php index c805a50c..e2dfe10a 100644 --- a/examples/shared.php +++ b/examples/shared.php @@ -35,15 +35,15 @@ $single_server = [ $multiple_servers = [ [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'database' => 15, - 'alias' => 'first', + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 15, + 'alias' => 'first', ], [ - 'host' => '127.0.0.1', - 'port' => 6380, - 'database' => 15, - 'alias' => 'second', + 'host' => '127.0.0.1', + 'port' => 6380, + 'database' => 15, + 'alias' => 'second', ], ]; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bd9a342b..1bbd2dd9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,15 @@ - - + @@ -16,6 +17,15 @@ + + + ./src + + + + + + ext-phpiredis diff --git a/src/Client.php b/src/Client.php index 9caa2e49..a00825f8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -358,7 +358,7 @@ class Client implements ClientInterface, IteratorAggregate /** * Executes the specified initializer method on `$this` by adjusting the - * actual invokation depending on the arity (0, 1 or 2 arguments). This is + * actual invocation depending on the arity (0, 1 or 2 arguments). This is * simply an utility method to create Redis contexts instances since they * follow a common initialization path. * diff --git a/src/Configuration/Option/Replication.php b/src/Configuration/Option/Replication.php index 00aa9741..b0f132d1 100644 --- a/src/Configuration/Option/Replication.php +++ b/src/Configuration/Option/Replication.php @@ -108,14 +108,6 @@ class Replication extends Aggregate */ public static function aggregate(OptionsInterface $options, AggregateConnectionInterface $connection, array $nodes) { - // TODO: at least for now we will replicate the previous behaviour of - // skipping automatic aggregation when using the redis-sentinel backend - // because $nodes contains an array of sentinel servers instead of Redis - // servers and SentinelReplication already gets the list of sentinels in - // the first argument of its constructor. SentinelReplication::add() - // actually knows how to handle connections marked with role=sentinel in - // their parameters but relying on it would require an explicit role to - // be set by the user and I would like to avoid enforcing that for now. if (!$connection instanceof SentinelReplication) { parent::aggregate($options, $connection, $nodes); } diff --git a/src/Connection/Cluster/PredisCluster.php b/src/Connection/Cluster/PredisCluster.php index 1fc87f77..0ba29bb5 100644 --- a/src/Connection/Cluster/PredisCluster.php +++ b/src/Connection/Cluster/PredisCluster.php @@ -25,8 +25,6 @@ use ReturnTypeWillChange; /** * Abstraction for a cluster of aggregate connections to various Redis servers * implementing client-side sharding based on pluggable distribution strategies. - * - * @todo Add the ability to remove connections from pool. */ class PredisCluster implements ClusterInterface, IteratorAggregate, Countable { diff --git a/src/Connection/Cluster/RedisCluster.php b/src/Connection/Cluster/RedisCluster.php index adcad65f..e0376940 100644 --- a/src/Connection/Cluster/RedisCluster.php +++ b/src/Connection/Cluster/RedisCluster.php @@ -80,7 +80,7 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable * Sets the maximum number of retries for commands upon server failure. * * -1 = unlimited retry attempts - * 0 = no retry attempts (fails immediatly) + * 0 = no retry attempts (fails immediately) * n = fail only after n retry attempts * * @param int $retry Number of retry attempts. diff --git a/src/Connection/CompositeConnectionInterface.php b/src/Connection/CompositeConnectionInterface.php index dc24844d..22b8c5f7 100644 --- a/src/Connection/CompositeConnectionInterface.php +++ b/src/Connection/CompositeConnectionInterface.php @@ -33,7 +33,7 @@ interface CompositeConnectionInterface extends NodeConnectionInterface /** * Reads the given number of bytes from the connection. * - * @param int $length Number of bytes to read from the connection. + * @param int $length Number of bytes to read from the connection. * * @return string */ diff --git a/src/Connection/Parameters.php b/src/Connection/Parameters.php index 016d8129..170d7e28 100644 --- a/src/Connection/Parameters.php +++ b/src/Connection/Parameters.php @@ -28,7 +28,7 @@ class Parameters implements ParametersInterface ]; /** - * Set of connection paramaters already filtered + * Set of connection parameters already filtered * for NULL or 0-length string values. * * @var array diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index 89fe0481..5dc9d635 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -91,7 +91,7 @@ class SentinelReplication implements ReplicationInterface * Max number of automatic retries of commands upon server failure. * * -1 = unlimited retry attempts - * 0 = no retry attempts (fails immediatly) + * 0 = no retry attempts (fails immediately) * n = fail only after n retry attempts * * @var int @@ -148,7 +148,7 @@ class SentinelReplication implements ReplicationInterface * Sets the maximum number of retries for commands upon server failure. * * -1 = unlimited retry attempts - * 0 = no retry attempts (fails immediatly) + * 0 = no retry attempts (fails immediately) * n = fail only after n retry attempts * * @param int $retry Number of retry attempts. diff --git a/src/Pipeline/Atomic.php b/src/Pipeline/Atomic.php index f5f7f0a5..09e19ead 100644 --- a/src/Pipeline/Atomic.php +++ b/src/Pipeline/Atomic.php @@ -80,7 +80,6 @@ class Atomic extends Pipeline $executed = $connection->executeCommand($commandFactory->create('exec')); if (!isset($executed)) { - // TODO: should be throwing a more appropriate exception. throw new ClientException( 'The underlying transaction has been aborted by the server.' ); diff --git a/src/Pipeline/ConnectionErrorProof.php b/src/Pipeline/ConnectionErrorProof.php index 9e042e72..8f995cf0 100644 --- a/src/Pipeline/ConnectionErrorProof.php +++ b/src/Pipeline/ConnectionErrorProof.php @@ -22,8 +22,6 @@ use SplQueue; /** * Command pipeline that does not throw exceptions on connection errors, but * returns the exception instances as the rest of the response elements. - * - * @todo Awful naming! */ class ConnectionErrorProof extends Pipeline { diff --git a/src/Protocol/Text/ResponseReader.php b/src/Protocol/Text/ResponseReader.php index c70b77b1..f49c96d2 100644 --- a/src/Protocol/Text/ResponseReader.php +++ b/src/Protocol/Text/ResponseReader.php @@ -82,7 +82,7 @@ class ResponseReader implements ResponseReaderInterface $header = $connection->readLine(); if ($header === '') { - $this->onProtocolError($connection, 'Unexpected empty reponse header'); + $this->onProtocolError($connection, 'Unexpected empty response header'); } $prefix = $header[0]; diff --git a/src/Replication/ReplicationStrategy.php b/src/Replication/ReplicationStrategy.php index 4944ba64..9460f200 100644 --- a/src/Replication/ReplicationStrategy.php +++ b/src/Replication/ReplicationStrategy.php @@ -112,7 +112,7 @@ class ReplicationStrategy /** * Checks if a GEORADIUS command is a readable operation by parsing the - * arguments array of the specified commad instance. + * arguments array of the specified command instance. * * @param CommandInterface $command Command instance. * diff --git a/src/Response/Iterator/MultiBulkTuple.php b/src/Response/Iterator/MultiBulkTuple.php index b8b9718a..77019aa8 100644 --- a/src/Response/Iterator/MultiBulkTuple.php +++ b/src/Response/Iterator/MultiBulkTuple.php @@ -22,7 +22,7 @@ use UnexpectedValueException; * keys and values. * * This wrapper is useful for responses to commands such as `HGETALL` that can - * be iterater as $key => $value pairs. + * be iterator as $key => $value pairs. */ class MultiBulkTuple extends MultiBulk implements OuterIterator { diff --git a/tests/PHPUnit/ArrayHasSameValuesConstraint.php b/tests/PHPUnit/ArrayHasSameValuesConstraint.php index ee839888..0f3de1a9 100644 --- a/tests/PHPUnit/ArrayHasSameValuesConstraint.php +++ b/tests/PHPUnit/ArrayHasSameValuesConstraint.php @@ -11,7 +11,7 @@ */ /** - * PHPUnit constraint matching arrays with same elemnts even in different order. + * PHPUnit constraint matching arrays with same elements even in different order. */ class ArrayHasSameValuesConstraint extends \PHPUnit\Framework\Constraint\Constraint { diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index 03856843..aad03117 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -59,7 +59,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase /** * Ensures that two Redis commands are similar. * - * This method supports can test for different contraints by accepting a few + * This method supports can test for different constraints by accepting a few * combinations of values as indicated below: * * - a string identifying a Redis command by its ID @@ -357,9 +357,9 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase public function isRedisServerVersion(string $operator, string $version): bool { $serverVersion = $this->getRedisServerVersion(); - $comparation = version_compare($serverVersion, $version); + $comparison = version_compare($serverVersion, $version); - return (bool) eval("return $comparation $operator 0;"); + return (bool) eval("return $comparison $operator 0;"); } /** diff --git a/tests/Predis/Command/RawCommandTest.php b/tests/Predis/Command/RawCommandTest.php index f7597108..b316d2db 100644 --- a/tests/Predis/Command/RawCommandTest.php +++ b/tests/Predis/Command/RawCommandTest.php @@ -58,7 +58,7 @@ class RawCommandTest extends PredisTestCase /** * The signature of RawCommand::create() requires one argument which is the - * ID of the command (other arguments are fetched dinamically). If the first + * ID of the command (other arguments are fetched dynamically). If the first * argument is missing a standard PHP exception is thrown on PHP >= 7.1. * * @group disconnected diff --git a/tests/Predis/Command/Redis/PEXPIRE_Test.php b/tests/Predis/Command/Redis/PEXPIRE_Test.php index 158a4fd6..bc41b381 100644 --- a/tests/Predis/Command/Redis/PEXPIRE_Test.php +++ b/tests/Predis/Command/Redis/PEXPIRE_Test.php @@ -88,25 +88,25 @@ class PEXPIRE_Test extends PredisCommandTestCase $this->assertSame(0, $redis->exists('foo')); } - /** - * @medium - * @group connected - * @requiresRedisVersion >= 2.6.0 - * @group slow - */ - public function testConsistencyWithTTL(): void - { - $ttl = 1000; - $redis = $this->getClient(); + /** + * @medium + * @group connected + * @requiresRedisVersion >= 2.6.0 + * @group slow + */ + public function testConsistencyWithTTL(): void + { + $ttl = 1000; + $redis = $this->getClient(); - $this->assertEquals('OK', $redis->set('foo', 'bar')); - $this->assertSame(1, $redis->pexpire('foo', $ttl)); + $this->assertEquals('OK', $redis->set('foo', 'bar')); + $this->assertSame(1, $redis->pexpire('foo', $ttl)); - $this->sleep(0.5); - $this->assertThat($redis->pttl('foo'), $this->logicalAnd( - $this->lessThanOrEqual($ttl), $this->greaterThan($ttl - 800) - )); - } + $this->sleep(0.5); + $this->assertThat($redis->pttl('foo'), $this->logicalAnd( + $this->lessThanOrEqual($ttl), $this->greaterThan($ttl - 800) + )); + } /** * @group connected diff --git a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php index 92cf1531..d60e4ad6 100644 --- a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php @@ -269,7 +269,7 @@ class ZRANGESTORE_Test extends PredisCommandTestCase { return [ 'wrong BY argument value' => [ - 0, -1, 'wrong value', false, false, 0, 0, 'By argument accepts only "bylex" and "byscore" values', + 0, -1, 'wrong value', false, false, 0, 0, 'By argument accepts only "bylex" and "byscore" values', ], 'wrong REV argument type' => [ 0, -1, false, 'wrong value', false, 0, 0, 'Wrong rev argument type', diff --git a/tests/Predis/Connection/Cluster/RedisClusterTest.php b/tests/Predis/Connection/Cluster/RedisClusterTest.php index fbadbb35..7cf28a66 100644 --- a/tests/Predis/Connection/Cluster/RedisClusterTest.php +++ b/tests/Predis/Connection/Cluster/RedisClusterTest.php @@ -707,12 +707,12 @@ class RedisClusterTest extends PredisTestCase $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory ->expects($this->once()) - ->method('create') - ->with([ + ->method('create') + ->with([ 'host' => '127.0.0.1', 'port' => '9381', - ]) - ->willReturn($connection4); + ]) + ->willReturn($connection4); // TODO: I'm not sure about mocking a protected method, but it'll do for now /** @var Connection\Cluster\RedisCluster|MockObject */ diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index 32620456..4d98dd6f 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -557,7 +557,7 @@ class FactoryTest extends PredisTestCase /** * Provides empty values for specific parameters. * - * These parameters usually trigger the addition of initializatin commands + * These parameters usually trigger the addition of initialization commands * to connection instances like `password` => AUTH and `database` => SELECT, * but they should not be added when their values are NULL or empty strings. * diff --git a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php index a8249484..0aea2273 100644 --- a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php @@ -838,7 +838,7 @@ class MasterSlaveReplicationTest extends PredisTestCase { $master = $this->getMockConnection('tcp://127.0.0.1:6379?role=master'); $master->expects($this->never()) - ->method('executeCommand'); + ->method('executeCommand'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6380?role=slave'); $slave1 diff --git a/tests/Predis/Connection/Replication/SentinelReplicationTest.php b/tests/Predis/Connection/Replication/SentinelReplicationTest.php index 941ae105..1dcc532c 100644 --- a/tests/Predis/Connection/Replication/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Replication/SentinelReplicationTest.php @@ -692,7 +692,7 @@ class SentinelReplicationTest extends PredisTestCase 'port' => '6382', 'role' => 'slave', ]) - ->willReturn($slave1); + ->willReturn($slave1); $replication = $this->getReplicationConnection('svc', [$sentinel1], $factory); @@ -1165,9 +1165,9 @@ class SentinelReplicationTest extends PredisTestCase ->withConsecutive( [$this->isRedisCommand('SET', ['key', $cmdGetResponse])] ) - ->willReturnOnConsecutiveCalls( - $cmdSetResponse - ); + ->willReturnOnConsecutiveCalls( + $cmdSetResponse + ); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave'); $slave1 @@ -1180,9 +1180,9 @@ class SentinelReplicationTest extends PredisTestCase ->withConsecutive( [$this->isRedisCommand('GET', ['key'])] ) - ->willReturnOnConsecutiveCalls( - $cmdGetResponse - ); + ->willReturnOnConsecutiveCalls( + $cmdGetResponse + ); $replication = $this->getReplicationConnection('svc', [$sentinel1]); diff --git a/tests/Predis/Protocol/Text/ResponseReaderTest.php b/tests/Predis/Protocol/Text/ResponseReaderTest.php index d28cd312..119dc73a 100644 --- a/tests/Predis/Protocol/Text/ResponseReaderTest.php +++ b/tests/Predis/Protocol/Text/ResponseReaderTest.php @@ -79,7 +79,7 @@ class ResponseReaderTest extends PredisTestCase public function testEmptyResponseHeader(): void { $this->expectException('Predis\Protocol\ProtocolException'); - $this->expectExceptionMessage('Unexpected empty reponse header [tcp://127.0.0.1:6379]'); + $this->expectExceptionMessage('Unexpected empty response header [tcp://127.0.0.1:6379]'); $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379'); $connection diff --git a/tests/README.md b/tests/README.md index a1ef1d9b..5d2e46a1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -94,4 +94,4 @@ matches its group, as defined by the Redis documentation. Valid realms are: When unsure about which value to use for `--realm` for a specific command, you can just infer it by searching in [`commands.json`](https://github.com/redis/redis-doc/blob/master/commands.json) for the -`group` attribute of the corrisponding command as use its value. +`group` attribute of the corresponding command as use its value.