Test Failed
Push — develop ( ff58ad...b8f9b2 )
by steve
13:44 queued 12s
created

UrlManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 1
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCanonical() 0 15 3
1
<?php
2
namespace neon\core\web;
3
4
use neon\core\helpers\Url;
5
use yii\web\UrlManager as WebUrlManager;
6
7
Class UrlManager extends WebUrlManager
8
{
9
	/**
10
	 * Returns the canonical URL of the currently requested page.
11
	 *
12
	 * The canonical URL is constructed using the current controller's [[\yii\web\Controller::route]] and
13
	 * [[\yii\web\Controller::actionParams]]. You may use the following code in the layout view to add a link tag
14
	 * about canonical URL:
15
	 *
16
	 * ```php
17
	 * $this->registerLinkTag(['rel' => 'canonical', 'href' => Url::canonical()]);
18
	 * ```
19
	 *
20
	 * @return string the canonical URL of the currently requested page
21
	 */
22
	public function getCanonical()
23
	{
24
		$params = neon()->controller->actionParams;
25
        $params[0] = neon()->controller->getRoute();
26
		$urlManager = neon()->getUrlManager();
27
		$url = $urlManager->createUrl($params);
28
		if (strpos($url, '://') === false) {
29
			$hostInfo = setting('cms', 'canonical', $urlManager->getHostInfo());
30
			if (strncmp($url, '//', 2) === 0) {
31
				$url = substr($hostInfo, 0, strpos($hostInfo, '://')) . ':' . $url;
32
			} else {
33
				$url = $hostInfo . $url;
34
			}
35
		}
36
		return Url::ensureScheme($url, null);
37
	}
38
}