]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Manually fix remaining PHPCS errors
authorArthurHoaro <arthur@hoa.ro>
Sun, 8 Nov 2020 14:02:45 +0000 (15:02 +0100)
committerArthurHoaro <arthur@hoa.ro>
Mon, 9 Nov 2020 09:56:49 +0000 (10:56 +0100)
18 files changed:
application/History.php
application/Languages.php
application/Thumbnailer.php
application/Utils.php
application/bookmark/Bookmark.php
application/bookmark/BookmarkFileService.php
application/bookmark/BookmarkInitializer.php
application/container/ContainerBuilder.php
application/formatter/BookmarkDefaultFormatter.php
application/formatter/BookmarkMarkdownFormatter.php
application/front/controller/admin/ConfigureController.php
application/front/controller/admin/ServerController.php
application/legacy/LegacyLinkDB.php
application/updater/Updater.php
application/updater/UpdaterUtils.php
phpcs.xml
tests/legacy/LegacyUpdaterTest.php
tests/updater/UpdaterTest.php

index 1be955c57dffac27b0595ef0f65c354a445341bc..d230f39de71bf0286158240341e41d73336125c5 100644 (file)
@@ -32,27 +32,27 @@ class History
     /**
      * @var string Action key: a new link has been created.
      */
-    const CREATED = 'CREATED';
+    public const CREATED = 'CREATED';
 
     /**
      * @var string Action key: a link has been updated.
      */
-    const UPDATED = 'UPDATED';
+    public const UPDATED = 'UPDATED';
 
     /**
      * @var string Action key: a link has been deleted.
      */
-    const DELETED = 'DELETED';
+    public const DELETED = 'DELETED';
 
     /**
      * @var string Action key: settings have been updated.
      */
-    const SETTINGS = 'SETTINGS';
+    public const SETTINGS = 'SETTINGS';
 
     /**
      * @var string Action key: a bulk import has been processed.
      */
-    const IMPORT = 'IMPORT';
+    public const IMPORT = 'IMPORT';
 
     /**
      * @var string History file path.
index 8d0e13c8f07f40a10fde1945ea2aeba1fbb075be..60e916317d7abf95b3b105ec6e57ef7bbe220e94 100644 (file)
@@ -41,7 +41,7 @@ class Languages
     /**
      * Core translations domain
      */
