Completed
Push — update/sitemaps-libxml ( 292726 )
by
unknown
11:41
created

Jetpack_Sitemap_Buffer_Page   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 1
B get_root_element() 32 32 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Sitemaps (per the protocol) are essentially lists of XML fragments;
4
 * lists which are subject to size constraints. The Jetpack_Sitemap_Buffer_Page
5
 * extends the Jetpack_Sitemap_Buffer class to represent the single page sitemap
6
 * buffer.
7
 *
8
 * @since 5.1.0
9
 * @package Jetpack
10
 */
11
12
/**
13
 * A buffer for constructing sitemap page xml files.
14
 *
15
 * @since 5.1.0
16
 */
17 View Code Duplication
class Jetpack_Sitemap_Buffer_Page extends Jetpack_Sitemap_Buffer {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
19
	public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) {
20
		parent::__construct( $item_limit, $byte_limit, $time );
21
22
		$this->doc->appendChild(
23
			$this->doc->createComment( "generator='jetpack-" . JETPACK__VERSION . "'" )
24
		);
25
26
		$this->doc->appendChild(
27
			$this->doc->createProcessingInstruction(
28
				'xml-stylesheet',
29
				'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'sitemap.xsl' ) . '"'
30
			)
31
		);
32
	}
33
34
	protected function get_root_element() {
35
		if ( ! isset( $this->root ) ) {
36
37
			/**
38
			 * Filter the attribute value pairs used for namespace and namespace URI mappings.
39
			 *
40
			 * @module sitemaps
41
			 *
42
			 * @since 3.9.0
43
			 *
44
			 * @param array $namespaces Associative array with namespaces and namespace URIs.
45
			 */
46
			$namespaces = apply_filters(
47
				'jetpack_sitemap_ns',
48
				array(
49
					'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
50
					'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
51
					'xmlns'              => 'http://www.sitemaps.org/schemas/sitemap/0.9',
52
				)
53
			);
54
55
			$this->root = $this->doc->createElement( 'urlset' );
56
57
			foreach ( $namespaces as $name => $value ) {
58
				$this->root->setAttribute( $name, $value );
59
			}
60
61
			$this->doc->appendChild( $this->root );
62
		}
63
64
		return $this->root;
65
	}
66
}
67