]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder}
authorVirtualTam <virtualtam@flibidi.net>
Sun, 2 Dec 2018 23:08:04 +0000 (00:08 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Sat, 12 Jan 2019 21:47:48 +0000 (22:47 +0100)
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
application/feed/Cache.php [moved from application/Cache.php with 100% similarity]
application/feed/CachedPage.php [moved from application/CachedPage.php with 93% similarity]
application/feed/FeedBuilder.php [moved from application/FeedBuilder.php with 87% similarity]
composer.json
index.php
plugins/pubsubhubbub/pubsubhubbub.php
tests/LinkDBTest.php
tests/feed/CacheTest.php [moved from tests/CacheTest.php with 68% similarity]
tests/feed/CachedPageTest.php [moved from tests/CachedPageTest.php with 92% similarity]
tests/feed/FeedBuilderTest.php [moved from tests/FeedBuilderTest.php with 97% similarity]

similarity index 93%
rename from application/CachedPage.php
rename to application/feed/CachedPage.php
index e11cc52d01e3aeac07142c476d76e35bf7b88229..1c51ac7397569011a8914abecfc180bbb33b26bb 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+
+namespace Shaarli\Feed;
 /**
  * Simple cache system, mainly for the RSS/ATOM feeds
  */
@@ -24,7 +26,7 @@ class CachedPage
     {
         // TODO: check write access to the cache directory
         $this->cacheDir = $cacheDir;
-        $this->filename = $this->cacheDir.'/'.sha1($url).'.cache';
+        $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache';
         $this->shouldBeCached = $shouldBeCached;
     }
 
similarity index 87%
rename from application/FeedBuilder.php
rename to application/feed/FeedBuilder.php
index 73fafcbed31cb733ac0bf99611313d861a1b60a0..dcfd2c89d62f297c618ab0ff7198d7842445118b 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+namespace Shaarli\Feed;
+
+use DateTime;
+use LinkDB;
 
 /**
  * FeedBuilder class.
@@ -38,12 +42,12 @@ class FeedBuilder
     protected $feedType;
 
     /**
-     * @var array $_SERVER.
+     * @var array $_SERVER
      */
     protected $serverInfo;
 
     /**
-     * @var array $_GET.
+     * @var array $_GET
      */
     protected $userInput;
 
@@ -75,10 +79,10 @@ class FeedBuilder
     /**
      * Feed constructor.
      *
-     * @param LinkDB  $linkDB        LinkDB instance.
-     * @param string  $feedType      Type of feed.
-     * @param array   $serverInfo    $_SERVER.
-     * @param array   $userInput     $_GET.
+     * @param LinkDB  $linkDB     LinkDB instance.
+     * @param string  $feedType   Type of feed.
+     * @param array   $serverInfo $_SERVER.
+     * @param array   $userInput  $_GET.
      * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise.
      */
     public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn)
@@ -124,7 +128,7 @@ class FeedBuilder
         $data['show_dates'] = !$this->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 = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>';
+            $permalink = '<a href="' . $link['url'] . '" title="' . t('Direct link') . '">' . t('Direct link') . '</a>';
         } else {
-            $permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>';
+            $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
         }
-        $link['description']  = format_description($link['description'], '', false, $pageaddr);
-        $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink;
+        $link['description'] = format_description($link['description'], '', false, $pageaddr);
+        $link['description'] .= PHP_EOL . '<br>&#8212; ' . $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;
         }
 
index 027203f48304ceb197b1342d736e4572301d9ab1..7c9cbf3d431924957db625a396c37d32f7d16175 100644 (file)
@@ -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"
         }
     }
index cc41d80c8b415b6ffbccadc7a5e11d3d4a577eaf..6d1ae3fc3b0cb1ab7b1d6e2edbecb368f98c3965 100644 (file)
--- 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;
index 9f0342a37fa376b20cdab8dac2a655c0c178ea5b..1872af8a1da0c20fad05e693ff82fb9b43230c47 100644 (file)
@@ -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.
index 9b2f35e6a678ff6fc97a1d2a2f0157864f6ad096..737a2247d03bd7404a9c9ca27961aecd79f596f1 100644 (file)
@@ -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';
similarity index 68%
rename from tests/CacheTest.php
rename to tests/feed/CacheTest.php
index f60fad91099048ba5d1c8c2d3d34289175880a4f..c0a9f26f2dc933d7adf8644a8b580d797efe01de 100644 (file)
@@ -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);
similarity index 92%
rename from tests/CachedPageTest.php
rename to tests/feed/CachedPageTest.php
index 51565cd63f591c5e69ff41a1eb29d1e616b52cba..0bcc1442c7133bbf41bba1348213a9143352d328 100644 (file)
@@ -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';
     }
 
     /**
similarity index 97%
rename from tests/FeedBuilderTest.php
rename to tests/feed/FeedBuilderTest.php
index 4ca58e5a3b514bf20f21a4597c3d49fb927c1378..1fdbc60e3816b340efc202ffc25383d1e94c3f9e 100644 (file)
@@ -1,6 +1,11 @@
 <?php
 
-require_once 'application/FeedBuilder.php';
+namespace Shaarli\Feed;
+
+use DateTime;
+use LinkDB;
+use ReferenceLinkDB;
+
 require_once 'application/LinkDB.php';
 
 /**
@@ -8,7 +13,7 @@ require_once 'application/LinkDB.php';
  *
  * Unit tests for FeedBuilder.
  */
-class FeedBuilderTest extends PHPUnit_Framework_TestCase
+class FeedBuilderTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string locale Basque (Spain).
@@ -90,7 +95,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
         $this->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']);