| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 49 | function TestCacheFilePath () { |
||
|
|
|||
| 50 | $this->oCh->SetCfg(array( |
||
| 51 | 'cache-type' => 'file', |
||
| 52 | 'cache-file-dir' => '/tmp/cache/', |
||
| 53 | 'cache-file-rule' => '1140', |
||
| 54 | )); |
||
| 55 | $key = 'site/index'; |
||
| 56 | |||
| 57 | //Ecl(md5($key)); |
||
| 58 | |||
| 59 | $x = '/tmp/cache/d0/ex/3ed0dc6e'; |
||
| 60 | $y = $this->oCh->CacheFilePath($key); |
||
| 61 | $this->assertEqual($x, $y); |
||
| 62 | |||
| 63 | $this->oCh->SetCfg(array('cache-file-rule' => '1131')); |
||
| 64 | $x = '/tmp/cache/d0/te/3ed0dc6e'; |
||
| 65 | $y = $this->oCh->CacheFilePath($key); |
||
| 66 | $this->assertEqual($x, $y); |
||
| 67 | |||
| 68 | // Notice: Directly use key's part as path may cause wrong |
||
| 69 | $this->oCh->SetCfg(array('cache-file-rule' => '2342')); |
||
| 70 | $x = '/tmp/cache/57//i/3ed0dc6e'; |
||
| 71 | $y = $this->oCh->CacheFilePath($key); |
||
| 72 | $this->assertEqual($x, $y); |
||
| 73 | |||
| 74 | // Common usage |
||
| 75 | $this->oCh->SetCfg(array('cache-file-rule' => '1011')); |
||
| 76 | $x = '/tmp/cache/3e/d0/3ed0dc6e'; |
||
| 77 | $y = $this->oCh->CacheFilePath($key); |
||
| 78 | $this->assertEqual($x, $y); |
||
| 79 | |||
| 80 | // Common usage 2 |
||
| 81 | $this->oCh->SetCfg(array('cache-file-rule' => '2021')); |
||
| 82 | $x = '/tmp/cache/b6/9c/3ed0dc6e'; |
||
| 83 | $y = $this->oCh->CacheFilePath($key); |
||
| 84 | $this->assertEqual($x, $y); |
||
| 85 | |||
| 86 | // Common usage 3 |
||
| 87 | $this->oCh->SetCfg(array('cache-file-rule' => '55')); |
||
| 88 | $x = '/tmp/cache/89/3ed0dc6e'; |
||
| 89 | $y = $this->oCh->CacheFilePath($key); |
||
| 90 | $this->assertEqual($x, $y); |
||
| 91 | |||
| 92 | //Ecl($y); |
||
| 93 | |||
| 94 | // Read/write |
||
| 95 | $v = $this->oCh->CacheGet($key, 1); |
||
| 96 | var_dump($v); |
||
| 97 | Ecl(hash('crc32', $key) |
||
| 98 | . '|' |
||
| 99 | . $this->oCh->CacheFilePath($key)); |
||
| 100 | } // end of func TestCacheFilePath |
||
| 101 | |||
| 128 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.