Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs folder standardization and other fixes #66

Merged
merged 10 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
Copyright © 2008 by Yii Software (<https://www.yiiframework.com/>)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software nor the names of its
* Neither the name of Yii Software nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

Expand Down
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,27 @@ a distributed applications (e.g. with several servers, load balancers, etc.).

The package could be installed with composer:

```
```shell
composer require yiisoft/cache-memcached
```

## Development environment
samdark marked this conversation as resolved.
Show resolved Hide resolved

For greater ease it is recommended to use docker containers.

Run container with memcached directly via command:

```dockerfile
docker run --rm --name yiisoft-cache-memcached-cache --detach --publish 11211:11211 memcached:1.6.23
```

Memcached must be accessible by address `127.0.0.1`. If you use PHP via docker container, run PHP container in network
of memcached container. Use `docker run` command argument for it:

```dockerfile
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
--network container:yiisoft-cache-memcached-cache
```

## Configuration

Creating an instance:
Expand Down Expand Up @@ -128,12 +145,10 @@ This package can be used as a cache handler for the [Yii Caching Library](https:

- [Internals](docs/internals.md)

## License
## Support

The Yii Cache Library - Memcached Handler is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).

## Support the project

Expand All @@ -146,3 +161,10 @@ Maintained by [Yii Software](https://www.yiiframework.com/).
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)

## License

The Yii Cache Library - Memcached Handler is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"issues": "https://github.com/yiisoft/cache-memcached/issues?state=open",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"irc": "ircs://irc.libera.chat:6697/yii",
"chat": "https://t.me/yii3en",
"source": "https://github.com/yiisoft/cache-memcached"
},
Expand Down
30 changes: 9 additions & 21 deletions docs/internals.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# Internals

## Development environment

For greater ease it is recommended to use docker containers.

Run container with memcached directly via command:

```shell
docker run --rm --name yiisoft-cache-memcached-cache --detach --publish 11211:11211 memcached:1.6.23
```

Memcached must be accessible by address `127.0.0.1`. If you use PHP via docker container, run PHP container in network
of memcached container. Use `docker run` command argument for it:

```
--network container:yiisoft-cache-memcached-cache
```

## Unit testing

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
Expand All @@ -42,7 +25,7 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static
./vendor/bin/psalm
```

## Code style
## Rector

Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
use either newest or any specific version of PHP:
Expand All @@ -51,7 +34,12 @@ use either newest or any specific version of PHP:
./vendor/bin/rector
```

## Dependencies
## Composer require checker

This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.

Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive
[Composer](https://getcomposer.org/) dependencies.
To run the checker, execute the following command:

```shell
./vendor/bin/composer-require-checker
```
4 changes: 2 additions & 2 deletions src/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* Memcached implements a cache application component based on
* [memcached](http://pecl.php.net/package/memcached) PECL extension.
* [memcached](https://pecl.php.net/package/memcached) PECL extension.
*
* Memcached can be configured with a list of memcached servers passed to the constructor.
* By default, Memcached assumes there is a memcached server running on localhost at port 11211.
Expand Down Expand Up @@ -115,7 +115,7 @@
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
{
$values = $this->iterableToArray($values);
$this->validateKeysOfValues($values);

Check warning on line 118 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ public function setMultiple(iterable $values, null|int|DateInterval $ttl = null) : bool { $values = $this->iterableToArray($values); - $this->validateKeysOfValues($values); + return $this->cache->setMulti($values, $this->normalizeTtl($ttl)); } public function deleteMultiple(iterable $keys) : bool
return $this->cache->setMulti($values, $this->normalizeTtl($ttl));
}

Expand All @@ -125,12 +125,12 @@
$this->validateKeys($keys);

foreach ($this->cache->deleteMulti($keys) as $result) {
if ($result === false) {

Check warning on line 128 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ $keys = $this->iterableToArray($keys); $this->validateKeys($keys); foreach ($this->cache->deleteMulti($keys) as $result) { - if ($result === false) { + if ($result === true) { return false; } }
return false;
}
}

return true;

Check warning on line 133 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ return false; } } - return true; + return false; } public function has(string $key) : bool {
}

public function has(string $key): bool
Expand Down Expand Up @@ -163,7 +163,7 @@

$ttl = (int) $ttl;

if ($ttl > 2_592_000) {

Check warning on line 166 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ $ttl = (new DateTime('@0'))->add($ttl)->getTimestamp(); } $ttl = (int) $ttl; - if ($ttl > 2592000) { + if ($ttl >= 2592000) { return $ttl + time(); } return $ttl > 0 ? $ttl : self::TTL_EXPIRED;
return $ttl + time();
}

Expand Down Expand Up @@ -214,7 +214,7 @@
* @see https://www.php.net/manual/en/memcached.getserverlist.php
*/
foreach ($this->cache->getServerList() as $existingServer) {
$existingServers["{$existingServer['host']}:{$existingServer['port']}"] = true;

Check warning on line 217 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ * @see https://www.php.net/manual/en/memcached.getserverlist.php */ foreach ($this->cache->getServerList() as $existingServer) { - $existingServers["{$existingServer['host']}:{$existingServer['port']}"] = true; + $existingServers["{$existingServer['host']}:{$existingServer['port']}"] = false; } foreach ($servers as $server) { if (!array_key_exists("{$server[0]}:{$server[1]}", $existingServers)) {
}

foreach ($servers as $server) {
Expand Down Expand Up @@ -250,8 +250,8 @@
|| (isset($server['weight']) && !is_int($server['weight']))
) {
throw new InvalidArgumentException(
'Each entry in servers parameter is supposed to be an array'

Check warning on line 253 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $normalized = []; foreach ($servers as $server) { if (!is_array($server) || !isset($server['host'], $server['port']) || !is_string($server['host']) || !is_int($server['port']) || isset($server['weight']) && !is_int($server['weight'])) { - throw new InvalidArgumentException('Each entry in servers parameter is supposed to be an array' . ' containing hostname (string), port (int), and, optionally, weight (int) of the server.'); + throw new InvalidArgumentException(' containing hostname (string), port (int), and, optionally, weight (int) of the server.' . 'Each entry in servers parameter is supposed to be an array'); } /** * @psalm-var array{host:string,port:int,weight?:int} $server Need for PHP 8.0

Check warning on line 253 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $normalized = []; foreach ($servers as $server) { if (!is_array($server) || !isset($server['host'], $server['port']) || !is_string($server['host']) || !is_int($server['port']) || isset($server['weight']) && !is_int($server['weight'])) { - throw new InvalidArgumentException('Each entry in servers parameter is supposed to be an array' . ' containing hostname (string), port (int), and, optionally, weight (int) of the server.'); + throw new InvalidArgumentException(' containing hostname (string), port (int), and, optionally, weight (int) of the server.'); } /** * @psalm-var array{host:string,port:int,weight?:int} $server Need for PHP 8.0

Check warning on line 253 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $normalized = []; foreach ($servers as $server) { if (!is_array($server) || !isset($server['host'], $server['port']) || !is_string($server['host']) || !is_int($server['port']) || isset($server['weight']) && !is_int($server['weight'])) { - throw new InvalidArgumentException('Each entry in servers parameter is supposed to be an array' . ' containing hostname (string), port (int), and, optionally, weight (int) of the server.'); + throw new InvalidArgumentException('Each entry in servers parameter is supposed to be an array'); } /** * @psalm-var array{host:string,port:int,weight?:int} $server Need for PHP 8.0
. ' containing hostname (string), port (int), and, optionally, weight (int) of the server.',
. ' containing hostname (string), port (int), and, optionally, weight (int) of the server.',
);
}
/**
Expand Down Expand Up @@ -284,6 +284,6 @@
private function validateKeysOfValues(array $values): void
{
$keys = array_map('\strval', array_keys($values));
$this->validateKeys($keys);

Check warning on line 287 in src/Memcached.php

View workflow job for this annotation

GitHub Actions / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ private function validateKeysOfValues(array $values) : void { $keys = array_map('\\strval', array_keys($values)); - $this->validateKeys($keys); + } }
}
}
Loading