Completed
Push — master ( d87efb...5aade8 )
by Auke
22s
created

ar_storeParents::info()   D

Complexity

Conditions 9
Paths 10

Size

Total Lines 33
Code Lines 22

Duplication

Lines 25
Ratio 75.76 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 25
loc 33
ccs 0
cts 0
cp 0
rs 4.909
cc 9
eloc 22
nc 10
nop 0
crap 90
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 8 and the first side effect is on line 3.

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
3
	ar_pinp::allow('ar_store');
4
	ar_pinp::allow('ar_storeFind');
5
	ar_pinp::allow('ar_storeGet');
6
	ar_pinp::allow('ar_storeParents');
7
8
	class ar_store extends arBase {
9
		static public $rememberShortcuts = true;
10
11
		public static function configure( $option, $value ) {
12
			switch ($option) {
13
				case 'rememberShortcuts' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
14
					self::$rememberShortcuts = $value;
15
				break;
16
			}
17
		}
18
19
		public function __set( $name, $value ) {
20
			ar_store::configure( $name, $value );
21
		}
22
23
		public function __get( $name ) {
24
			if ( isset( ar_store::${$name} ) ) {
25
				return ar_store::${$name};
26
			}
27
		}
28
29
		public static function ls() {
30
			return new ar_storeList( ar::context()->getPath() );
31
		}
32
33 4
		public static function find( $query = "" ) {
34 4
			return new ar_storeFind( ar::context()->getPath(), $query);
35
		}
36
37 136 View Code Duplication
		public static function get( $path = "" ) {
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...
38 136
			$path = (string) $path;
39 136
			return new ar_storeGet( ar::context()->getPath( array(
40 136
				'rememberShortcuts' => self::$rememberShortcuts,
41 34
				'path' => $path
42 102
			) ) );
43
		}
44
45
		public static function parents() {
46
			return new ar_storeParents( ar::context()->getPath( array(
47
				'rememberShortcuts' => self::$rememberShortcuts
48
			) ) );
49
		}
50
51 View Code Duplication
		public static function exists( $path = '' ) {
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...
52
			global $store;
53
			$path = (string) $path;
54
			return $store->exists( ar::context()->getPath( array(
55
				'skipShortcuts' => true,
56
				'path' => $path
57
			) ) );
58
		}
59
60 View Code Duplication
		public static function currentSite( $path = '' ) {
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...
61
			$path = (string) $path;
62
			$me = ar::context()->getObject();
63
			if ($me) {
64
				if (self::$rememberShortcuts) {
65
					$me->_load('mod_keepurl.php');
66
					$path = pinp_keepurl::_currentsite( $path );
67
				} else {
68
					$path = $me->currentsite( $path );
69
				}
70
			}
71
			return $path;
72
		}
73
74 View Code Duplication
		public static function parentSite( $path = '' ) {
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...
75
			$path = (string) $path;
76
			$me = ar::context()->getObject();
77
			if ($me) {
78
				if (self::$rememberShortcuts) {
79
					$me->_load('mod_keepurl.php');
80
					$path = pinp_keepurl::_currentsite( $path.'../' );
81
				} else {
82
					$path = $me->parentsite( $path );
83
				}
84
			}
85
			return $path;
86
		}
87
88 View Code Duplication
		public static function currentSection( $path = '' ) {
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...
89
			$path = (string) $path;
90
			$me = ar::context()->getObject();
91
			if ($me) {
92
				if (self::$rememberShortcuts) {
93
					$me->_load('mod_keepurl.php');
94
					$path = pinp_keepurl::_currentsection( $path );
95
				} else {
96
					$path = $me->currentsection( $path );
97
				}
98
			}
99
			return $path;
100
		}
101
102 View Code Duplication
		public static function parentSection( $path = '' ) {
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...
103
			$path = (string) $path;
104
			$me = ar::context()->getObject();
105
			if ($me) {
106
				if (self::$rememberShortcuts) {
107
					$me->_load('mod_keepurl.php');
108
					$path = pinp_keepurl::_currentsection( $path.'../' );
109
				} else {
110
					$path = $me->parentsection( $path );
111
				}
112
			}
113
			return $path;
114
		}
115
116 6 View Code Duplication
		public static function currentProject( $path = '' ) {
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...
117
			$path = (string) $path;
118
			$me = ar::context()->getObject();
119
			if ($me) {
120
				$path = $me->currentproject( $path );
121
			}
122
			return $path;
123 6
		}
124
125 View Code Duplication
		public static function parentProject( $path = '' ) {
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...
126
			$path = (string) $path;
127
			$me = ar::context()->getObject();
128
			if ($me) {
129
				$path = $me->parentproject( $path );
130
			}
131
			return $path;
132
		}
133
134 View Code Duplication
		public static function makePath( $path = '' ) {
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...
135
			$path = (string) $path;
136
			return ar::context()->getPath( array(
137
				'rememberShortcuts' => self::$rememberShortcuts,
138
				'path' => $path
139
			) );
140
		}
141
142 136 View Code Duplication
		public static function makeRealPath( $path = '' ) {
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...
143 136
			$path = (string) $path;
144 136
			return ar::context()->getPath( array(
145 136
				'skipShortcuts' => true,
146 34
				'path' => $path
147 102
			) );
148
		}
149
150
	}
