Completed
Push — master ( fad9f9...8658c1 )
by Jean-Christophe
01:44
created

UrlParser   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 10 3
A parseUrl() 0 12 3
A getLastModified() 0 14 3
1
<?php
2
3
namespace Ubiquity\seo;
4
5
use Ubiquity\cache\CacheManager;
6
use Ubiquity\utils\base\UIntrospection;
7
use Ubiquity\utils\base\UFileSystem;
8
use Ubiquity\controllers\Startup;
9
10
class UrlParser {
11
	public static $frequencies=[ 'always','hourly','daily','weekly','monthly','yearly','never' ];
12
	private $routes;
13
	private $config;
14
15
	public function __construct() {
16
		$this->routes=CacheManager::getRoutes();
17
		$this->config=Startup::getConfig();
18
	}
19
20
	public function parse() {
21
		$urls=[ ];
22
		foreach ( $this->routes as $path => $route ) {
23
			$url=$this->parseUrl($path, $route);
24
			if (isset($url)) {
25
				$urls[]=$url;
26
			}
27
		}
28
		return $urls;
29
	}
30
31
	protected function parseUrl($path, $route) {
32
		if (isset($route["controller"])) {
33
			$controller=$route["controller"];
34
			$action=$route["action"];
35
		} elseif (isset($route["get"])) {
36
			return $this->parse($route["get"]);
0 ignored issues
show
Unused Code introduced by
The call to UrlParser::parse() has too many arguments starting with $route['get'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
		} else {
38
			return;
39
		}
40
		$url=new Url($path, $this->getLastModified($controller, $action));
41
		return $url;
42
	}
43
44
	protected function getLastModified($controller, $action) {
45
		$classCode=UIntrospection::getClassCode($controller);
46
		$lastModified=UFileSystem::lastModified(UIntrospection::getFileName($controller));
47
		$reflexAction=new \ReflectionMethod([ $controller,$action ]);
48
		$actionCode=UIntrospection::getMethodCode($reflexAction, $classCode);
49
		$views=UIntrospection::getLoadedViews($reflexAction, $actionCode);
50
		foreach ( $views as $view ) {
51
			$file=ROOT . DS . "views" . DS . $view;
52
			$viewDate=UFileSystem::lastModified($file);
53
			if ($viewDate > $lastModified)
54
				$lastModified=$viewDate;
55
		}
56
		return $lastModified;
57
	}
58
}
59
60