Completed
Push — master ( f975f8...470e80 )
by Nazar
04:10
created

Local::get_files_list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 10
dl 0
loc 14
ccs 0
cts 14
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs\Storage;
9
class Local extends _Abstract {
10
	/**
11
	 * @inheritdoc
12
	 */
13
	function __construct ($base_url, $host, $user = '', $password = '') {
14
		$this->base_url  = url_by_source(PUBLIC_STORAGE);
15
		$this->connected = true;
16
	}
17
	/**
18
	 * @inheritdoc
19
	 */
20
	function get_files_list (
21
		$dir,
22
		$mask = false,
23
		$mode = 'f',
24
		$prefix_path = false,
25
		$subfolders = false,
26
		$sort = false,
27
		$exclusion = false,
28
		$system_files = false,
29
		$apply = null,
30
		$limit = null
31
	) {
32
		return get_files_list($this->absolute_path($dir), $mask, $mode, $prefix_path, $subfolders, $sort, $exclusion, $system_files, $apply, $limit);
33
	}
34
	/**
35
	 * @inheritdoc
36
	 */
37
	function file ($filename, $flags = null) {
38
		return file($this->absolute_path($filename), $flags);
39
	}
40
	/**
41
	 * @inheritdoc
42
	 */
43
	function file_get_contents ($filename, $flags = null) {
44
		return file_get_contents($this->absolute_path($filename), $flags);
45
	}
46
	/**
47
	 * @inheritdoc
48
	 */
49
	function file_put_contents ($filename, $data, $flags = null) {
50
		return file_put_contents($this->absolute_path($filename), $data, $flags);
51
	}
52
	/**
53
	 * @inheritdoc
54
	 */
55
	function copy ($source, $dest) {
56
		return copy($this->absolute_path($source), $this->absolute_path($dest));
57
	}
58
	/**
59
	 * @inheritdoc
60
	 */
61
	function unlink ($filename) {
62
		return unlink($this->absolute_path($filename));
63
	}
64
	/**
65
	 * @inheritdoc
66
	 */
67
	function file_exists ($filename) {
68
		return file_exists($this->absolute_path($filename));
69
	}
70
	/**
71
	 * @inheritdoc
72
	 */
73
	function rename ($oldname, $newname) {
74
		return rename($this->absolute_path($oldname), $this->absolute_path($newname));
75
	}
76
	/**
77
	 * @inheritdoc
78
	 */
79
	function mkdir ($pathname, $mode = 0777, $recursive = false) {
80
		/** @noinspection MkdirRaceConditionInspection */
81
		return mkdir($this->absolute_path($pathname), $mode, $recursive);
82
	}
83
	/**
84
	 * @inheritdoc
85
	 */
86
	function rmdir ($dirname) {
87
		return rmdir($this->absolute_path($dirname));
88
	}
89
	/**
90
	 * @inheritdoc
91
	 */
92
	function is_file ($filename) {
93
		return is_file($this->absolute_path($filename));
94
	}
95
	/**
96
	 * @inheritdoc
97
	 */
98
	function is_dir ($filename) {
99
		return is_dir($this->absolute_path($filename));
100
	}
101
	/**
102
	 * @inheritdoc
103
	 */
104
	function url_by_source ($source) {
105
		return url_by_source($this->absolute_path($source));
106
	}
107
	/**
108
	 * @inheritdoc
109
	 */
110
	function source_by_url ($url) {
111
		return $this->relative_path(source_by_url($url));
112
	}
113
	protected function absolute_path ($path) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
114
		return preg_match('#^(([a-z]+:)?//|/)#i', $path) ? $path : PUBLIC_STORAGE.'/'.ltrim($path);
115
	}
116
	protected function relative_path ($path) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
117
		return strpos($path, PUBLIC_STORAGE.'/') === 0 ? $path : substr($path, strlen(PUBLIC_STORAGE.'/'));
118
	}
119
}
120