Completed
Push — master ( d867f6...facc0d )
by Maxence
01:49
created

MiscService::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
/**
3
 * Files_FullTextSearch - Index the content of your files
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2018
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Files_FullTextSearch\Service;
28
29
use OCA\Files_FullTextSearch\AppInfo\Application;
30
use OCP\ILogger;
31
32
class MiscService {
33
34
	/** @var ILogger */
35
	private $logger;
36
37
	public function __construct(ILogger $logger) {
38
		$this->logger = $logger;
39
	}
40
41
	public function log($message, $level = 2) {
42
		$data = array(
43
			'app'   => Application::APP_NAME,
44
			'level' => $level
45
		);
46
47
		$this->logger->log($level, $message, $data);
48
	}
49
50
	/**
51
	 * @param $arr
52
	 * @param $k
53
	 *
54
	 * @param string $default
55
	 *
56
	 * @return array|string|integer
57
	 */
58
	public static function get($arr, $k, $default = '') {
59
		if (!key_exists($k, $arr)) {
60
			return $default;
61
		}
62
63
		return $arr[$k];
64
	}
65
66
67
	/**
68
	 * @param string $path
69
	 * @param bool $trim
70
	 *
71
	 * @return string
72
	 */
73 View Code Duplication
	public static function endSlash($path, $trim = false) {
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...
74
		if (substr($path, -1) !== '/') {
75
			$path .= '/';
76
		}
77
78
		if ($trim) {
79
			$path = trim($path);
80
		}
81
82
		return $path;
83
	}
84
85
86
	/**
87
	 * @param string $path
88
	 * @param bool $trim
89
	 *
90
	 * @return string
91
	 */
92 View Code Duplication
	public static function noEndSlash($path, $trim = false) {
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...
93
		if (substr($path, -1) === '/') {
94
			$path = substr($path, 0, -1);
95
		}
96
97
		if ($trim) {
98
			$path = trim($path);
99
		}
100
101
		return $path;
102
	}
103
104
105
	/**
106
	 * @param string $path
107
	 * @param bool $trim
108
	 *
109
	 * @return string
110
	 */
111 View Code Duplication
	public static function noBeginSlash($path, $trim = false) {
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...
112
		if (substr($path, 0, 1) === '/') {
113
			$path = substr($path, 1);
114
		}
115
116
		if ($trim) {
117
			$path = trim($path);
118
		}
119
120
		return $path;
121
	}
122
123
124
	public static function secureUsername($username) {
125
		return str_replace('.', '\.', $username);
126
	}
127
}
128
129