From dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Mon, 3 Dec 2018 00:08:04 +0100 Subject: [PATCH] namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder} Signed-off-by: VirtualTam --- application/{ => feed}/Cache.php | 0 application/{ => feed}/CachedPage.php | 4 ++- application/{ => feed}/FeedBuilder.php | 37 ++++++++++++++------------ composer.json | 1 + index.php | 8 +++--- plugins/pubsubhubbub/pubsubhubbub.php | 1 + tests/LinkDBTest.php | 4 +-- tests/{ => feed}/CacheTest.php | 23 ++++++++-------- tests/{ => feed}/CachedPageTest.php | 9 +++---- tests/{ => feed}/FeedBuilderTest.php | 11 +++++--- 10 files changed, 54 insertions(+), 44 deletions(-) rename application/{ => feed}/Cache.php (100%) rename application/{ => feed}/CachedPage.php (93%) rename application/{ => feed}/FeedBuilder.php (87%) rename tests/{ => feed}/CacheTest.php (68%) rename tests/{ => feed}/CachedPageTest.php (92%) rename tests/{ => feed}/FeedBuilderTest.php (97%) diff --git a/application/Cache.php b/application/feed/Cache.php similarity index 100% rename from application/Cache.php rename to application/feed/Cache.php diff --git a/application/CachedPage.php b/application/feed/CachedPage.php similarity index 93% rename from application/CachedPage.php rename to application/feed/CachedPage.php index e11cc52d..1c51ac73 100644 --- a/application/CachedPage.php +++ b/application/feed/CachedPage.php @@ -1,4 +1,6 @@ cacheDir = $cacheDir; - $this->filename = $this->cacheDir.'/'.sha1($url).'.cache'; + $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache'; $this->shouldBeCached = $shouldBeCached; } diff --git a/application/FeedBuilder.php b/application/feed/FeedBuilder.php similarity index 87% rename from application/FeedBuilder.php rename to application/feed/FeedBuilder.php index 73fafcbe..dcfd2c89 100644 --- a/application/FeedBuilder.php +++ b/application/feed/FeedBuilder.php @@ -1,4 +1,8 @@ hideDates || $this->isLoggedIn; // Remove leading slash from REQUEST_URI. $data['self_link'] = escape(server_url($this->serverInfo)) - . escape($this->serverInfo['REQUEST_URI']); + . escape($this->serverInfo['REQUEST_URI']); $data['index_url'] = $pageaddr; $data['usepermalinks'] = $this->usePermalinks === true; $data['links'] = $linkDisplayed; @@ -142,18 +146,18 @@ class FeedBuilder */ protected function buildItem($link, $pageaddr) { - $link['guid'] = $pageaddr .'?'. $link['shorturl']; + $link['guid'] = $pageaddr . '?' . $link['shorturl']; // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = $pageaddr . $link['url']; } if ($this->usePermalinks === true) { - $permalink = ''. t('Direct link') .''; + $permalink = '' . t('Direct link') . ''; } else { - $permalink = ''. t('Permalink') .''; + $permalink = '' . t('Permalink') . ''; } - $link['description'] = format_description($link['description'], '', false, $pageaddr); - $link['description'] .= PHP_EOL .'
— '. $permalink; + $link['description'] = format_description($link['description'], '', false, $pageaddr); + $link['description'] .= PHP_EOL . '
— ' . $permalink; $pubDate = $link['created']; $link['pub_iso_date'] = $this->getIsoDate($pubDate); @@ -164,7 +168,6 @@ class FeedBuilder $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); } else { $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM); - ; } // Save the more recent item. @@ -223,11 +226,11 @@ class FeedBuilder public function getTypeLanguage() { // Use the locale do define the language, if available. - if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { - $length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; + if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { + $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2; return str_replace('_', '-', substr($this->locale, 0, $length)); } - return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en'; + return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en'; } /** @@ -287,7 +290,7 @@ class FeedBuilder } $intNb = intval($this->userInput['nb']); - if (! is_int($intNb) || $intNb == 0) { + if (!is_int($intNb) || $intNb == 0) { return self::$DEFAULT_NB_LINKS; } diff --git a/composer.json b/composer.json index 027203f4..7c9cbf3d 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "Shaarli\\Config\\": "application/config/", "Shaarli\\Config\\Exception\\": "application/config/exception", "Shaarli\\Exceptions\\": "application/exceptions", + "Shaarli\\Feed\\": "application/feed", "Shaarli\\Security\\": "application/security" } } diff --git a/index.php b/index.php index cc41d80c..6d1ae3fc 100644 --- a/index.php +++ b/index.php @@ -57,10 +57,8 @@ require_once __DIR__ . '/vendor/autoload.php'; // Shaarli library require_once 'application/ApplicationUtils.php'; -require_once 'application/Cache.php'; -require_once 'application/CachedPage.php'; require_once 'application/config/ConfigPlugin.php'; -require_once 'application/FeedBuilder.php'; +require_once 'application/feed/Cache.php'; require_once 'application/FileUtils.php'; require_once 'application/History.php'; require_once 'application/HttpUtils.php'; @@ -76,7 +74,9 @@ require_once 'application/PluginManager.php'; require_once 'application/Router.php'; require_once 'application/Updater.php'; use \Shaarli\Config\ConfigManager; -use Shaarli\History; +use \Shaarli\Feed\CachedPage; +use \Shaarli\Feed\FeedBuilder; +use \Shaarli\History; use \Shaarli\Languages; use \Shaarli\Security\LoginManager; use \Shaarli\Security\SessionManager; diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 9f0342a3..1872af8a 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -11,6 +11,7 @@ use pubsubhubbub\publisher\Publisher; use Shaarli\Config\ConfigManager; +use Shaarli\Feed\FeedBuilder; /** * Plugin init function - set the hub to the default appspot one. diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 9b2f35e6..737a2247 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -3,9 +3,7 @@ * Link datastore tests */ -use Shaarli\Exceptions\IOException; - -require_once 'application/Cache.php'; +require_once 'application/feed/Cache.php'; require_once 'application/FileUtils.php'; require_once 'application/LinkDB.php'; require_once 'application/Utils.php'; diff --git a/tests/CacheTest.php b/tests/feed/CacheTest.php similarity index 68% rename from tests/CacheTest.php rename to tests/feed/CacheTest.php index f60fad91..c0a9f26f 100644 --- a/tests/CacheTest.php +++ b/tests/feed/CacheTest.php @@ -2,16 +2,17 @@ /** * Cache tests */ +namespace Shaarli\Feed; // required to access $_SESSION array session_start(); -require_once 'application/Cache.php'; +require_once 'application/feed/Cache.php'; /** * Unitary tests for cached pages */ -class CacheTest extends PHPUnit_Framework_TestCase +class CacheTest extends \PHPUnit\Framework\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/dummycache'; @@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase */ public function setUp() { - if (! is_dir(self::$testCacheDir)) { + if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); } else { - array_map('unlink', glob(self::$testCacheDir.'/*')); + array_map('unlink', glob(self::$testCacheDir . '/*')); } foreach (self::$pages as $page) { - file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); + file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page); } - file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); + file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere'); } /** @@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase */ public function tearDown() { - array_map('unlink', glob(self::$testCacheDir.'/*')); + array_map('unlink', glob(self::$testCacheDir . '/*')); rmdir(self::$testCacheDir); } @@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase { purgeCachedPages(self::$testCacheDir); foreach (self::$pages as $page) { - $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache'); } - $this->assertFileExists(self::$testCacheDir.'/intru.der'); + $this->assertFileExists(self::$testCacheDir . '/intru.der'); } /** @@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase ini_set('error_log', '/dev/null'); $this->assertEquals( 'Cannot purge sandbox/dummycache_missing: no directory', - purgeCachedPages(self::$testCacheDir.'_missing') + purgeCachedPages(self::$testCacheDir . '_missing') ); ini_set('error_log', $oldlog); } @@ -83,7 +84,7 @@ class CacheTest extends PHPUnit_Framework_TestCase invalidateCaches(self::$testCacheDir); foreach (self::$pages as $page) { - $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); + $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache'); } $this->assertArrayNotHasKey('tags', $_SESSION); diff --git a/tests/CachedPageTest.php b/tests/feed/CachedPageTest.php similarity index 92% rename from tests/CachedPageTest.php rename to tests/feed/CachedPageTest.php index 51565cd6..0bcc1442 100644 --- a/tests/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -2,13 +2,12 @@ /** * PageCache tests */ - -require_once 'application/CachedPage.php'; +namespace Shaarli\Feed; /** * Unitary tests for cached pages */ -class CachedPageTest extends PHPUnit_Framework_TestCase +class CachedPageTest extends \PHPUnit\Framework\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/pagecache'; @@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase */ public static function setUpBeforeClass() { - if (! is_dir(self::$testCacheDir)) { + if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); } - self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache'; + self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache'; } /** diff --git a/tests/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php similarity index 97% rename from tests/FeedBuilderTest.php rename to tests/feed/FeedBuilderTest.php index 4ca58e5a..1fdbc60e 100644 --- a/tests/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php @@ -1,6 +1,11 @@ assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); - $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); + $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); $this->assertEquals($pub, $up); $this->assertContains('Stallman has a beard', $link['description']); $this->assertContains('Permalink', $link['description']); -- 2.41.0