Skip to content

Commit

Permalink
php-cs: add more rules
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Oct 15, 2023
1 parent 03c55a8 commit 465c5f2
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 9 deletions.
11 changes: 9 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'parameters', 'arguments']],
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead
'modernize_strpos' => false, // needs PHP 8+ or polyfill
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress', 'template-implements']],
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'parameters', 'arguments']],
'modernize_strpos' => true,
'no_alias_functions' => true,
'array_syntax' => ['syntax' => 'short'],
'ternary_to_elvis_operator' => true,
'ternary_to_null_coalescing' => true,
'return_assignment' => true,
'declare_strict_types' => true,
'strict_param' => true,
])
->setFinder($finder)
;
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function setSystemConfig(string $key, $value): Http\Response
Util::setSystemConfig($key, $value);

// If changing vod settings, kill any running go-vod instances
if (0 === strpos($key, 'memories.vod.')) {
if (str_starts_with($key, 'memories.vod.')) {
try {
BinExt::startGoVod();
} catch (\Exception $e) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/FoldersController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Controller;

use OCA\Memories\Db\TimelineRoot;
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Controller;

use OCA\Files\Event\LoadSidebar;
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/PublicAlbumController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Controller;

use OCA\Memories\AppInfo\Application;
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Controller;

use OCA\Memories\AppInfo\Application;
Expand Down Expand Up @@ -185,7 +187,7 @@ protected function redirectIfOwned(IShare $share): void
$foldersPath = Util::sanitizePath('/'.$foldersPath.'/');

// Check if relPath starts with foldersPath
if (0 !== strpos($relPath, $foldersPath)) {
if (!str_starts_with($relPath, $foldersPath)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function transcode(string $client, int $fileid, string $profile): Http\Re

// Check if file starts with temp dir
$tmpDir = sys_get_temp_dir();
if (0 === strpos($path, $tmpDir)) {
if (str_starts_with($path, $tmpDir)) {
throw Exceptions::Forbidden('files in temp directory not supported');
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Cron/IndexJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Cron;

use OCA\Memories\AppInfo\Application;
Expand Down
2 changes: 2 additions & 0 deletions lib/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Db;

use OC\DB\SchemaWrapper;
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/TimelineQueryDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function executeQueryWithCTEs(IQueryBuilder $query, string $psql = ''): \
: self::CTE_FOLDERS(\array_key_exists('cteIncludeHidden', $params));

// Add WITH clause if needed
if (false !== strpos($sql, 'cte_folders')) {
if (str_contains($sql, 'cte_folders')) {
$sql = $CTE_SQL.' '.$sql;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static function setExif(string $path, array $data): void
fclose($pipes[2]);
proc_terminate($proc);
proc_close($proc);
if (false !== strpos($stdout, 'error')) {
if (str_contains($stdout, 'error')) {
error_log("Exiftool error: {$stdout}");

throw new \Exception('Could not set exif data: '.$stdout);
Expand Down
2 changes: 2 additions & 0 deletions lib/ExifFields.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is the list of fields that will be STORED in the databse as JSON.
* This is mostly only used for the metadata view.
Expand Down
2 changes: 2 additions & 0 deletions lib/HttpResponseException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories;

use OCP\AppFramework\Http;
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/Places.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Service;

use OCA\Memories\Db\TimelineWrite;
Expand Down Expand Up @@ -36,7 +38,7 @@ public function detectGisType(): int
}

// Detect database type
$platform = strtolower(\get_class($this->connection->getDatabasePlatform()));
$platform = strtolower($this->connection->getDatabasePlatform()::class);

// Test MySQL-like support in databse
if (str_contains($platform, 'mysql') || str_contains($platform, 'mariadb')) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Settings;

use OCA\Memories\AppInfo\Application;
Expand Down
2 changes: 2 additions & 0 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OCA\Memories\Settings;

use OCP\AppFramework\Http\TemplateResponse;
Expand Down
2 changes: 2 additions & 0 deletions lib/SystemConfigDefault.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
// Path to exiftool binary
'memories.exiftool' => '',
Expand Down
2 changes: 1 addition & 1 deletion lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public static function callerIsNative(): bool
return 'gallery.memories' === $_SERVER['HTTP_X_REQUESTED_WITH'];
}

return false !== strpos($_SERVER['HTTP_USER_AGENT'] ?? '', 'MemoriesNative');
return str_contains($_SERVER['HTTP_USER_AGENT'] ?? '', 'MemoriesNative');
}

/**
Expand Down

0 comments on commit 465c5f2

Please sign in to comment.