]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
namespacing: \Shaarli\Netscape\NetscapeBookmarkUtils
authorVirtualTam <virtualtam@flibidi.net>
Mon, 3 Dec 2018 23:13:42 +0000 (00:13 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Sat, 12 Jan 2019 22:11:19 +0000 (23:11 +0100)
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
12 files changed:
application/netscape/NetscapeBookmarkUtils.php [moved from application/NetscapeBookmarkUtils.php with 90% similarity]
composer.json
index.php
tests/netscape/BookmarkExportTest.php [moved from tests/NetscapeBookmarkUtils/BookmarkExportTest.php with 94% similarity]
tests/netscape/BookmarkImportTest.php [moved from tests/NetscapeBookmarkUtils/BookmarkImportTest.php with 99% similarity]
tests/netscape/input/empty.htm [moved from tests/NetscapeBookmarkUtils/input/empty.htm with 100% similarity]
tests/netscape/input/internet_explorer_encoding.htm [moved from tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm with 100% similarity]
tests/netscape/input/lowercase_doctype.htm [moved from tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm with 100% similarity]
tests/netscape/input/netscape_basic.htm [moved from tests/NetscapeBookmarkUtils/input/netscape_basic.htm with 100% similarity]
tests/netscape/input/netscape_nested.htm [moved from tests/NetscapeBookmarkUtils/input/netscape_nested.htm with 100% similarity]
tests/netscape/input/no_doctype.htm [moved from tests/NetscapeBookmarkUtils/input/no_doctype.htm with 100% similarity]
tests/netscape/input/same_date.htm [moved from tests/NetscapeBookmarkUtils/input/same_date.htm with 100% similarity]

similarity index 90%
rename from application/NetscapeBookmarkUtils.php
rename to application/netscape/NetscapeBookmarkUtils.php
index e0022fe1a391e333b0d58fcce8e4300fe66f2fa6..2bf928c2084da0cd286363439fe4ab281d100163 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+namespace Shaarli\Netscape;
+
+use DateTime;
+use DateTimeZone;
+use Exception;
 use Psr\Log\LogLevel;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
@@ -33,8 +38,8 @@ class NetscapeBookmarkUtils
     public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl)
     {
         // see tpl/export.html for possible values
-        if (! in_array($selection, array('all', 'public', 'private'))) {
-            throw new Exception(t('Invalid export selection:') .' "'.$selection.'"');
+        if (!in_array($selection, array('all', 'public', 'private'))) {
+            throw new Exception(t('Invalid export selection:') . ' "' . $selection . '"');
         }
 
         $bookmarkLinks = array();
@@ -86,7 +91,7 @@ class NetscapeBookmarkUtils
             $status .= vsprintf(
                 t(
                     'was successfully processed in %d seconds: '
-                    .'%d links imported, %d links overwritten, %d links skipped.'
+                    . '%d links imported, %d links overwritten, %d links skipped.'
                 ),
                 [$duration, $importCount, $overwriteCount, $skipCount]
             );
@@ -97,11 +102,11 @@ class NetscapeBookmarkUtils
     /**
      * Imports Web bookmarks from an uploaded Netscape bookmark dump
      *
-     * @param array         $post      Server $_POST parameters
-     * @param array         $files     Server $_FILES parameters
-     * @param LinkDB        $linkDb    Loaded LinkDB instance
-     * @param ConfigManager $conf      instance
-     * @param History       $history   History instance
+     * @param array         $post    Server $_POST parameters
+     * @param array         $files   Server $_FILES parameters
+     * @param LinkDB        $linkDb  Loaded LinkDB instance
+     * @param ConfigManager $conf    instance
+     * @param History       $history History instance
      *
      * @return string Summary of the bookmark import status
      */
@@ -117,7 +122,7 @@ class NetscapeBookmarkUtils
         }
 
         // Overwrite existing links?
-        $overwrite = ! empty($post['overwrite']);
+        $overwrite = !empty($post['overwrite']);
 
         // Add tags to all imported links?
         if (empty($post['default_tags'])) {
@@ -140,7 +145,7 @@ class NetscapeBookmarkUtils
         );
         $logger = new Logger(
             $conf->get('resource.data_dir'),
-            ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
+            !$conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
             [
                 'prefix' => 'import.',
                 'extension' => 'log',
@@ -195,7 +200,7 @@ class NetscapeBookmarkUtils
             }
 
             // Add a new link - @ used for UNIX timestamps
-            $newLinkDate = new DateTime('@'.strval($bkm['time']));
+            $newLinkDate = new DateTime('@' . strval($bkm['time']));
             $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
             $newLink['created'] = $newLinkDate;
             $newLink['id'] = $linkDb->getNextId();
index af7634729845223d74e0d813c3c7e3d92d6a3781..c1f47317b8bd92058cc916631e520bb9efd9a7a4 100644 (file)
@@ -45,6 +45,7 @@
             "Shaarli\\Exceptions\\": "application/exceptions",
             "Shaarli\\Feed\\": "application/feed",
             "Shaarli\\Http\\": "application/http",
+            "Shaarli\\Netscape\\": "application/netscape",
             "Shaarli\\Render\\": "application/render",
             "Shaarli\\Security\\": "application/security",
             "Shaarli\\Updater\\": "application/updater",
index 1dec569ce0b4197028ef0f2099dbaf5413b3720e..bff8e8ff14f24f5de02eb7be20ef8e5901afb48d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -63,7 +63,6 @@ require_once 'application/http/HttpUtils.php';
 require_once 'application/http/UrlUtils.php';
 require_once 'application/updater/UpdaterUtils.php';
 require_once 'application/FileUtils.php';
-require_once 'application/NetscapeBookmarkUtils.php';
 require_once 'application/TimeZone.php';
 require_once 'application/Utils.php';
 require_once 'application/PluginManager.php';
@@ -76,6 +75,7 @@ use \Shaarli\Feed\CachedPage;
 use \Shaarli\Feed\FeedBuilder;
 use \Shaarli\History;
 use \Shaarli\Languages;
+use \Shaarli\Netscape\NetscapeBookmarkUtils;
 use \Shaarli\Render\PageBuilder;
 use \Shaarli\Render\ThemeUtils;
 use \Shaarli\Router;
similarity index 94%
rename from tests/NetscapeBookmarkUtils/BookmarkExportTest.php
rename to tests/netscape/BookmarkExportTest.php
index adf854c59df90b114cc2592940aeed2d9930f44d..6de9876d419701cd76bcf7078b3c57a718e13510 100644 (file)
@@ -1,13 +1,14 @@
 <?php
+namespace Shaarli\Netscape;
 
 use Shaarli\Bookmark\LinkDB;
 
-require_once 'application/NetscapeBookmarkUtils.php';
+require_once 'tests/utils/ReferenceLinkDB.php';
 
 /**
  * Netscape bookmark export
  */
-class BookmarkExportTest extends PHPUnit_Framework_TestCase
+class BookmarkExportTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations
@@ -15,7 +16,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
     protected static $testDatastore = 'sandbox/datastore.php';
 
     /**
-     * @var ReferenceLinkDB instance.
+     * @var \ReferenceLinkDB instance.
      */
     protected static $refDb = null;
 
@@ -29,7 +30,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
      */
     public static function setUpBeforeClass()
     {
-        self::$refDb = new ReferenceLinkDB();
+        self::$refDb = new \ReferenceLinkDB();
         self::$refDb->write(self::$testDatastore);
         self::$linkDb = new LinkDB(self::$testDatastore, true, false);
     }
similarity index 99%
rename from tests/NetscapeBookmarkUtils/BookmarkImportTest.php
rename to tests/netscape/BookmarkImportTest.php
index 98c989bcebfa67d27ab990fd15cba7726e038535..ccafc1619cf48d988fef4e4a62d44f5f81789a88 100644 (file)
@@ -1,7 +1,7 @@
 <?php
+namespace Shaarli\Netscape;
 
-require_once 'application/NetscapeBookmarkUtils.php';
-
+use DateTime;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
@@ -28,7 +28,7 @@ function file2array($filename)
 /**
  * Netscape bookmark import
  */
-class BookmarkImportTest extends PHPUnit_Framework_TestCase
+class BookmarkImportTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string datastore to test write operations