Issues (762)

com.jukusoft.cms.version/classes/version.php (3 issues)

1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: RocketCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 23.03.2018
25
 * Time: 15:46
26
 */
27
28
class Version {
29
30
	protected static $instance = null;
31
32
	protected $version_data = array();
33
34
	public function __construct() {
35
		//
36
	}
37
38
	public function load ($version_path) {
39
		//because unserialize is 2 times faster than json_decode, we cache this value
40
		if (Cache::contains("version", "version_" . $version_path)) {
41
			$this->version_data = Cache::get("version", "version_" . $version_path);
42
		} else {
43
			if (!file_exists($version_path)) {
44
				echo "Version file doesnt exists: " . $version_path;
45
				exit;
46
			}
47
48
			$array = json_decode(file_get_contents($version_path), true);
49
50
			//cache
51
			Cache::put("version", "version_" . $version_path, $array);
52
53
			$this->version_data = $array;
54
		}
55
	}
56
57
	public function getVersion () : string {
58
		if (!isset($this->version_data['version'])) {
59
			var_dump($this->version_data);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->version_data) looks like debug code. Are you sure you do not want to remove it?
Loading history...
60
61
			echo "Version not found!";
62
			exit;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
63
		}
64
65
		return $this->version_data['version'];
66
	}
67
68
	public function getBuildNumber () : string {
69
		return $this->version_data['build'];
70
	}
71
72
	public static function &current () : Version {
73
		if (self::$instance == null) {
74
			self::$instance = new Version();
75
			self::$instance->load(ROOT_PATH . "system/core/version.json");
76
		}
77
78
		return self::$instance;
79
	}
80
81
}
82
83
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
84