Completed
Push — master ( 69cfbf...345b96 )
by Nazar
03:53
created

Local::get_files_list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 12
nc 1
nop 10

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 CMS
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 move_uploaded_file ($filename, $destination) {
74
		return copy($filename, $this->absolute_path($destination));
75
	}
76
	/**
77
	 * @inheritdoc
78
	 */
79
	function rename ($oldname, $newname) {
80
		return rename($this->absolute_path($oldname), $this->absolute_path($newname));
81
	}
82
	/**
83
	 * @inheritdoc
84
	 */
85
	function mkdir ($pathname, $mode = 0777, $recursive = false) {
86
		/** @noinspection MkdirRaceConditionInspection */
87
		return mkdir($this->absolute_path($pathname), $mode, $recursive);
88
	}
89
	/**
90
	 * @inheritdoc
91
	 */
92
	function rmdir ($dirname) {
93
		return rmdir($this->absolute_path($dirname));
94
	}
95
	/**
96
	 * @inheritdoc
97
	 */
98
	function is_file ($filename) {
99
		return is_file($this->absolute_path($filename));
100
	}
101
	/**
102
	 * @inheritdoc
103
	 */
104
	function is_dir ($filename) {
105
		return is_dir($this->absolute_path($filename));
106
	}
107
	/**
108
	 * @inheritdoc
109
	 */
110
	function url_by_source ($source) {
111
		return url_by_source($this->absolute_path($source));
112
	}
113
	/**
114
	 * @inheritdoc
115
	 */
116
	function source_by_url ($url) {
117
		return $this->relative_path(source_by_url($url));
118
	}
119
	protected function absolute_path ($path) {
120
		return preg_match('#^(([a-z]+:)?//|/)#i', $path) ? $path : PUBLIC_STORAGE.'/'.ltrim($path);
121
	}
122
	protected function relative_path ($path) {
123
		return strpos($path, PUBLIC_STORAGE.'/') === 0 ? $path : substr($path, strlen(PUBLIC_STORAGE.'/'));
124
	}
125
}
126