Completed
Push — master ( e5ef44...29e0f1 )
by Auke
18s
created

check.php ➔ display_perms()   F

Complexity

Conditions 23
Paths > 20000

Size

Total Lines 51
Code Lines 39

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 23
eloc 39
nc 110592
nop 1
dl 0
loc 51
rs 2.942

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 64 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
	$DEBUGON = true;
3
4
	cdebug("check.php START");
5
6
	check_file( "../ariadne.inc" );
7
	cdebug("reading ../ariadne.inc");
8
	include_once("../ariadne.inc");
9
10
	check_file( $ariadne );
11
12
	$ariadne_configs = $ariadne."/configs";
13
	check_file( $ariadne_configs );
14
15
	check_file( $ariadne."/configs/ariadne.phtml" );
16
	cdebug("reading ".$ariadne."/configs/ariadne.phtml");
17
	require_once($ariadne."/configs/ariadne.phtml");
18
19
	check_file( $ariadne."/configs/store.phtml" );
20
	cdebug("reading ".$ariadne."/configs/store.phtml");
21
	require_once($ariadne."/configs/store.phtml");
22
23
	check_file( $ariadne."/configs/axstore.phtml" );
24
	cdebug("reading ".$ariadne."/configs/axstore.phtml");
25
	require_once($ariadne."/configs/axstore.phtml");
26
27
	check_file( $store_config['code'] );
28
	check_file( $store_config['code']."includes/" );
29
30
	check_file( $store_config['code']."modules/mod_debug.php" );
31
	cdebug( "reading ".$store_config['code']."modules/mod_debug.php" );
32
	include_once( $store_config['code']."modules/mod_debug.php" );
33
34
	check_file( $store_config['code']."includes/loader.web.php" );
35
	cdebug( "reading ".$store_config['code']."includes/loader.web.php" );
36
	include_once( $store_config['code']."includes/loader.web.php" );
37
38
	check_file( $store_config['code']."stores/" );
39
	check_file( $store_config['code']."stores/".$ax_config["dbms"]."store.phtml" );
40
	cdebug( "reading ".$store_config['code']."stores/".$ax_config["dbms"]."store.phtml" );
41
	include_once($store_config['code']."stores/".$ax_config["dbms"]."store.phtml");
42
43
	check_file( $store_config['code']."stores/".$store_config["dbms"]."store_install.phtml" );
44
	cdebug( "reading ".$store_config['code']."stores/".$store_config["dbms"]."store_install.phtml" );
45
	include_once($store_config['code']."stores/".$store_config["dbms"]."store_install.phtml");
46
47
	check_file( $store_config['code']."nls/" );
48
	check_file( $store_config['code']."nls/".$AR->nls->default );
49
	cdebug( "reading ".$store_config['code']."nls/".$AR->nls->default );
50
	include_once( $store_config['code']."nls/".$AR->nls->default );
51
52
	$ariadne_files = substr($ariadne, 0, strlen($ariadne)-3)."files";
53
	check_file( $ariadne_files );
54
	if( ! is_writable( $ariadne_files ) ) {
55
		cdebug( "$ariadne_files is not writable" );
56
		echo "[FATAL] can't write to $ariadne_files even though it exists, check permissions: ";
57
		display_perms( fileperms($ariadne_files) );
58
	} else {
59
		cdebug( "$ariadne_files is writable" );
60
	}
61
62
	cdebug( "check.php END\n\n");
63
64
	function check_file( $file ) {
65
66
		if( ! file_exists( $file ) ) {
67
			echo "[FATAL] $file can not be found.\n";
68
			exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function check_file() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
69
		}
70
71
		cdebug( "$file exists" );
72
73
		if( ! is_readable( $file ) ) {
74
			echo "[FATAL] can't read $file even though it exists, check permissions: ";
75
			display_perms( fileperms($file) );
76
			exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function check_file() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
77
		}
78
79
		cdebug( "$file is readable" );
80
		return true;
81
	}
82
83
	function display_perms( $mode ) {
84
		/* Determine Type */
85
		if( $mode & 0x1000 ) {
86
			$type='p'; /* FIFO pipe */
87
		} else if( $mode & 0x2000 ) {
88
			$type='c'; /* Character special */
89
		} else if( $mode & 0x4000 ) {
90
			$type='d'; /* Directory */
91
		} else if( $mode & 0x6000 ) {
92
			$type='b'; /* Block special */
93
		} else if( $mode & 0x8000 ) {
94
			$type='-'; /* Regular */
95
		} else if( $mode & 0xA000 ) {
96
			$type='l'; /* Symbolic Link */
97
		} else if( $mode & 0xC000 ) {
98
			$type='s'; /* Socket */
99
		} else {
100
			$type='u'; /* UNKNOWN */
101
		}
102
103
		/* Determine permissions */
104
		$owner = array();
105
		$group = array();
106
		$world = array();
107
108
		$owner["read"]	 = ($mode & 00400) ? 'r' : '-';
109
		$owner["write"]	= ($mode & 00200) ? 'w' : '-';
110
		$owner["execute"] = ($mode & 00100) ? 'x' : '-';
111
		$group["read"]	 = ($mode & 00040) ? 'r' : '-';
112
		$group["write"]	= ($mode & 00020) ? 'w' : '-';
113
		$group["execute"] = ($mode & 00010) ? 'x' : '-';
114
		$world["read"]	 = ($mode & 00004) ? 'r' : '-';
115
		$world["write"]	= ($mode & 00002) ? 'w' : '-';
116
		$world["execute"] = ($mode & 00001) ? 'x' : '-';
117
118
		/* Adjust for SUID, SGID and sticky bit */
119
		if( $mode & 0x800 ) {
120
			$owner["execute"] = ($owner['execute']=='x') ? 's' : 'S';
121
		}
122
		if( $mode & 0x400 ) {
123
			$group["execute"] = ($group['execute']=='x') ? 's' : 'S';
124
		}
125
		if( $mode & 0x200 ) {
126
			$world["execute"] = ($world['execute']=='x') ? 't' : 'T';
127
		}
128
129
		printf("%1s", $type);
130
		printf("%1s%1s%1s", $owner['read'], $owner['write'], $owner['execute']);
131
		printf("%1s%1s%1s", $group['read'], $group['write'], $group['execute']);
132
		printf("%1s%1s%1s\n", $world['read'], $world['write'], $world['execute']);
133
	}
134
135
	function cdebug( $text ) {
136
		global $DEBUGON;
137
138
		if( $DEBUGON ) {
139
			echo "[CHECK] ".$text."\n";
140
		}
141
	}
142
143
?>
0 ignored issues
show
Best Practice introduced by
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...
144