Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #1364

Merged
merged 2 commits into from
Sep 15, 2024
Merged

Fix CI #1364

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@
"OCA\\Notes\\Tests\\API\\": "tests/api/"
}
},
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"test": [
"@test:unit"
],
"test:unit": "./vendor/bin/phpunit -c tests/unit/phpunit.xml",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix"
}
}
2 changes: 1 addition & 1 deletion lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function index(int $pruneBefore = 0) : JSONResponse {
// initialize and load settings
$settings = $this->settingsService->getAll($userId, true);

$lastViewedNote = (int) $this->settings->getUserValue(
$lastViewedNote = (int)$this->settings->getUserValue(
$userId,
$this->appName,
'notesLastViewedNote'
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public function getExcerpt(int $maxlen = 100) : string {
$excerpt = trim($this->noteUtil->stripMarkdown($this->getContent()));
$title = $this->getTitle();
if (!empty($title)) {
$length = mb_strlen($title, "utf-8");
$length = mb_strlen($title, 'utf-8');
if (strncasecmp($excerpt, $title, $length) === 0) {
$excerpt = mb_substr($excerpt, $length, null, "utf-8");
$excerpt = mb_substr($excerpt, $length, null, 'utf-8');
}
}
$excerpt = trim($excerpt);
if (mb_strlen($excerpt, "utf-8") > $maxlen) {
$excerpt = mb_substr($excerpt, 0, $maxlen, "utf-8") . '…';
if (mb_strlen($excerpt, 'utf-8') > $maxlen) {
$excerpt = mb_substr($excerpt, 0, $maxlen, 'utf-8') . '…';
}
return str_replace("\n", "\u{2003}", $excerpt);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public function getData(array $exclude = []) : array {
}
$data['internalPath'] = $this->noteUtil->getPathForUser($this->file);
$data['shareTypes'] = $this->noteUtil->getShareTypes($this->file);
$data['isShared'] = (bool) count($data['shareTypes']);
$data['isShared'] = (bool)count($data['shareTypes']);
$data['error'] = false;
$data['errorType'] = '';
if (!in_array('content', $exclude)) {
Expand Down
20 changes: 10 additions & 10 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function getCategoryFolder(Folder $notesFolder, string $category) {
* @param string $title the filename which should be used
* @param string $suffix the suffix (incl. dot) which should be used
* @param int $id the id of the note for which the title should be generated
* used to see if the file itself has the title and not a different file for
* checking for filename collisions
* used to see if the file itself has the title and not a different file for
* checking for filename collisions
* @return string the resolved filename to prevent overwriting different
* files with the same title
* files with the same title
*/
public function generateFileName(Folder $folder, string $title, string $suffix, int $id) : string {
$title = $this->getSafeTitle($title);
Expand All @@ -91,7 +91,7 @@ public function generateFileName(Folder $folder, string $title, string $suffix,
// increments name (2) to name (3)
$match = preg_match('/\s\((?P<id>\d+)\)$/u', $title, $matches);
if ($match) {
$newId = ((int) $matches['id']) + 1;
$newId = ((int)$matches['id']) + 1;
$baseTitle = preg_replace('/\s\(\d+\)$/u', '', $title);
$idSuffix = ' (' . $newId . ')';
} else {
Expand All @@ -100,7 +100,7 @@ public function generateFileName(Folder $folder, string $title, string $suffix,
}
// make sure there's enough room for the ID suffix before appending or it will be
// trimmed by getSafeTitle() and could cause infinite recursion
$newTitle = mb_substr($baseTitle, 0, self::MAX_TITLE_LENGTH - mb_strlen($idSuffix), "UTF-8") . $idSuffix;
$newTitle = mb_substr($baseTitle, 0, self::MAX_TITLE_LENGTH - mb_strlen($idSuffix), 'UTF-8') . $idSuffix;
return $this->generateFileName($folder, $newTitle, $suffix, $id);
}
}
Expand All @@ -117,7 +117,7 @@ public function getSafeTitle(string $content) : string {
$title = preg_replace('/\s/u', ' ', $title);

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function create(string $userId, string $title, string $category) : Note {

// get file name
$fileSuffix = $this->settings->get($userId, 'fileSuffix');
if ($fileSuffix === "custom") {
if ($fileSuffix === 'custom') {
$fileSuffix = $this->settings->get($userId, 'customSuffix');
}
$filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1);
Expand Down Expand Up @@ -194,7 +194,7 @@ private static function isNote(FileInfo $file, string $customExtension) : bool {
*/
private function getCustomExtension(string $userId) {
$suffix = $this->settings->get($userId, 'customSuffix');
return ltrim($suffix, ".");
return ltrim($suffix, '.');
}

/**
Expand Down Expand Up @@ -238,7 +238,7 @@ public function getAttachment(string $userId, int $noteid, string $path) : File
* @param $fileDataArray
* @throws NotPermittedException
* @throws ImageNotWritableException
* https://github.com/nextcloud/deck/blob/master/lib/Service/AttachmentService.php
* https://github.com/nextcloud/deck/blob/master/lib/Service/AttachmentService.php
*/
public function createImage(string $userId, int $noteid, $fileDataArray) {
$note = $this->get($userId, $noteid);
Expand All @@ -253,7 +253,7 @@ public function createImage(string $userId, int $noteid, $fileDataArray) {
}
$filename = $filename . '.' . explode('.', $fileDataArray['name'])[1];

if ($fileDataArray['tmp_name'] === "") {
if ($fileDataArray['tmp_name'] === '') {
throw new ImageNotWritableException();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}

private function getListAttrs(string $attributeName, array $values) : array {
$default = $this->config->getAppValue(Application::APP_ID, $attributeName, $values[0]);

Check warning on line 70 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / lint-php (max)

Call to deprecated function \OCP\IConfig::getAppValue() defined at vendor/nextcloud/ocp/OCP/IConfig.php:134 (Deprecated because: 29.0.0 Use {@see IAppConfig} directly)

return [
'default' => $default,
Expand All @@ -82,7 +82,7 @@
}

public function getDefaultNotesPath(string $uid) : string {
$defaultFolder = $this->config->getAppValue(Application::APP_ID, 'defaultFolder', 'Notes');

Check warning on line 85 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / lint-php (max)

Call to deprecated function \OCP\IConfig::getAppValue() defined at vendor/nextcloud/ocp/OCP/IConfig.php:134 (Deprecated because: 29.0.0 Use {@see IAppConfig} directly)
$defaultExists = $this->root->getUserFolder($uid)->nodeExists($defaultFolder);
if ($defaultExists) {
return $defaultFolder;
Expand All @@ -107,7 +107,7 @@
if ($value !== null && array_key_exists($name, $this->attrs)) {
$settings[$name] = $value = $this->attrs[$name]['validate']($value);
}
$default = is_callable($this->attrs[$name]['default']) ? $this->attrs[$name]['default']($uid) : $this->attrs[$name]['default'];

Check warning on line 110 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / lint-php (min)

Line exceeds 120 characters; contains 139 characters

Check warning on line 110 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / lint-php (max)

Line exceeds 120 characters; contains 139 characters
if (!$writeDefaults && (!array_key_exists($name, $this->attrs)
|| $value === null
|| $value === $default
Expand Down Expand Up @@ -156,7 +156,7 @@
}
}
if ($toBeSaved) {
$this->set($uid, (array) $settings);
$this->set($uid, (array)$settings);
}
return $settings;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phan-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

return [
'directory_list' => $testDirs,
"exclude_analysis_directory_list" => [
'exclude_analysis_directory_list' => [
'vendor/',
],
];
Loading