]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
namespacing: \Shaarli\Bookmark\LinkFilter
authorVirtualTam <virtualtam@flibidi.net>
Mon, 3 Dec 2018 00:22:45 +0000 (01:22 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Sat, 12 Jan 2019 21:47:48 +0000 (22:47 +0100)
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
application/Updater.php
application/bookmark/LinkDB.php
application/bookmark/LinkFilter.php [moved from application/LinkFilter.php with 93% similarity]
application/bookmark/exception/LinkNotFoundException.php [new file with mode: 0644]
composer.json
index.php
tests/bookmark/LinkDBTest.php
tests/bookmark/LinkFilterTest.php [moved from tests/LinkFilterTest.php with 96% similarity]

index 043ecf682d5a5dadd3cdf0566bb2e7cb59e297c7..ca05ecc2fca49913e3675cebe979f749308b98f9 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Shaarli\Bookmark\LinkDB;
+use Shaarli\Bookmark\LinkFilter;
 use Shaarli\Config\ConfigJson;
 use Shaarli\Config\ConfigPhp;
 use Shaarli\Config\ConfigManager;
index 3b77422a25672dce722935df120115d2309db935..6041c0884fec8547d430e38e3f432521083e08f4 100644 (file)
@@ -6,8 +6,8 @@ use ArrayAccess;
 use Countable;
 use DateTime;
 use Iterator;
-use LinkFilter;
-use LinkNotFoundException;
+use Shaarli\Bookmark\LinkFilter;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
 use Shaarli\Exceptions\IOException;
 use Shaarli\FileUtils;
 
@@ -107,10 +107,10 @@ class LinkDB implements Iterator, Countable, ArrayAccess
      *
      * Checks if the datastore exists; else, attempts to create a dummy one.
      *
-     * @param string $datastore datastore file path.
-     * @param boolean $isLoggedIn is the user logged in?
-     * @param boolean $hidePublicLinks if true all links are private.
-     * @param string $redirector link redirector set in user settings.
+     * @param string  $datastore        datastore file path.
+     * @param boolean $isLoggedIn       is the user logged in?
+     * @param boolean $hidePublicLinks  if true all links are private.
+     * @param string  $redirector       link redirector set in user settings.
      * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
      */
     public function __construct(
@@ -426,12 +426,12 @@ You use the community supported version of the original Shaarli project, by Seba
     /**
      * Filter links according to search parameters.
      *
-     * @param array $filterRequest Search request content. Supported keys:
+     * @param array  $filterRequest  Search request content. Supported keys:
      *                                - searchtags: list of tags
      *                                - searchterm: term search
-     * @param bool $casesensitive Optional: Perform case sensitive filter
-     * @param string $visibility return only all/private/public links
-     * @param string $untaggedonly return only untagged links
+     * @param bool   $casesensitive  Optional: Perform case sensitive filter
+     * @param string $visibility     return only all/private/public links
+     * @param bool   $untaggedonly   return only untagged links
      *
      * @return array filtered links, all links if no suitable filter was provided.
      */
@@ -457,8 +457,8 @@ You use the community supported version of the original Shaarli project, by Seba
     /**
      * Returns the list tags appearing in the links with the given tags
      *
-     * @param array $filteringTags tags selecting the links to consider
-     * @param string $visibility process only all/private/public links
+     * @param array  $filteringTags tags selecting the links to consider
+     * @param string $visibility    process only all/private/public links
      *
      * @return array tag => linksCount
      */
@@ -500,7 +500,7 @@ You use the community supported version of the original Shaarli project, by Seba
      * Rename or delete a tag across all links.
      *
      * @param string $from Tag to rename
-     * @param string $to New tag. If none is provided, the from tag will be deleted
+     * @param string $to   New tag. If none is provided, the from tag will be deleted
      *
      * @return array|bool List of altered links or false on error
      */
similarity index 93%
rename from application/LinkFilter.php
rename to application/bookmark/LinkFilter.php
index 91c79905280851473878059a7e6d8e57dd9b3265..9b96630737008cb2075886e339b85d6b2bbeb109 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 
-use Shaarli\Bookmark\LinkDB;
+namespace Shaarli\Bookmark;
+
+use Exception;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
 
 /**
  * Class LinkFilter.
@@ -12,22 +15,22 @@ class LinkFilter
     /**
      * @var string permalinks.
      */
-    public static $FILTER_HASH   = 'permalink';
+    public static $FILTER_HASH = 'permalink';
 
     /**
      * @var string text search.
      */
-    public static $FILTER_TEXT   = 'fulltext';
+    public static $FILTER_TEXT = 'fulltext';
 
     /**
      * @var string tag filter.
      */
-    public static $FILTER_TAG    = 'tags';
+    public static $FILTER_TAG = 'tags';
 
     /**
      * @var string filter by day.
      */
-    public static $FILTER_DAY    = 'FILTER_DAY';
+    public static $FILTER_DAY = 'FILTER_DAY';
 
     /**
      * @var string Allowed characters for hashtags (regex syntax).
@@ -60,7 +63,7 @@ class LinkFilter
      */
     public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
     {
-        if (! in_array($visibility, ['all', 'public', 'private'])) {
+        if (!in_array($visibility, ['all', 'public', 'private'])) {
             $visibility = 'all';
         }
 
@@ -119,7 +122,7 @@ class LinkFilter
         foreach ($this->links as $key => $value) {
             if ($value['private'] && $visibility === 'private') {
                 $out[$key] = $value;
-            } elseif (! $value['private'] && $visibility === 'public') {
+            } elseif (!$value['private'] && $visibility === 'public') {
                 $out[$key] = $value;
             }
         }
@@ -134,7 +137,7 @@ class LinkFilter
      *
      * @return array $filtered array containing permalink data.
      *
-     * @throws LinkNotFoundException if the smallhash doesn't match any link.
+     * @throws \Shaarli\Bookmark\Exception\LinkNotFoundException if the smallhash doesn't match any link.
      */
     private function filterSmallHash($smallHash)
     {
@@ -171,7 +174,7 @@ class LinkFilter
      *  - see https://github.com/shaarli/Shaarli/issues/75 for examples
      *
      * @param string $searchterms search query.
-     * @param string $visibility Optional: return only all/private/public links.
+     * @param string $visibility  Optional: return only all/private/public links.
      *
      * @return array search results.
      */
@@ -209,7 +212,7 @@ class LinkFilter
         foreach ($this->links as $id => $link) {
             // ignore non private links when 'privatonly' is on.
             if ($visibility !== 'all') {
-                if (! $link['private'] && $visibility === 'private') {
+                if (!$link['private'] && $visibility === 'private') {
                     continue;
                 } elseif ($link['private'] && $visibility === 'public') {
                     continue;
@@ -252,7 +255,9 @@ class LinkFilter
 
     /**
      * generate a regex fragment out of a tag
+     *
      * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
+     *
      * @return string generated regex fragment
      */
     private static function tag2regex($tag)
@@ -336,7 +341,7 @@ class LinkFilter
             // check level of visibility
             // ignore non private links when 'privateonly' is on.
             if ($visibility !== 'all') {
-                if (! $link['private'] && $visibility === 'private') {
+                if (!$link['private'] && $visibility === 'private') {
                     continue;
                 } elseif ($link['private'] && $visibility === 'public') {
                     continue;
@@ -379,7 +384,7 @@ class LinkFilter
         $filtered = [];
         foreach ($this->links as $key => $link) {
             if ($visibility !== 'all') {
-                if (! $link['private'] && $visibility === 'private') {
+                if (!$link['private'] && $visibility === 'private') {
                     continue;
                 } elseif ($link['private'] && $visibility === 'public') {
                     continue;
@@ -408,7 +413,7 @@ class LinkFilter
      */
     public function filterDay($day)
     {
-        if (! checkDateFormat('Ymd', $day)) {
+        if (!checkDateFormat('Ymd', $day)) {
             throw new Exception('Invalid date format');
         }
 
@@ -442,14 +447,3 @@ class LinkFilter
         return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
     }
 }
-
-class LinkNotFoundException extends Exception
-{
-    /**
-     * LinkNotFoundException constructor.
-     */
-    public function __construct()
-    {
-        $this->message =  t('The link you are trying to reach does not exist or has been deleted.');
-    }
-}
diff --git a/application/bookmark/exception/LinkNotFoundException.php b/application/bookmark/exception/LinkNotFoundException.php
new file mode 100644 (file)
index 0000000..f941442
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace Shaarli\Bookmark\Exception;
+
+use Exception;
+
+class LinkNotFoundException extends Exception
+{
+    /**
+     * LinkNotFoundException constructor.
+     */
+    public function __construct()
+    {
+        $this->message = t('The link you are trying to reach does not exist or has been deleted.');
+    }
+}
index e8dc2eb13c919c96258876e0d255e8493a5bac04..7d0f96b38bc29249aba887a56640f71e6936d803 100644 (file)
@@ -36,6 +36,7 @@
             "Shaarli\\Api\\Controllers\\": "application/api/controllers",
             "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
             "Shaarli\\Bookmark\\": "application/bookmark",
+            "Shaarli\\Bookmark\\Exception\\": "application/bookmark/exception",
             "Shaarli\\Config\\": "application/config/",
             "Shaarli\\Config\\Exception\\": "application/config/exception",
             "Shaarli\\Exceptions\\": "application/exceptions",
index b1d37a01cf1d83fd0c55e68b8020176060f7593f..dbb3c6fcdfe5f0ce03afe35943b1feb274c06325 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/FileUtils.php';
 require_once 'application/History.php';
-require_once 'application/LinkFilter.php';
 require_once 'application/LinkUtils.php';
 require_once 'application/NetscapeBookmarkUtils.php';
 require_once 'application/TimeZone.php';
@@ -72,6 +71,7 @@ require_once 'application/PluginManager.php';
 require_once 'application/Router.php';
 require_once 'application/Updater.php';
 
+use \Shaarli\Bookmark\Exception\LinkNotFoundException;
 use \Shaarli\Bookmark\LinkDB;
 use \Shaarli\Config\ConfigManager;
 use \Shaarli\Feed\CachedPage;
index f18a3155bd060efdf0477dd7150cc6126176a614..65409e956b3f38afb826914c109f6f3f44a8a42e 100644 (file)
@@ -6,7 +6,7 @@
 namespace Shaarli\Bookmark;
 
 use DateTime;
-use LinkNotFoundException;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
 use ReferenceLinkDB;
 use ReflectionClass;
 use Shaarli;
@@ -457,7 +457,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
     /**
      * Test filterHash() with an invalid smallhash.
      *
-     * @expectedException LinkNotFoundException
+     * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
      */
     public function testFilterHashInValid1()
     {
@@ -468,7 +468,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
     /**
      * Test filterHash() with an empty smallhash.
      *
-     * @expectedException LinkNotFoundException
+     * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
      */
     public function testFilterHashInValid()
     {
similarity index 96%
rename from tests/LinkFilterTest.php
rename to tests/bookmark/LinkFilterTest.php
index db28b1c4fec7cd275b0d4937eb6230aaa8723d78..808f81220b84e5d75d48ae3ca62983f262473a1f 100644 (file)
@@ -1,13 +1,14 @@
 <?php
 
-use Shaarli\Bookmark\LinkDB;
+namespace Shaarli\Bookmark;
 
-require_once 'application/LinkFilter.php';
+use Exception;
+use ReferenceLinkDB;
 
 /**
  * Class LinkFilterTest.
  */
-class LinkFilterTest extends PHPUnit_Framework_TestCase
+class LinkFilterTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Test datastore path.
@@ -29,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
     protected static $linkDB;
 
     /**
-     * Instanciate linkFilter with ReferenceLinkDB data.
+     * Instantiate linkFilter with ReferenceLinkDB data.
      */
     public static function setUpBeforeClass()
     {
@@ -81,10 +82,14 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
             count(
                 self::$linkFilter->filter(
                     LinkFilter::$FILTER_TAG,
-                    /*$request=*/'',
-                    /*$casesensitive=*/false,
-                    /*$visibility=*/'all',
-                    /*$untaggedonly=*/true
+                    /*$request=*/
+                    '',
+                    /*$casesensitive=*/
+                    false,
+                    /*$visibility=*/
+                    'all',
+                    /*$untaggedonly=*/
+                    true
                 )
             )
         );
@@ -229,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
     /**
      * No link for this hash
      *
-     * @expectedException LinkNotFoundException
+     * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
      */
     public function testFilterUnknownSmallHash()
     {