151
152
	class ar_storeFind extends arBase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
153
154
		var $limit = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $limit.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
155
		var $offset = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $offset.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
156
		var $order = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $order.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
157
		var $query = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $query.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
158
		var $path = '/';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $path.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
159
160 4
		public function __construct( $path = '/', $query = '' ) {
161 4
			$this->path = (string)$path;
162 4
			$this->query = (string)$query;
163 4
		}
164
165 6
		public function call( $template, $args = null ) {
166 4
			global $store;
167 4
			if ($template instanceof ar_listExpression_Pattern ) {
168
				$template = ar::listExpression( $this->count() )->pattern( $template );
169
			}
170 4
			if (ar_store::$rememberShortcuts) {
171 4
				$path = ar_store::makeRealPath( $this->path );
172 3
			} else {
173
				$path = $this->path;
174
			}
175 4
			$query = $this->query;
176 4
			if ($this->order) {
177
				$query .= ' order by '.$this->order;
178 3
			}
179 4
			$result = $store->call( $template, $args, $store->find( $path, $query, $this->limit, $this->offset), array( 'usePathAsKey' => true ) );
180 4
			return $result;
181
		}
182
183
		public function info() {
184
			global $store;
185
			if (ar_store::$rememberShortcuts) {
186
				$path = ar_store::makeRealPath( $this->path );
187
			} else {
188
				$path = $this->path;
189
			}
190
			$query = $this->query;
191
			if ($this->order) {
192
				$query .= ' order by '.$this->order;
193
			}
194
			$result = $store->info( $store->find( $path, $query, $this->limit, $this->offset), array( 'usePathAsKey' => true ));
195
			return $result;
196
		}
197
198
		public function count() {
199
			global $store;
200
			if (ar_store::$rememberShortcuts) {
201
				$path = ar_store::makeRealPath( $this->path );
0 ignored issues
show
Unused Code introduced by
$path is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
202
			} else {
203
				$path = $this->path;
0 ignored issues
show
Unused Code introduced by
$path is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
204
			}
205
			return $store->count_find( $this->path, $this->query, $this->limit, $this->offset );
206
		}
207
208
		public function limit( $limit ) {
209
			$clone = clone $this;
210
			$clone->limit = $limit;
211
			return $clone;
212
		}
213
214
		public function offset( $offset ) {
215
			$clone = clone $this;
216
			$clone->offset = $offset;
217
			return $clone;
218
		}
219
220
		public function order( $order ) {
221
			$clone = clone $this;
222
			$clone->order = $order;
223
			return $clone;
224
		}
225 136
226 136
	}
227 136
228
	class ar_storeList extends ar_storeFind {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
229
230
		public function __construct( $path ) {
231
			parent::__construct( $path, "object.parent = '" . $path . "'" );
232
		}
233
234
	}
235
236
	class ar_storeGet extends arBase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
237 136
238 136
		protected $path = '';
239 136
240
		public function __construct( $path ) {
241
			$this->path = (string)$path;
242 136
		}
243 136
244 102
		public function find( $query = "" ) {
245
			return new ar_storeFind( $this->path, $query );
246
		}
247 136
248
		public function ls() {
249
			return new ar_storeList( $this->path );
250
		}
