These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Nextcloud - namespace OCA\Nextnote |
||
4 | * |
||
5 | * @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
||
6 | * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
||
7 | * @license GNU AGPL version 3 or any later version |
||
8 | * |
||
9 | * This program is free software: you can redistribute it and/or modify |
||
10 | * it under the terms of the GNU Affero General Public License as |
||
11 | * published by the Free Software Foundation, either version 3 of the |
||
12 | * License, or (at your option) any later version. |
||
13 | * |
||
14 | * This program is distributed in the hope that it will be useful, |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
17 | * GNU Affero General Public License for more details. |
||
18 | * |
||
19 | * You should have received a copy of the GNU Affero General Public License |
||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
21 | * |
||
22 | */ |
||
23 | |||
24 | namespace OCA\NextNote\Utility; |
||
25 | |||
26 | class Utils { |
||
27 | /** |
||
28 | * Gets the unix epoch UTC timestamp |
||
29 | * @return int |
||
30 | */ |
||
31 | public static $maxPartSize = 2621440; |
||
32 | |||
33 | public static function getTime() { |
||
34 | return (new \DateTime())->getTimestamp(); |
||
35 | } |
||
36 | /** |
||
37 | * @return int the current unix time in milliseconds |
||
38 | */ |
||
39 | public static function getMicroTime() { |
||
40 | return microtime(true); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param $uid |
||
45 | * @return string |
||
46 | */ |
||
47 | public static function getNameByUid($uid){ |
||
48 | $u = Utils::getUserInfo($uid); |
||
0 ignored issues
–
show
|
|||
49 | return $u['display_name']; |
||
50 | } |
||
51 | |||
52 | public static function getUserInfo($uid){ |
||
53 | $um = \OC::$server->getUserManager(); |
||
54 | $u = $um->get($uid); |
||
55 | $user = [ |
||
56 | 'display_name' => $u->getDisplayName(), |
||
57 | 'uid' => $uid, |
||
58 | 'avatar' => $u->getAvatarImage(32) |
||
59 | ]; |
||
60 | return $user; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Splits a string in parts of 5Mb |
||
65 | * @param $str |
||
66 | * @return array |
||
67 | */ |
||
68 | public function splitContent($str) { |
||
69 | $maxlength = Utils::$maxPartSize; // 5 Megs (2 bytes per character) |
||
70 | $count = 0; |
||
71 | $strarray = array(); |
||
72 | while (true) { |
||
73 | if (strlen($str) <= $maxlength) { |
||
74 | $strarray[$count++] = $str; |
||
75 | return $strarray; |
||
76 | } else { |
||
77 | $strarray[$count++] = substr($str, 0, $maxlength); |
||
78 | $str = substr($str, $maxlength); |
||
79 | } |
||
80 | } |
||
81 | return $strarray; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param $key |
||
86 | * @param $value |
||
87 | * @param $array |
||
88 | * @return int|null|string |
||
89 | * @internal param $ $ |
||
90 | */ |
||
91 | public static function getItemByProperty($key, $value, $array) { |
||
92 | foreach ($array as $_key => $val) { |
||
93 | if ($val[$key] === $value) { |
||
94 | return $val; |
||
95 | } |
||
96 | } |
||
97 | return null; |
||
98 | } |
||
99 | } |
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.