1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Music app |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Pauli Järvinen <[email protected]> |
10
|
|
|
* @copyright Pauli Järvinen 2018 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Utility; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Miscellaneous static utility functions |
17
|
|
|
*/ |
18
|
|
|
class Util { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Extract ID of each array element by calling getId and return |
22
|
|
|
* the IDs as array |
23
|
|
|
* @param array $arr |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
|
|
public static function extractIds(array $arr) { |
27
|
|
|
return \array_map(function ($i) { |
28
|
|
|
return $i->getId(); |
29
|
|
|
}, $arr); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get difference of two arrays, i.e. elements belonging to $b but not $a. |
34
|
|
|
* This function is faster than the built-in array_diff for large arrays but |
35
|
|
|
* at the expense of higher RAM usage and can be used only for arrays of |
36
|
|
|
* integers or strings. |
37
|
|
|
* From https://stackoverflow.com/a/8827033 |
38
|
|
|
* @param array $b |
39
|
|
|
* @param array $a |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public static function arrayDiff($b, $a) { |
43
|
|
|
$at = \array_flip($a); |
44
|
|
|
$d = []; |
45
|
|
|
foreach ($b as $i) { |
46
|
|
|
if (!isset($at[$i])) { |
47
|
|
|
$d[] = $i; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
return $d; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Truncate the given string to maximum length, appendig ellipsis character |
55
|
|
|
* if the truncation happened. Also null argument may be safely passed and |
56
|
|
|
* it remains unaltered. |
57
|
|
|
* @param string|null $string |
58
|
|
|
* @param int $maxLength |
59
|
|
|
* @return string|null |
60
|
|
|
*/ |
61
|
|
|
public static function truncate($string, $maxLength) { |
62
|
|
|
if ($string === null) { |
63
|
|
|
return null; |
64
|
|
|
} else { |
65
|
|
|
return \mb_strimwidth($string, 0, $maxLength, "\u{2026}"); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Test if given string starts with another given string |
71
|
|
|
* @param string $string |
72
|
|
|
* @param string $potentialStart |
73
|
|
|
* @return boolean |
74
|
|
|
*/ |
75
|
|
|
public static function startsWith($string, $potentialStart) { |
76
|
|
|
return \substr($string, 0, \strlen($potentialStart)) === $potentialStart; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Test if given string ends with another given string |
81
|
|
|
* @param string $string |
82
|
|
|
* @param string $potentialEnd |
83
|
|
|
* @return boolean |
84
|
|
|
*/ |
85
|
|
|
public static function endsWith($string, $potentialEnd) { |
86
|
|
|
return \substr($string, -\strlen($potentialEnd)) === $potentialEnd; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Multi-byte safe case-insensitive string comparison |
91
|
|
|
* @param string $a |
92
|
|
|
* @param string $b |
93
|
|
|
*/ |
94
|
|
|
public static function stringCaseCompare($a, $b) { |
95
|
|
|
return \strcmp(\mb_strtolower($a), \mb_strtolower($b)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param Folder $parentFolder |
|
|
|
|
100
|
|
|
* @param string $relativePath |
101
|
|
|
* @return Folder |
102
|
|
|
*/ |
103
|
|
|
public static function getFolderFromRelativePath($parentFolder, $relativePath) { |
104
|
|
|
if ($relativePath !== null && $relativePath !== '/' && $relativePath !== '') { |
105
|
|
|
return $parentFolder->get($relativePath); |
106
|
|
|
} else { |
107
|
|
|
return $parentFolder; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths