Completed
Push — master ( 0648f2...737095 )
by Jean-Christophe
01:38
created

StartupConfigTrait::reloadConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ubiquity\controllers\traits;
4
5
use Ubiquity\utils\base\UString;
6
use Ubiquity\utils\base\UFileSystem;
7
8
trait StartupConfigTrait {
9
	protected static $config;
10
	protected static $ctrlNS;
11
	
12
	public static function getConfig() {
13
		return self::$config;
14
	}
15
	
16
	public static function setConfig($config) {
17
		self::$config = $config;
18
	}
19
	
20
	public static function getModelsDir() {
21
		return self::$config ["mvcNS"] ["models"];
22
	}
23
	
24
	public static function getModelsCompletePath() {
25
		return ROOT . DS . self::getModelsDir ();
26
	}
27
	
28 View Code Duplication
	protected static function needsKeyInConfigArray(&$result, $array, $needs) {
0 ignored issues
show
Duplication introduced by
This method 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...
29
		foreach ( $needs as $need ) {
30
			if (! isset ( $array [$need] ) || UString::isNull ( $array [$need] )) {
31
				$result [] = $need;
32
			}
33
		}
34
	}
35
	
36 View Code Duplication
	public static function getNS($part = "controllers") {
0 ignored issues
show
Duplication introduced by
This method 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...
37
		$config = self::$config;
38
		$ns = $config ["mvcNS"] [$part];
39
		if ($ns !== "" && $ns !== null) {
40
			$ns .= "\\";
41
		}
42
		return $ns;
43
	}
44
	
45
	protected static function setCtrlNS() {
46
		self::$ctrlNS = self::getNS ();
47
	}
48
	
49 View Code Duplication
	public static function checkDbConfig() {
0 ignored issues
show
Duplication introduced by
This method 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...
50
		$config = self::$config;
51
		$result = [ ];
52
		$needs = [ "type","dbName","serverName" ];
53
		if (! isset ( $config ["database"] )) {
54
			$result [] = "database";
55
		} else {
56
			self::needsKeyInConfigArray ( $result, $config ["database"], $needs );
57
		}
58
		return $result;
59
	}
60
	
61 View Code Duplication
	public static function checkModelsConfig() {
0 ignored issues
show
Duplication introduced by
This method 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...
62
		$config = self::$config;
63
		$result = [ ];
64
		if (! isset ( $config ["mvcNS"] )) {
65
			$result [] = "mvcNS";
66
		} else {
67
			self::needsKeyInConfigArray ( $result, $config ["mvcNS"], [ "models" ] );
68
		}
69
		return $result;
70
	}
71
	
72
	
73 View Code Duplication
	public static function reloadConfig(){
0 ignored issues
show
Duplication introduced by
This method 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...
74
		$appDir=\dirname ( ROOT );
75
		$filename=$appDir."/app/config/config.php";
76
		self::$config=include($filename);
77
		self::startTemplateEngine(self::$config);
78
		return self::$config;
79
	}
80
	
81 View Code Duplication
	public static function saveConfig($content){
0 ignored issues
show
Duplication introduced by
This method 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...
82
		$appDir=\dirname ( ROOT );
83
		$filename=$appDir."/app/config/config.php";
84
		$oldFilename=$appDir."/app/config/config.old.php";
85
		if (!file_exists($filename) || copy($filename, $oldFilename)) {
86
			return UFileSystem::save($filename,$content);
87
		}
88
		return false;
89
	}
90
}
91
92