From: VirtualTam Date: Mon, 3 Dec 2018 00:22:45 +0000 (+0100) Subject: namespacing: \Shaarli\Bookmark\LinkFilter X-Git-Tag: v0.11.0~43^2~11 X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=commitdiff_plain;h=6696729b88e67504fdd333cbaab43a63c3617d86 namespacing: \Shaarli\Bookmark\LinkFilter Signed-off-by: VirtualTam --- diff --git a/application/Updater.php b/application/Updater.php index 043ecf68..ca05ecc2 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -1,6 +1,7 @@ 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 */ diff --git a/application/LinkFilter.php b/application/bookmark/LinkFilter.php similarity index 93% rename from application/LinkFilter.php rename to application/bookmark/LinkFilter.php index 91c79905..9b966307 100644 --- a/application/LinkFilter.php +++ b/application/bookmark/LinkFilter.php @@ -1,6 +1,9 @@ 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 index 00000000..f9414428 --- /dev/null +++ b/application/bookmark/exception/LinkNotFoundException.php @@ -0,0 +1,15 @@ +message = t('The link you are trying to reach does not exist or has been deleted.'); + } +} diff --git a/composer.json b/composer.json index e8dc2eb1..7d0f96b3 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/index.php b/index.php index b1d37a01..dbb3c6fc 100644 --- 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; diff --git a/tests/bookmark/LinkDBTest.php b/tests/bookmark/LinkDBTest.php index f18a3155..65409e95 100644 --- a/tests/bookmark/LinkDBTest.php +++ b/tests/bookmark/LinkDBTest.php @@ -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() { diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php similarity index 96% rename from tests/LinkFilterTest.php rename to tests/bookmark/LinkFilterTest.php index db28b1c4..808f8122 100644 --- a/tests/LinkFilterTest.php +++ b/tests/bookmark/LinkFilterTest.php @@ -1,13 +1,14 @@ 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() {