251
252
		public function call( $template, $args = null ) {
253
			global $store;
254
			if ( $template instanceof ar_listExpression_Pattern ) {
255
				$template = ar::listExpression( 1 )->pattern( $template );
256
			}
257
			if ( ar_store::$rememberShortcuts ) {
258
				$path = ar_store::makeRealPath( $this->path );
259
			} else {
260
				$path = $this->path;
261
			}
262
			return $store->call( $template, $args, $store->get( $path ), array( 'usePathAsKey' => true ) );
263
		}
264
265
		public function info() {
266
			global $store;
267
			if ( ar_store::$rememberShortcuts ) {
268
				$path = ar_store::makeRealPath( $this->path );
269
			} else {
270
				$path = $this->path;
271
			}
272
			return $store->info( $store->get( $path ), array( 'usePathAsKey' => true ));
273
		}
274
275
		public function parents() {
276
			return new ar_storeParents( $this->path );
277
		}
278
279
	}
280
281
	class ar_storeParents extends arBase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
282
283
		protected $path = '';
284
		protected $top = '/';
285
286
		public function __construct( $path = "" ) {
287
			$this->path	= (string)$path;
288
		}
289
290
		public function call( $template, $args = null ) {
291
			global $store;
292
			if ( $template instanceof ar_listExpression_Pattern ) {
293
				$template = ar::listExpression( $this->count() )->pattern( $template );
294
			}
295 View Code Duplication
			if ( ar_store::$rememberShortcuts) {
296
				$path     = ar_store::makePath( $this->path );
297
				$realpath = ar_store::makeRealPath( $this->path );
298
				if ($realpath != $path ) {
299
					// must do a call for each seperate path.
300
					$list   = array();
301
					$parent = $path;
302
					while ( $realpath != $this->top && $parent != $this->top && end( $list ) != $realpath ) {
303
						$list[$parent] = $realpath;
304
						$parent        = ar_store::makePath( $parent . '../' );
305
						$realpath      = ar_store::makeRealPath( $parent );
306
					}
307
					if ( ( $realpath == $this->top ) || ( $parent == $this->top ) ) {
308
						$list[$parent] = $realpath;
309
					}
310
					$list = array_reverse( $list );
311
					$result = array();
312
					foreach ( $list as $virtualpath => $path ) {
313
						$result[$virtualpath] = current( $store->call( $template, $args,
314
							$store->get( $path ),
315
							array(
316
								'usePathAsKey' => true
317
							)
318
						) );
319
					}
320
					return $result;
321
				}
322
			}
323
			return $store->call( $template, $args,
324
				$store->parents( $this->path, $this->top ),
325
				array( 'usePathAsKey' => true )
326
			);
327
		}
328
329
		public function info(){
330
			global $store;
331
332 View Code Duplication
			if ( ar_store::$rememberShortcuts) {
333
				$path     = ar_store::makePath( $this->path );
334
				$realpath = ar_store::makeRealPath( $this->path );
335
				if ($realpath != $path ) {
336
					// must do a call for each seperate path.
337
					$list   = array();
338
					$parent = $path;
339
					while ( $realpath != $this->top && $parent != $this->top && end( $list ) != $realpath ) {
340
						$list[$parent] = $realpath;
341
						$parent        = ar_store::makePath( $parent . '../' );
342
						$realpath      = ar_store::makeRealPath( $parent );
343
					}
344
					if ( ( $realpath == $this->top ) || ( $parent == $this->top ) ) {
345
						$list[$parent] = $realpath;
346
					}
347
					$list = array_reverse( $list );
348
					$result = array();
349
					foreach ( $list as $virtualpath => $path ) {
350
						$result[$virtualpath] = current( $store->info(
351
							$store->get( $path )
352
						));
353
					}
354
					return $result;
355
				}
356
			}
357
358
			return $store->info(
359
				$store->parents( $this->path, $this->top ), array( 'usePathAsKey' => true )
360
			);
361
		}
362
363
		public function count() {
364
			global $store;
365
			return $store->count( $store->parents( $this->path, $this->top ) );
366
		}
367
368
		public function top( $top = "/" ) {
369
			$clone = clone $this;
370
			$clone->top = $top;
371
			return $clone;
372
		}
373
374
	}
375