| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 50.00% covered (warning) | 50.00% | 1 / 2 | CRAP | 87.50% covered (warning) | 87.50% | 7 / 8
CachingGenerator | 0.00% covered (danger) | 0.00% | 0 / 1 | 50.00% covered (warning) | 50.00% | 1 / 2 | 3.02 | 87.50% covered (warning) | 87.50% | 7 / 8
__construct(Generator $generator) | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 2 / 2
generate(MockConfiguration $config) | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.02 | 83.33% covered (warning) | 83.33% | 5 / 6

1 | <?php
2 |
3 | namespace Mockery\Generator;
4 |
5 | class CachingGenerator implements Generator
6 | {
7 | protected $generator;
8 | protected $cache = array();
9 |
10 | public function __construct(Generator $generator)
11 | {
12 | $this->generator = $generator;
13 | }
14 |
15 | public function generate(MockConfiguration $config)
16 | {
17 | $hash = $config->getHash();
18 | if (isset($this->cache[$hash])) {
19 | return $this->cache[$hash];
20 | }
21 |
22 | $definition = $this->generator->generate($config);
23 | $this->cache[$hash] = $definition;
24 |
25 | return $definition;
26 | }
27 | }