Skip to content

Commit 3aff3fb

Browse files
author
James Galecki
committed
PHPCS / PHPUNIT / Missed Corrections
1 parent 4199999 commit 3aff3fb

11 files changed

Lines changed: 90 additions & 87 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @traderinteractive/opensource

CONTRIBUTING.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Memoize
22
A PHP library for memoizing repeated function calls.
33

4-
[![Build Status](http://img.shields.io/travis/dominionenterprises/memoize-php.svg?style=flat)](https://travis-ci.org/dominionenterprises/memoize-php)
5-
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/dominionenterprises/memoize-php.svg?style=flat)](https://scrutinizer-ci.com/g/dominionenterprises/memoize-php/)
6-
[![Code Coverage](http://img.shields.io/coveralls/dominionenterprises/memoize-php.svg?style=flat)](https://coveralls.io/r/dominionenterprises/memoize-php)
4+
[![Build Status](http://img.shields.io/travis/traderinteractive/memoize-php.svg?style=flat)](https://travis-ci.org/traderinteractive/memoize-php)
5+
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/traderinteractive/memoize-php.svg?style=flat)](https://scrutinizer-ci.com/g/traderinteractive/memoize-php/)
6+
[![Code Coverage](http://img.shields.io/coveralls/traderinteractive/memoize-php.svg?style=flat)](https://coveralls.io/r/traderinteractive/memoize-php)
77

8-
[![Latest Stable Version](http://img.shields.io/packagist/v/dominionenterprises/memoize.svg?style=flat)](https://packagist.org/packages/dominionenterprises/memoize)
9-
[![Total Downloads](http://img.shields.io/packagist/dt/dominionenterprises/memoize.svg?style=flat)](https://packagist.org/packages/dominionenterprises/memoize)
10-
[![License](http://img.shields.io/packagist/l/dominionenterprises/memoize.svg?style=flat)](https://packagist.org/packages/dominionenterprises/memoize)
8+
[![Latest Stable Version](http://img.shields.io/packagist/v/traderinteractive/memoize.svg?style=flat)](https://packagist.org/packages/traderinteractive/memoize)
9+
[![Total Downloads](http://img.shields.io/packagist/dt/traderinteractive/memoize.svg?style=flat)](https://packagist.org/packages/traderinteractive/memoize)
10+
[![License](http://img.shields.io/packagist/l/traderinteractive/memoize.svg?style=flat)](https://packagist.org/packages/traderinteractive/memoize)
1111

1212
## Requirements
1313
This library requires PHP 5.4, or newer.
1414

1515
## Installation
1616
This package uses [composer](https://getcomposer.org) so you can just add
17-
`dominionenterprises/memoize` as a dependency to your `composer.json` file.
17+
`traderinteractive/memoize` as a dependency to your `composer.json` file.
1818

1919
## Memoization
2020
[Memoization](http://en.wikipedia.org/wiki/Memoization) is a way of optimizing
2121
a function that is called repeatedly by caching the results of a function call.
2222

2323
## Memoization Providers
2424
This library includes several built-in providers for memoization. Each one
25-
implements the `\DominionEnterprises\Memoize\Memoize` interface:
25+
implements the `\TraderInteractive\Memoize\Memoize` interface:
2626
```php
2727
interface Memoize
2828
{
@@ -90,7 +90,7 @@ rather than only caching computation for the current process.
9090
#### Example
9191
```php
9292
$predis = new \Predis\Client($redisUrl);
93-
$memoize = new \DominionEnterprises\Memoize\Predis($predis);
93+
$memoize = new \TraderInteractive\Memoize\Predis($predis);
9494

9595
$compute = function() {
9696
// Perform some long operation that you want to memoize
@@ -106,7 +106,7 @@ moment and only keeps the results around as long as the memoizer is in memory.
106106

107107
#### Example
108108
```php
109-
$memoize = new \DominionEnterprises\Memoize\Memory();
109+
$memoize = new \TraderInteractive\Memoize\Memory();
110110

111111
$compute = function() {
112112
// Perform some long operation that you want to memoize
@@ -123,7 +123,7 @@ out for this one and everything will still work.
123123

124124
#### Example
125125
```php
126-
$memoize = new \DominionEnterprises\Memoize\Never();
126+
$memoize = new \TraderInteractive\Memoize\Never();
127127

128128
$compute = function() {
129129
// Perform some long operation that you want to memoize

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
"predis/predis": "Allows for Redis-based memoization."
2727
},
2828
"autoload": {
29-
"psr-4": { "DominionEnterprises\\Memoize\\": "src/" }
29+
"psr-4": { "TraderInteractive\\Memoize\\": "src/" }
3030
}
3131
}

src/Memoize.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
2-
namespace DominionEnterprises\Memoize;
2+
3+
namespace TraderInteractive\Memoize;
34

45
interface Memoize
56
{
67
/**
78
* Gets the value stored in the cache or uses the passed function to compute the value and save to cache.
89
*
9-
* @param string $key The key to fetch
10-
* @param callable $compute A function to run if the value was not cached that will return the result.
11-
* @param int $cacheTime The number of seconds to cache the response for, or null to not expire it ever.
10+
* @param string $key The key to fetch
11+
* @param callable $compute A function to run if the value was not cached that will return the result.
12+
* @param int $cacheTime The number of seconds to cache the response for, or null to not expire it ever.
13+
*
1214
* @return mixed The data requested, optionally pulled from cache
1315
*/
1416
public function memoizeCallable($key, $compute, $cacheTime = null);

src/Memory.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
namespace DominionEnterprises\Memoize;
2+
3+
namespace TraderInteractive\Memoize;
34

45
/**
56
* An in-memory memoizer that keeps the cached values around for the lifetime of this instance.
@@ -11,7 +12,7 @@ class Memory implements Memoize
1112
*
1213
* @var array
1314
*/
14-
private $_cache = [];
15+
private $cache = [];
1516

1617
/**
1718
* $cacheTime is ignored - this will keep the results around for the lifetime of this instance.
@@ -20,12 +21,12 @@ class Memory implements Memoize
2021
*/
2122
public function memoizeCallable($key, $compute, $cacheTime = null)
2223
{
23-
if (array_key_exists($key, $this->_cache)) {
24-
return $this->_cache[$key];
24+
if (array_key_exists($key, $this->cache)) {
25+
return $this->cache[$key];
2526
}
2627

2728
$result = call_user_func($compute);
28-
$this->_cache[$key] = $result;
29+
$this->cache[$key] = $result;
2930

3031
return $result;
3132
}

src/Never.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2-
namespace DominionEnterprises\Memoize;
2+
3+
namespace TraderInteractive\Memoize;
34

45
/**
5-
* A memoizer that never caches and always recomputes the result. This is useful for turning off memoization (e.g., for debugging).
6+
* A memoizer that never caches and always recomputes the result.
7+
* This is useful for turning off memoization (e.g., for debugging).
68
*/
79
class Never implements Memoize
810
{

src/Predis.php

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2-
namespace DominionEnterprises\Memoize;
2+
3+
namespace TraderInteractive\Memoize;
34

45
use \Predis\Client;
56

67
/**
7-
* A memoizer that caches the results in a redis cache.
8+
* A memoizer that caches the results in a redis cache.
89
*/
910
class Predis implements Memoize
1011
{
@@ -13,37 +14,38 @@ class Predis implements Memoize
1314
*
1415
* @var \Predis\Client
1516
*/
16-
private $_client;
17+
private $client;
1718

1819
/**
1920
* Cache refresh
2021
*
2122
* @var boolean
2223
*/
23-
private $_refresh;
24+
private $refresh;
2425

2526
/**
2627
* Sets the predis client.
2728
*
28-
* @param \Predis\Client $client The predis client to use
29-
* @param boolean $refresh If true we will always overwrite cache even if it is already set
29+
* @param \Predis\Client $client The predis client to use
30+
* @param boolean $refresh If true we will always overwrite cache even if it is already set
3031
*/
31-
public function __construct(Client $client, $refresh = false)
32+
public function __construct(Client $client, bool $refresh = false)
3233
{
33-
$this->_client = $client;
34-
$this->_refresh = $refresh;
34+
$this->client = $client;
35+
$this->refresh = $refresh;
3536
}
3637

3738
/**
38-
* The value is stored in redis as a json_encoded string, so make sure that the value you return from $compute is json-encodable.
39+
* The value is stored in redis as a json_encoded string,
40+
* so make sure that the value you return from $compute is json-encode-able.
3941
*
4042
* @see Memoize::memoizeCallable
4143
*/
4244
public function memoizeCallable($key, $compute, $cacheTime = null)
4345
{
44-
if (!$this->_refresh) {
46+
if (!$this->refresh) {
4547
try {
46-
$cached = $this->_client->get($key);
48+
$cached = $this->client->get($key);
4749
if ($cached !== null) {
4850
$data = json_decode($cached, true);
4951
return $data['result'];
@@ -55,30 +57,33 @@ public function memoizeCallable($key, $compute, $cacheTime = null)
5557

5658
$result = call_user_func($compute);
5759

58-
$this->_cache($key, json_encode(['result' => $result]), $cacheTime);
60+
$this->cache($key, json_encode(['result' => $result]), $cacheTime);
5961

6062
return $result;
6163
}
6264

6365
/**
6466
* Caches the value into redis with errors suppressed.
6567
*
66-
* @param string $key The key.
67-
* @param string $value The value.
68-
* @param int $cacheTime The optional cache time
68+
* @param string $key The key.
69+
* @param string $value The value.
70+
* @param int $cacheTime The optional cache time
71+
*
6972
* @return void
7073
*/
71-
private function _cache($key, $value, $cacheTime = null)
74+
private function cache(string $key, string $value, int $cacheTime = null)
7275
{
7376
try {
74-
$this->_client->set($key, $value);
77+
$this->client->set($key, $value);
7578

7679
if ($cacheTime !== null) {
77-
$this->_client->expire($key, $cacheTime);
80+
$this->client->expire($key, $cacheTime);
7881
}
7982
} catch (\Exception $e) {
80-
// We don't want exceptions in accessing the cache to break functionality. The cache should be as transparent as possible.
81-
// If insight is needed into these exceptions, a better way would be by notifying an observer with the errors.
83+
// We don't want exceptions in accessing the cache to break functionality.
84+
// The cache should be as transparent as possible.
85+
// If insight is needed into these exceptions,
86+
// a better way would be by notifying an observer with the errors.
8287
}
8388
}
8489
}

tests/MemoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace DominionEnterprises\Memoize;
3+
namespace TraderInteractive\Memoize;
44

55
use PHPUnit\Framework\TestCase;
66

77
/**
8-
* @coversDefaultClass \DominionEnterprises\Memoize\Memory
8+
* @coversDefaultClass \TraderInteractive\Memoize\Memory
99
*/
1010
class MemoryTest extends TestCase
1111
{
@@ -18,7 +18,7 @@ public function memoizeCallableTwice()
1818
$count = 0;
1919
$key = 'foo';
2020
$value = 'bar';
21-
$compute = function() use(&$count, $value) {
21+
$compute = function () use (&$count, $value) {
2222
$count++;
2323

2424
return $value;

tests/NeverTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace DominionEnterprises\Memoize;
3+
namespace TraderInteractive\Memoize;
44

55
use PHPUnit\Framework\TestCase;
66

77
/**
8-
* @coversDefaultClass \DominionEnterprises\Memoize\Never
8+
* @coversDefaultClass \TraderInteractive\Memoize\Never
99
*/
1010
class NeverTest extends TestCase
1111
{
@@ -18,13 +18,13 @@ public function memoizeCallableTwice()
1818
$count = 0;
1919
$key = 'foo';
2020
$value = 'bar';
21-
$compute = function() use(&$count, $value) {
21+
$compute = function () use (&$count, $value) {
2222
$count++;
2323

2424
return $value;
2525
};
2626

27-
$memoizer = new \DominionEnterprises\Memoize\Never();
27+
$memoizer = new Never();
2828

2929
$this->assertSame($value, $memoizer->memoizeCallable($key, $compute));
3030
$this->assertSame($value, $memoizer->memoizeCallable($key, $compute));

0 commit comments

Comments
 (0)