]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
namespacing: \Shaarli\History
authorVirtualTam <virtualtam@flibidi.net>
Sun, 2 Dec 2018 22:24:58 +0000 (23:24 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Sat, 12 Jan 2019 21:47:48 +0000 (22:47 +0100)
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
13 files changed:
application/History.php
application/NetscapeBookmarkUtils.php
application/api/controllers/ApiController.php
index.php
tests/HistoryTest.php
tests/NetscapeBookmarkUtils/BookmarkImportTest.php
tests/api/controllers/history/HistoryTest.php
tests/api/controllers/links/DeleteLinkTest.php
tests/api/controllers/links/PostLinkTest.php
tests/api/controllers/links/PutLinkTest.php
tests/api/controllers/tags/DeleteTagTest.php
tests/api/controllers/tags/PutTagTest.php
tests/utils/ReferenceHistory.php

index 35ec016a9be27c374dec0e96cbcd0d27e20a119a..8074a0172c634912adf507bcd2236d8419cffe81 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+namespace Shaarli;
+
+use DateTime;
+use Exception;
+use FileUtils;
 
 /**
  * Class History
@@ -141,7 +146,7 @@ class History
      * Save a new event and write it in the history file.
      *
      * @param string $status Event key, should be defined as constant.
-     * @param mixed  $id     Event item identifier (e.g. link ID).
+     * @param mixed $id Event item identifier (e.g. link ID).
      */
     protected function addEvent($status, $id = null)
     {
@@ -166,11 +171,11 @@ class History
      */
     protected function check()
     {
-        if (! is_file($this->historyFilePath)) {
+        if (!is_file($this->historyFilePath)) {
             FileUtils::writeFlatDB($this->historyFilePath, []);
         }
 
-        if (! is_writable($this->historyFilePath)) {
+        if (!is_writable($this->historyFilePath)) {
             throw new Exception(t('History file isn\'t readable or writable'));
         }
     }
@@ -191,7 +196,7 @@ class History
      */
     protected function write()
     {
-        $comparaison = new DateTime('-'. $this->retentionTime . ' seconds');
+        $comparaison = new DateTime('-' . $this->retentionTime . ' seconds');
         foreach ($this->history as $key => $value) {
             if ($value['datetime'] < $comparaison) {
                 unset($this->history[$key]);
index 84dd2b2083e36f8d20755fbdb2d97502c83b15cd..c0c007ea4a120ac3b11f5e883e512e7e334e504f 100644 (file)
@@ -2,6 +2,7 @@
 
 use Psr\Log\LogLevel;
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
 use Katzgrau\KLogger\Logger;
 
index 9edefcf627f1f4fe7026f07f7e438bdd3d68080e..47e0e1780919e6fc2b943d708ea0ef5672c0dc72 100644 (file)
@@ -30,7 +30,7 @@ abstract class ApiController
     protected $linkDb;
 
     /**
-     * @var \History
+     * @var \Shaarli\History
      */
     protected $history;
 
index acfcc660bad686182b9f4fe1294b39a51152de87..cc41d80c8b415b6ffbccadc7a5e11d3d4a577eaf 100644 (file)
--- a/index.php
+++ b/index.php
@@ -76,6 +76,7 @@ require_once 'application/PluginManager.php';
 require_once 'application/Router.php';
 require_once 'application/Updater.php';
 use \Shaarli\Config\ConfigManager;
+use Shaarli\History;
 use \Shaarli\Languages;
 use \Shaarli\Security\LoginManager;
 use \Shaarli\Security\SessionManager;
index d3bef5a332cec8336455d00fc80c51d43b6bae23..7723c4617767be50e21af98779fa14a34cac9291 100644 (file)
@@ -1,9 +1,12 @@
 <?php
 
-require_once 'application/History.php';
+namespace Shaarli;
 
+use DateTime;
+use Exception;
+use FileUtils;
 
-class HistoryTest extends PHPUnit_Framework_TestCase
+class HistoryTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string History file path
index f0a958cb2e71fed3cd747ef10f906b38b82efc1b..07411c85cfd7b0faa3c6f173ae1285ddeb775c13 100644 (file)
@@ -3,6 +3,7 @@
 require_once 'application/NetscapeBookmarkUtils.php';
 
 use Shaarli\Config\ConfigManager;
+use Shaarli\History;
 
 /**
  * Utility function to load a file's metadata in a $_FILES-like array
index ff34e16dce598be8e849fba6fac30887908cc875..24efee89baf5d4f2e60786ef842ea8e00448a45f 100644 (file)
@@ -49,7 +49,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = true;
-        $this->container['history'] = new \History(self::$testHistory);
+        $this->container['history'] = new \Shaarli\History(self::$testHistory);
 
         $this->controller = new History($this->container);
     }
@@ -78,35 +78,35 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals($this->refHistory->count(), count($data));
 
-        $this->assertEquals(\History::DELETED, $data[0]['event']);
+        $this->assertEquals(\Shaarli\History::DELETED, $data[0]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
             $data[0]['datetime']
         );
         $this->assertEquals(124, $data[0]['id']);
 
-        $this->assertEquals(\History::SETTINGS, $data[1]['event']);
+        $this->assertEquals(\Shaarli\History::SETTINGS, $data[1]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
             $data[1]['datetime']
         );
         $this->assertNull($data[1]['id']);
 
-        $this->assertEquals(\History::UPDATED, $data[2]['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $data[2]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM),
             $data[2]['datetime']
         );
         $this->assertEquals(123, $data[2]['id']);
 
-        $this->assertEquals(\History::CREATED, $data[3]['event']);
+        $this->assertEquals(\Shaarli\History::CREATED, $data[3]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM),
             $data[3]['datetime']
         );
         $this->assertEquals(124, $data[3]['id']);
 
-        $this->assertEquals(\History::CREATED, $data[4]['event']);
+        $this->assertEquals(\Shaarli\History::CREATED, $data[4]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
             $data[4]['datetime']
@@ -131,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals(1, count($data));
 
-        $this->assertEquals(\History::DELETED, $data[0]['event']);
+        $this->assertEquals(\Shaarli\History::DELETED, $data[0]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
             $data[0]['datetime']
@@ -156,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals(1, count($data));
 
-        $this->assertEquals(\History::CREATED, $data[0]['event']);
+        $this->assertEquals(\Shaarli\History::CREATED, $data[0]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
             $data[0]['datetime']
@@ -181,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals(1, count($data));
 
-        $this->assertEquals(\History::DELETED, $data[0]['event']);
+        $this->assertEquals(\Shaarli\History::DELETED, $data[0]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
             $data[0]['datetime']
@@ -206,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals(1, count($data));
 
-        $this->assertEquals(\History::SETTINGS, $data[0]['event']);
+        $this->assertEquals(\Shaarli\History::SETTINGS, $data[0]['event']);
         $this->assertEquals(
             \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
             $data[0]['datetime']
index 7d79713779cc70bf1c18c3ae3803196be6af3990..07371e7abc27f0138cef87423df96cdbdeec8e67 100644 (file)
@@ -37,7 +37,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
     protected $linkDB;
 
     /**
-     * @var \History instance.
+     * @var \Shaarli\History instance.
      */
     protected $history;
 
@@ -62,7 +62,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
         $this->linkDB = new \LinkDB(self::$testDatastore, true, false);
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
-        $this->history = new \History(self::$testHistory);
+        $this->history = new \Shaarli\History(self::$testHistory);
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = $this->linkDB;
@@ -100,7 +100,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse(isset($this->linkDB[$id]));
 
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::DELETED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::DELETED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
index 5c2b56232c4691529c0aa8ac96904a1c4ec9ec54..a73f443c47789dd9db5f5f93362e6ca43198880a 100644 (file)
@@ -40,7 +40,7 @@ class PostLinkTest extends TestCase
     protected $refDB = null;
 
     /**
-     * @var \History instance.
+     * @var \Shaarli\History instance.
      */
     protected $history;
 
@@ -70,12 +70,12 @@ class PostLinkTest extends TestCase
 
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
-        $this->history = new \History(self::$testHistory);
+        $this->history = new \Shaarli\History(self::$testHistory);
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
-        $this->container['history'] = new \History(self::$testHistory);
+        $this->container['history'] = new \Shaarli\History(self::$testHistory);
 
         $this->controller = new Links($this->container);
 
@@ -133,7 +133,7 @@ class PostLinkTest extends TestCase
         $this->assertEquals('', $data['updated']);
 
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::CREATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::CREATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
index f276b4c179df6edcec3c7896c4621bc7bdc93bf1..3bb4d43f7f17dd7c5c45dbcaf413ffd16515b63c 100644 (file)
@@ -32,7 +32,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
     protected $refDB = null;
 
     /**
-     * @var \History instance.
+     * @var \Shaarli\History instance.
      */
     protected $history;
 
@@ -62,12 +62,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
 
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
-        $this->history = new \History(self::$testHistory);
+        $this->history = new \Shaarli\History(self::$testHistory);
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
-        $this->container['history'] = new \History(self::$testHistory);
+        $this->container['history'] = new \Shaarli\History(self::$testHistory);
 
         $this->controller = new Links($this->container);
 
@@ -119,7 +119,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
         );
 
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
index e0787ce2cfa213f356e6a770f1875fc24364e73f..a1e419cda1a767bd3f5295ebe27d895be574fd0d 100644 (file)
@@ -37,7 +37,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
     protected $linkDB;
 
     /**
-     * @var \History instance.
+     * @var \Shaarli\History instance.
      */
     protected $history;
 
@@ -62,7 +62,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
         $this->linkDB = new \LinkDB(self::$testDatastore, true, false);
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
-        $this->history = new \History(self::$testHistory);
+        $this->history = new \Shaarli\History(self::$testHistory);
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = $this->linkDB;
@@ -103,12 +103,12 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
 
         // 2 links affected
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
         $historyEntry = $this->history->getHistory()[1];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
@@ -137,7 +137,7 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($tags[strtolower($tagName)] > 0);
 
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
index 3801724304d9b011c88325ff60d77fc8e0cf826f..c45fa7222a46426f71e56540e8327e7d4913cb20 100644 (file)
@@ -33,7 +33,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
     protected $refDB = null;
 
     /**
-     * @var \History instance.
+     * @var \Shaarli\History instance.
      */
     protected $history;
 
@@ -68,7 +68,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
 
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
-        $this->history = new \History(self::$testHistory);
+        $this->history = new \Shaarli\History(self::$testHistory);
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
@@ -113,12 +113,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(2, $tags[$newName]);
 
         $historyEntry = $this->history->getHistory()[0];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
         $historyEntry = $this->history->getHistory()[1];
-        $this->assertEquals(\History::UPDATED, $historyEntry['event']);
+        $this->assertEquals(\Shaarli\History::UPDATED, $historyEntry['event']);
         $this->assertTrue(
             (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
         );
index 75cbb32629a3668fcde141619afde6514a360210..f19cdf2fbd9abd94cdca7628ada7a42ae20a8529 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Shaarli\History;
+
 /**
  * Populates a reference history
  */