Skip to content

Commit 0d9779d

Browse files
authored
Merge pull request #1364 from nextcloud/fix/php-cs
Fix CI
2 parents 792e8c4 + d52ae38 commit 0d9779d

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

composer.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,14 @@
1313
"OCA\\Notes\\Tests\\API\\": "tests/api/"
1414
}
1515
},
16-
"prefer-stable": true
16+
"prefer-stable": true,
17+
"scripts": {
18+
"test": [
19+
"@test:unit"
20+
],
21+
"test:unit": "./vendor/bin/phpunit -c tests/unit/phpunit.xml",
22+
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
23+
"cs:check": "php-cs-fixer fix --dry-run --diff",
24+
"cs:fix": "php-cs-fixer fix"
25+
}
1726
}

lib/Controller/NotesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function index(int $pruneBefore = 0) : JSONResponse {
5959
// initialize and load settings
6060
$settings = $this->settingsService->getAll($userId, true);
6161

62-
$lastViewedNote = (int) $this->settings->getUserValue(
62+
$lastViewedNote = (int)$this->settings->getUserValue(
6363
$userId,
6464
$this->appName,
6565
'notesLastViewedNote'

lib/Service/Note.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public function getExcerpt(int $maxlen = 100) : string {
6060
$excerpt = trim($this->noteUtil->stripMarkdown($this->getContent()));
6161
$title = $this->getTitle();
6262
if (!empty($title)) {
63-
$length = mb_strlen($title, "utf-8");
63+
$length = mb_strlen($title, 'utf-8');
6464
if (strncasecmp($excerpt, $title, $length) === 0) {
65-
$excerpt = mb_substr($excerpt, $length, null, "utf-8");
65+
$excerpt = mb_substr($excerpt, $length, null, 'utf-8');
6666
}
6767
}
6868
$excerpt = trim($excerpt);
69-
if (mb_strlen($excerpt, "utf-8") > $maxlen) {
70-
$excerpt = mb_substr($excerpt, 0, $maxlen, "utf-8") . '';
69+
if (mb_strlen($excerpt, 'utf-8') > $maxlen) {
70+
$excerpt = mb_substr($excerpt, 0, $maxlen, 'utf-8') . '';
7171
}
7272
return str_replace("\n", "\u{2003}", $excerpt);
7373
}
@@ -107,7 +107,7 @@ public function getData(array $exclude = []) : array {
107107
}
108108
$data['internalPath'] = $this->noteUtil->getPathForUser($this->file);
109109
$data['shareTypes'] = $this->noteUtil->getShareTypes($this->file);
110-
$data['isShared'] = (bool) count($data['shareTypes']);
110+
$data['isShared'] = (bool)count($data['shareTypes']);
111111
$data['error'] = false;
112112
$data['errorType'] = '';
113113
if (!in_array('content', $exclude)) {

lib/Service/NoteUtil.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public function getCategoryFolder(Folder $notesFolder, string $category) {
7474
* @param string $title the filename which should be used
7575
* @param string $suffix the suffix (incl. dot) which should be used
7676
* @param int $id the id of the note for which the title should be generated
77-
* used to see if the file itself has the title and not a different file for
78-
* checking for filename collisions
77+
* used to see if the file itself has the title and not a different file for
78+
* checking for filename collisions
7979
* @return string the resolved filename to prevent overwriting different
80-
* files with the same title
80+
* files with the same title
8181
*/
8282
public function generateFileName(Folder $folder, string $title, string $suffix, int $id) : string {
8383
$title = $this->getSafeTitle($title);
@@ -91,7 +91,7 @@ public function generateFileName(Folder $folder, string $title, string $suffix,
9191
// increments name (2) to name (3)
9292
$match = preg_match('/\s\((?P<id>\d+)\)$/u', $title, $matches);
9393
if ($match) {
94-
$newId = ((int) $matches['id']) + 1;
94+
$newId = ((int)$matches['id']) + 1;
9595
$baseTitle = preg_replace('/\s\(\d+\)$/u', '', $title);
9696
$idSuffix = ' (' . $newId . ')';
9797
} else {
@@ -100,7 +100,7 @@ public function generateFileName(Folder $folder, string $title, string $suffix,
100100
}
101101
// make sure there's enough room for the ID suffix before appending or it will be
102102
// trimmed by getSafeTitle() and could cause infinite recursion
103-
$newTitle = mb_substr($baseTitle, 0, self::MAX_TITLE_LENGTH - mb_strlen($idSuffix), "UTF-8") . $idSuffix;
103+
$newTitle = mb_substr($baseTitle, 0, self::MAX_TITLE_LENGTH - mb_strlen($idSuffix), 'UTF-8') . $idSuffix;
104104
return $this->generateFileName($folder, $newTitle, $suffix, $id);
105105
}
106106
}
@@ -117,7 +117,7 @@ public function getSafeTitle(string $content) : string {
117117
$title = preg_replace('/\s/u', ' ', $title);
118118

119119
// using a maximum of 100 chars should be enough
120-
$title = mb_substr($title, 0, self::MAX_TITLE_LENGTH, "UTF-8");
120+
$title = mb_substr($title, 0, self::MAX_TITLE_LENGTH, 'UTF-8');
121121

122122
// ensure that title is not empty
123123
if (empty($title)) {
@@ -151,10 +151,10 @@ private function sanitisePath(string $str) : string {
151151

152152
public function stripMarkdown(string $str) : string {
153153
// prepare content: remove markdown characters and empty spaces
154-
$str = preg_replace("/^\s*[*+-]\s+/mu", "", $str); // list item
155-
$str = preg_replace("/^#+\s+(.*?)\s*#*$/mu", "$1", $str); // headline
156-
$str = preg_replace("/^(=+|-+)$/mu", "", $str); // separate line for headline
157-
$str = preg_replace("/(\*+|_+)(.*?)\\1/mu", "$2", $str); // emphasis
154+
$str = preg_replace("/^\s*[*+-]\s+/mu", '', $str); // list item
155+
$str = preg_replace("/^#+\s+(.*?)\s*#*$/mu", '$1', $str); // headline
156+
$str = preg_replace('/^(=+|-+)$/mu', '', $str); // separate line for headline
157+
$str = preg_replace("/(\*+|_+)(.*?)\\1/mu", '$2', $str); // emphasis
158158
return $str;
159159
}
160160

lib/Service/NotesService.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function create(string $userId, string $title, string $category) : Note {
120120

121121
// get file name
122122
$fileSuffix = $this->settings->get($userId, 'fileSuffix');
123-
if ($fileSuffix === "custom") {
123+
if ($fileSuffix === 'custom') {
124124
$fileSuffix = $this->settings->get($userId, 'customSuffix');
125125
}
126126
$filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1);
@@ -194,7 +194,7 @@ private static function isNote(FileInfo $file, string $customExtension) : bool {
194194
*/
195195
private function getCustomExtension(string $userId) {
196196
$suffix = $this->settings->get($userId, 'customSuffix');
197-
return ltrim($suffix, ".");
197+
return ltrim($suffix, '.');
198198
}
199199

200200
/**
@@ -238,7 +238,7 @@ public function getAttachment(string $userId, int $noteid, string $path) : File
238238
* @param $fileDataArray
239239
* @throws NotPermittedException
240240
* @throws ImageNotWritableException
241-
* https://github.com/nextcloud/deck/blob/master/lib/Service/AttachmentService.php
241+
* https://github.com/nextcloud/deck/blob/master/lib/Service/AttachmentService.php
242242
*/
243243
public function createImage(string $userId, int $noteid, $fileDataArray) {
244244
$note = $this->get($userId, $noteid);
@@ -253,7 +253,7 @@ public function createImage(string $userId, int $noteid, $fileDataArray) {
253253
}
254254
$filename = $filename . '.' . explode('.', $fileDataArray['name'])[1];
255255

256-
if ($fileDataArray['tmp_name'] === "") {
256+
if ($fileDataArray['tmp_name'] === '') {
257257
throw new ImageNotWritableException();
258258
}
259259

lib/Service/SettingsService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass {
156156
}
157157
}
158158
if ($toBeSaved) {
159-
$this->set($uid, (array) $settings);
159+
$this->set($uid, (array)$settings);
160160
}
161161
return $settings;
162162
}

tests/phan-config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
return [
1313
'directory_list' => $testDirs,
14-
"exclude_analysis_directory_list" => [
14+
'exclude_analysis_directory_list' => [
1515
'vendor/',
1616
],
1717
];

0 commit comments

Comments
 (0)