From a96f868772fb55d8ddad29acfd004e17fa0a1951 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Sun, 15 Sep 2024 11:01:04 +0200 Subject: [PATCH 1/2] chore: Add composer scripts Signed-off-by: Julius Knorr --- composer.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 36aa7df48..8622e9f46 100644 --- a/composer.json +++ b/composer.json @@ -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" + } } From d52ae38589e3bb142ae68dee2fc7503b35504423 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Sun, 15 Sep 2024 11:03:42 +0200 Subject: [PATCH 2/2] style: Apply php-cs-fixer changes Signed-off-by: Julius Knorr --- lib/Controller/NotesController.php | 2 +- lib/Service/Note.php | 10 +++++----- lib/Service/NoteUtil.php | 20 ++++++++++---------- lib/Service/NotesService.php | 8 ++++---- lib/Service/SettingsService.php | 2 +- tests/phan-config.php | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Controller/NotesController.php b/lib/Controller/NotesController.php index dfcc54a05..04279856e 100644 --- a/lib/Controller/NotesController.php +++ b/lib/Controller/NotesController.php @@ -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' diff --git a/lib/Service/Note.php b/lib/Service/Note.php index 1fb186693..61fc1bcba 100644 --- a/lib/Service/Note.php +++ b/lib/Service/Note.php @@ -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); } @@ -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)) { diff --git a/lib/Service/NoteUtil.php b/lib/Service/NoteUtil.php index 251d2e48e..924d45576 100644 --- a/lib/Service/NoteUtil.php +++ b/lib/Service/NoteUtil.php @@ -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); @@ -91,7 +91,7 @@ public function generateFileName(Folder $folder, string $title, string $suffix, // increments name (2) to name (3) $match = preg_match('/\s\((?P\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 { @@ -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); } } @@ -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)) { @@ -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; } diff --git a/lib/Service/NotesService.php b/lib/Service/NotesService.php index cce8b149f..395b39334 100644 --- a/lib/Service/NotesService.php +++ b/lib/Service/NotesService.php @@ -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); @@ -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, '.'); } /** @@ -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); @@ -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(); } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index e34263356..205a3725e 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -156,7 +156,7 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass { } } if ($toBeSaved) { - $this->set($uid, (array) $settings); + $this->set($uid, (array)$settings); } return $settings; } diff --git a/tests/phan-config.php b/tests/phan-config.php index 86ebe0098..6012bafa7 100644 --- a/tests/phan-config.php +++ b/tests/phan-config.php @@ -11,7 +11,7 @@ return [ 'directory_list' => $testDirs, - "exclude_analysis_directory_list" => [ + 'exclude_analysis_directory_list' => [ 'vendor/', ], ];