Completed
Pull Request — master (#555)
by Jeroen De
03:53
created

CachingPageRetriever   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetchPage() 0 11 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Infrastructure;
6
7
use Doctrine\Common\Cache\Cache;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class CachingPageRetriever implements PageRetriever {
14
15
	private $pageRetriever;
16
	private $cache;
17
18
	public function __construct( PageRetriever $pageRetriever, Cache $cache ) {
19
		$this->pageRetriever = $pageRetriever;
20
		$this->cache = $cache;
21
	}
22
23
	public function fetchPage( string $pageName, string $fetchMode ): string {
24
		if ( $this->cache->contains( $pageName ) ) {
25
			return $this->cache->fetch( $pageName );
26
		}
27
28
		$content = $this->pageRetriever->fetchPage( $pageName, $fetchMode );
29
30
		$this->cache->save( $pageName, $content );
31
32
		return $content;
33
	}
34
35
}
36