-    const DEFAULT_DOMAIN = 'shaarli';
+    public const DEFAULT_DOMAIN = 'shaarli';
 
     /**
      * @var TranslatorInterface
@@ -122,7 +122,9 @@ class Languages
         $translations = new Translations();
         // Core translations
         try {
-            $translations = $translations->addFromPoFile('inc/languages/' . $this->language . '/LC_MESSAGES/shaarli.po');
+            $translations = $translations->addFromPoFile(
+                'inc/languages/' . $this->language . '/LC_MESSAGES/shaarli.po'
+            );
             $translations->setDomain('shaarli');
             $this->translator->loadTranslations($translations);
         } catch (\InvalidArgumentException $e) {
index 303543100f0be4247ccf16ce5ef5c3c7e22779e9..c4ff8d7abac86a87983cd9b58b9a980fae832540 100644 (file)
@@ -13,7 +13,7 @@ use WebThumbnailer\WebThumbnailer;
  */
 class Thumbnailer
 {
-    const COMMON_MEDIA_DOMAINS = [
+    protected const COMMON_MEDIA_DOMAINS = [
         'imgur.com',
         'flickr.com',
         'youtube.com',
@@ -31,9 +31,9 @@ class Thumbnailer
         'deviantart.com',
     ];
 
-    const MODE_ALL = 'all';
-    const MODE_COMMON = 'common';
-    const MODE_NONE = 'none';
+    public const MODE_ALL = 'all';
+    public const MODE_COMMON = 'common';
+    public const MODE_NONE = 'none';
 
     /**
      * @var WebThumbnailer instance.
index 4c2d670133f84b002a8b15c0c8c47815b4a23860..952378ab8620e02a360f73fd10ad4d1147afda9d 100644 (file)
@@ -382,8 +382,10 @@ function return_bytes($val)
     switch ($last) {
         case 'g':
             $val *= 1024;
+        // do no break in order 1024^2 for each unit
         case 'm':
             $val *= 1024;
+        // do no break in order 1024^2 for each unit
         case 'k':
             $val *= 1024;
     }
index b592722fba47a5046786fac3d6501ba0e07b12d5..4238ef259a8938eacaba721d6ca92e9cac6d54ae 100644 (file)
@@ -19,7 +19,7 @@ use Shaarli\Bookmark\Exception\InvalidBookmarkException;
 class Bookmark
 {
     /** @var string Date format used in string (former ID format) */
-    const LINK_DATE_FORMAT = 'Ymd_His';
+    public const LINK_DATE_FORMAT = 'Ymd_His';
 
     /** @var int Bookmark ID */
     protected $id;
index 66248cc26537ebed1dd9f0f9ecbb8faeac38703d..6666a251c821a9eb83e710ddb48973e14008261d 100644 (file)
@@ -409,14 +409,14 @@ class BookmarkFileService implements BookmarkServiceInterface
             false
         );
         $updater = new LegacyUpdater(
-            UpdaterUtils::read_updates_file($this->conf->get('resource.updates')),
+            UpdaterUtils::readUpdatesFile($this->conf->get('resource.updates')),
             $bookmarkDb,
             $this->conf,
             true
         );
         $newUpdates = $updater->update();
         if (! empty($newUpdates)) {
-            UpdaterUtils::write_updates_file(
+            UpdaterUtils::writeUpdatesFile(
                 $this->conf->get('resource.updates'),
                 $updater->getDoneUpdates()
             );
index 2240f58cd684e471b0ed832a58a4f45f3a2e47a3..8ab5c441a6eb163f2293f782965ca2ad7f0a3ccc 100644 (file)
@@ -13,6 +13,9 @@ namespace Shaarli\Bookmark;
  * To prevent data corruption, it does not overwrite existing bookmarks,
  * even though there should not be any.
  *
+ * We disable this because otherwise it creates indentation issues, and heredoc is not supported by PHP gettext.
+ * @phpcs:disable Generic.Files.LineLength.TooLong
+ *
  * @package Shaarli\Bookmark
  */
 class BookmarkInitializer
index d84418ad6f7828b99ff1fb622013451825cd8e49..f0234eca2f92a4bcca74ea99b915c18d4d2e64f4 100644 (file)
@@ -158,7 +158,7 @@ class ContainerBuilder
 
         $container['updater'] = function (ShaarliContainer $container): Updater {
             return new Updater(
-                UpdaterUtils::read_updates_file($container->conf->get('resource.updates')),
+                UpdaterUtils::readUpdatesFile($container->conf->get('resource.updates')),
                 $container->bookmarkService,
                 $container->conf,
                 $container->loginManager->isLoggedIn()
index 51bea0f15082ee2ed168446f7fd15f207f7cdd54..7e0afafc8a413f375e14992181b03c2c294e2d47 100644 (file)
@@ -12,8 +12,8 @@ namespace Shaarli\Formatter;
  */
 class BookmarkDefaultFormatter extends BookmarkFormatter
 {
-    const SEARCH_HIGHLIGHT_OPEN = '|@@HIGHLIGHT';
-    const SEARCH_HIGHLIGHT_CLOSE = 'HIGHLIGHT@@|';
+    protected const SEARCH_HIGHLIGHT_OPEN = '|@@HIGHLIGHT';
+    protected const SEARCH_HIGHLIGHT_CLOSE = 'HIGHLIGHT@@|';
 
     /**
      * @inheritdoc
index 052333ca275aceae067daf9d9eacb8e20bf83745..ee4e8dca4f993b9a6c02894e674150615e182315 100644 (file)
@@ -16,7 +16,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
     /**
      * When this tag is present in a bookmark, its description should not be processed with Markdown
      */
-    const NO_MD_TAG = 'nomarkdown';
+    public const NO_MD_TAG = 'nomarkdown';
 
     /** @var \Parsedown instance */
     protected $parsedown;
index eb26ef21f56daa2c2d0b6a1994e35eb4eab5e373..dc421661c89ea0e2470a768284513a6267210a02 100644 (file)
@@ -51,7 +51,10 @@ class ConfigureController extends ShaarliAdminController
         $this->assignView('languages', Languages::getAvailableLanguages());
         $this->assignView('gd_enabled', extension_loaded('gd'));
         $this->assignView('thumbnails_mode', $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE));
-        $this->assignView('pagetitle', t('Configure') . ' - ' . $this->container->conf->get('general.title', 'Shaarli'));
+        $this->assignView(
+            'pagetitle',
+            t('Configure') . ' - ' . $this->container->conf->get('general.title', 'Shaarli')
+        );
 
         return $response->write($this->render(TemplatePage::CONFIGURE));
     }
@@ -101,7 +104,9 @@ class ConfigureController extends ShaarliAdminController
         ) {
             $this->saveWarningMessage(
                 t('You have enabled or changed thumbnails mode.') .
-                '<a href="' . $this->container->basePath . '/admin/thumbnails">' . t('Please synchronize them.') . '</a>'
+                '<a href="' . $this->container->basePath . '/admin/thumbnails">' .
+                    t('Please synchronize them.') .
+                '</a>'
             );
         }
         $this->container->conf->set('thumbnails.mode', $thumbnailsMode);
index 809979402ebd2be76d46c46e23658e75cb8236d8..575a2f9dce082b24806b8fef0ef8ab82a62222c8 100644 (file)
@@ -65,7 +65,9 @@ class ServerController extends ShaarliAdminController
 
             $this->saveWarningMessage(
                 t('Thumbnails cache has been cleared.') . ' ' .
-                '<a href="' . $this->container->basePath . '/admin/thumbnails">' . t('Please synchronize them.') . '</a>'
+                '<a href="' . $this->container->basePath . '/admin/thumbnails">' .
+                    t('Please synchronize them.') .
+                '</a>'
             );
         } else {
             $folders = [
index 442b833c72a8eebcb4a7aba461628ad7f9451606..d3beafe0dc874b7b8aad069257f2623c13fa7e9a 100644 (file)
@@ -62,7 +62,7 @@ class LegacyLinkDB implements Iterator, Countable, ArrayAccess
     private $datastore;
 
     // Link date storage format
-    const LINK_DATE_FORMAT = 'Ymd_His';
+    public const LINK_DATE_FORMAT = 'Ymd_His';
 
     // List of bookmarks (associative array)
     //  - key:   link date (e.g. "20110823_124546"),
index 3451cf363214009c0d2c563b4b81e9d66132a0d8..4f557d0f58fabca7429684eadbf3dfcc82bb1f7c 100644 (file)
@@ -122,12 +122,12 @@ class Updater
 
     public function readUpdates(string $updatesFilepath): array
     {
-        return UpdaterUtils::read_updates_file($updatesFilepath);
+        return UpdaterUtils::readUpdatesFile($updatesFilepath);
     }
 
     public function writeUpdates(string $updatesFilepath, array $updates): void
     {
-        UpdaterUtils::write_updates_file($updatesFilepath, $updates);
+        UpdaterUtils::writeUpdatesFile($updatesFilepath, $updates);
     }
 
     /**
index 908bdc395f5bf46cbba5f1cfd09f7fdb6fbe6877..206f826eda34b5719a5605c0c4b8106206b519b1 100644 (file)
@@ -11,7 +11,7 @@ class UpdaterUtils
      *
      * @return array Already done update methods.
      */
-    public static function read_updates_file($updatesFilepath)
+    public static function readUpdatesFile($updatesFilepath)
     {
         if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
             $content = file_get_contents($updatesFilepath);
@@ -30,7 +30,7 @@ class UpdaterUtils
      *
      * @throws \Exception Couldn't write version number.
      */
-    public static function write_updates_file($updatesFilepath, $updates)
+    public static function writeUpdatesFile($updatesFilepath, $updates)
     {
         if (empty($updatesFilepath)) {
             throw new \Exception('Updates file path is not set, can\'t write updates.');
index 349dc5664f6ac626c6f982edc51f9375074508b6..c559e35da97bb4d8ec7afb229c7845fab983767f 100644 (file)
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -14,4 +14,9 @@
 
   <rule ref="PSR12"/>
   <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
+
+  <rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
+    <!--  index.php bootstraps everything, so yes mixed symbols with side effects  -->
+    <exclude-pattern>index.php</exclude-pattern>
+  </rule>
 </ruleset>
index f7391b867f593efd932aba8ae66f46ab6a1685fd..395dd4b70d37826a2434f8bfc3eb73bdad05d97d 100644 (file)
@@ -51,10 +51,10 @@ class LegacyUpdaterTest extends \Shaarli\TestCase
      */
     public function testReadEmptyUpdatesFile()
     {
-        $this->assertEquals(array(), UpdaterUtils::read_updates_file(''));
+        $this->assertEquals(array(), UpdaterUtils::readUpdatesFile(''));
         $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         touch($updatesFile);
-        $this->assertEquals(array(), UpdaterUtils::read_updates_file($updatesFile));
+        $this->assertEquals(array(), UpdaterUtils::readUpdatesFile($updatesFile));
         unlink($updatesFile);
     }
 
@@ -66,14 +66,14 @@ class LegacyUpdaterTest extends \Shaarli\TestCase
         $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         $updatesMethods = array('m1', 'm2', 'm3');
 
-        UpdaterUtils::write_updates_file($updatesFile, $updatesMethods);
-        $readMethods = UpdaterUtils::read_updates_file($updatesFile);
+        UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
+        $readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
         $this->assertEquals($readMethods, $updatesMethods);
 
         // Update
         $updatesMethods[] = 'm4';
-        UpdaterUtils::write_updates_file($updatesFile, $updatesMethods);
-        $readMethods = UpdaterUtils::read_updates_file($updatesFile);
+        UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
+        $readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
         $this->assertEquals($readMethods, $updatesMethods);
         unlink($updatesFile);
     }
@@ -86,7 +86,7 @@ class LegacyUpdaterTest extends \Shaarli\TestCase
         $this->expectException(\Exception::class);
         $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
 
-        UpdaterUtils::write_updates_file('', array('test'));
+        UpdaterUtils::writeUpdatesFile('', array('test'));
     }
 
     /**
@@ -101,7 +101,7 @@ class LegacyUpdaterTest extends \Shaarli\TestCase
         touch($updatesFile);
         chmod($updatesFile, 0444);
         try {
-            @UpdaterUtils::write_updates_file($updatesFile, array('test'));
+            @UpdaterUtils::writeUpdatesFile($updatesFile, array('test'));
         } catch (Exception $e) {
             unlink($updatesFile);
             throw $e;
index 47332544a7b254c8a56ab4adf6c80604daad5ac5..cadd826538f2e76f08bffe27bb3d105abcf43375 100644 (file)
@@ -60,10 +60,10 @@ class UpdaterTest extends TestCase
      */
     public function testReadEmptyUpdatesFile()
     {
-        $this->assertEquals(array(), UpdaterUtils::read_updates_file(''));
+        $this->assertEquals(array(), UpdaterUtils::readUpdatesFile(''));
         $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         touch($updatesFile);
-        $this->assertEquals(array(), UpdaterUtils::read_updates_file($updatesFile));
+        $this->assertEquals(array(), UpdaterUtils::readUpdatesFile($updatesFile));
         unlink($updatesFile);
     }
 
@@ -75,14 +75,14 @@ class UpdaterTest extends TestCase
         $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         $updatesMethods = array('m1', 'm2', 'm3');
 
-        UpdaterUtils::write_updates_file($updatesFile, $updatesMethods);
-        $readMethods = UpdaterUtils::read_updates_file($updatesFile);
+        UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
+        $readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
         $this->assertEquals($readMethods, $updatesMethods);
 
         // Update
         $updatesMethods[] = 'm4';
-        UpdaterUtils::write_updates_file($updatesFile, $updatesMethods);
-        $readMethods = UpdaterUtils::read_updates_file($updatesFile);
+        UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
+        $readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
         $this->assertEquals($readMethods, $updatesMethods);
         unlink($updatesFile);
     }
@@ -95,7 +95,7 @@ class UpdaterTest extends TestCase
         $this->expectException(\Exception::class);
         $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
 
-        UpdaterUtils::write_updates_file('', array('test'));
+        UpdaterUtils::writeUpdatesFile('', array('test'));
     }
 
     /**
@@ -110,7 +110,7 @@ class UpdaterTest extends TestCase
         touch($updatesFile);
         chmod($updatesFile, 0444);
         try {
-            @UpdaterUtils::write_updates_file($updatesFile, array('test'));
+            @UpdaterUtils::writeUpdatesFile($updatesFile, array('test'));
         } catch (Exception $e) {
             unlink($updatesFile);
             throw $e;