Completed
Push — try/composer-jetpack-logo-pack... ( 20dcf2 )
by Marin
12:08 queued 03:55
created

Logo::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * A logo for Jetpack.
4
 *
5
 * @package jetpack-logo
6
 */
7
8
namespace Jetpack\Assets;
9
10
/**
11
 * Create and render a Jetpack logo.
12
 */
13
class Logo {
14
	/**
15
	 * Absolute URL of the Jetpack logo.
16
	 *
17
	 * @var string
18
	 */
19
	private $url;
20
21
	/**
22
	 * Constructor.
23
	 * You can optionally pass a URL to override the default one.
24
	 *
25
	 * @param string $url New URL of the Jetpack logo.
26
	 */
27
	public function __construct( $url = '' ) {
28
		if ( ! $url ) {
29
			$url = plugins_url( 'assets/logo.svg', __DIR__ );
30
		}
31
32
		$this->url = $url;
33
	}
34
35
	/**
36
	 * Build and retrieve an <img /> tag with the Jetpack logo.
37
	 *
38
	 * @return string The Jetpack logo.
39
	 */
40
	public function get_image() {
41
		return sprintf(
42
			'<img src="%s" class="jetpack-logo" alt="%s" />',
43
			esc_url( $this->url ),
44
			esc_attr__(
45
				'Jetpack is a free plugin that utilizes powerful WordPress.com servers to enhance your site and simplify managing it',
46
				'jetpack'
47
			)
48
		);
49
	}
50
51
	/**
52
	 * Create a new `Logo` instance and render it.
53
	 *
54
	 * @static
55
	 *
56
	 * @param string $url Optional custom URL of a Jetpack logo.
57
	 * @return string The Jetpack logo.
58
	 */
59
	public static function render( $url = '' ) {
60
		$logo = new self( $url );
61
62
		return $logo->get_image();
63
	}
64
}
65