SimpleCacheInvalidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A invalidateCaches() 0 15 3
1
<?php
2
3
namespace SubPageList;
4
5
use SubPageList\Lister\SubPageFinder;
6
use Title;
7
8
/**
9
 * Naive cache invalidator that invalidates subpages and the top parent page.
10
 *
11
 * @since 1.0
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class SimpleCacheInvalidator implements CacheInvalidator {
17
18
	/**
19
	 * @var SubPageFinder
20
	 */
21
	private $subPageFinder;
22
23
	/**
24
	 * Constructor.
25
	 *
26
	 * @since 1.0
27
	 *
28
	 * @param SubPageFinder $subPageFinder
29
	 */
30
	public function __construct( SubPageFinder $subPageFinder ) {
31
		$this->subPageFinder = $subPageFinder;
32
	}
33
34
	/**
35
	 * @see CacheInvalidator::invalidateCaches
36
	 *
37
	 * @since 1.0
38
	 *
39
	 * @param Title $title
40
	 */
41
	public function invalidateCaches( Title $title ) {
42
		$pageSegments = explode( '/', $title->getDBkey() );
43
44
		$rootTitle = Title::newFromText( $pageSegments[0] );
45
46
		if ( $rootTitle === null ) {
47
			return;
48
		}
49
50
		$subPages = $this->subPageFinder->getSubPagesFor( $rootTitle );
51
52
		foreach ( $subPages as $subPage ) {
53
			$subPage->invalidateCache();
54
		}
55
	}
56
57
}
58