Skip to content

Commit

Permalink
Merge pull request #1364 from nextcloud/fix/php-cs
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
juliusknorr authored Sep 15, 2024
2 parents 792e8c4 + d52ae38 commit 0d9779d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
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 @@ -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;
}
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/',
],
];

0 comments on commit 0d9779d

Please sign in to comment.