From 02e030ee78aabfe2b8453dbe03f05459a353d7eb Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Fri, 2 May 2014 12:16:40 +1200
Subject: [PATCH] Refs #5037 Refactor the factory out of the Period class in
 its own Period\Factory class

---
 core/Archive.php                              |   3 +-
 core/DataTable.php                            |   2 +-
 core/DataTable/Renderer/Csv.php               |   2 +-
 core/Period.php                               |  94 +--------------
 core/Period/Factory.php                       | 110 ++++++++++++++++++
 core/Period/Range.php                         |   4 +-
 core/Plugin/Controller.php                    |  58 ++++++---
 plugins/API/ProcessedReport.php               |   2 +-
 plugins/Annotations/API.php                   |   2 +-
 plugins/CoreAdminHome/API.php                 |   2 +-
 plugins/Live/API.php                          |   2 +-
 plugins/Transitions/API.php                   |   4 +-
 plugins/VisitTime/API.php                     |   2 +-
 plugins/VisitTime/VisitTime.php               |   2 +-
 .../Benchmarks/ArchiveQueryBenchmark.php      |   2 +-
 tests/PHPUnit/Core/PeriodTest.php             |  10 +-
 .../Core/ArchiveProcessingTest.php            |   2 +-
 17 files changed, 176 insertions(+), 127 deletions(-)
 create mode 100644 core/Period/Factory.php

diff --git a/core/Archive.php b/core/Archive.php
index e5884aea70..f4732c2751 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -13,6 +13,7 @@ use Piwik\Archive\Parameters;
 use Piwik\ArchiveProcessor\Rules;
 use Piwik\DataAccess\ArchiveSelector;
 use Piwik\Period\Range;
+use Piwik\Period\Factory;
 
 /**
  * The **Archive** class is used to query cached analytics statistics
@@ -204,7 +205,7 @@ class Archive
             $allPeriods = $oPeriod->getSubperiods();
         } else {
             $timezone = count($websiteIds) == 1 ? Site::getTimezoneFor($websiteIds[0]) : false;
-            $oPeriod = Period::makePeriodFromQueryParams($timezone, $period, $strDate);
+            $oPeriod = Factory::makePeriodFromQueryParams($timezone, $period, $strDate);
             $allPeriods = array($oPeriod);
         }
         $segment = new Segment($segment, $websiteIds);
diff --git a/core/DataTable.php b/core/DataTable.php
index b70ef4bde7..6d75b5f71b 100644
--- a/core/DataTable.php
+++ b/core/DataTable.php
@@ -139,7 +139,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
  * 
  *     $dataTable = \Piwik\Plugins\Referrers\API::getInstance()->getSearchEngines($idSite = 1, $period = 'day', $date = '2007-07-24');
  *     $oldPeriod = $dataTable->metadata['period'];
- *     $dataTable->metadata['period'] = Period::factory('week', Date::factory('2013-10-18'));
+ *     $dataTable->metadata['period'] = Period\Factory::build('week', Date::factory('2013-10-18'));
  * 
  * **Serializing & unserializing**
  * 
diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php
index cc9030d4a0..75d6d68fc0 100644
--- a/core/DataTable/Renderer/Csv.php
+++ b/core/DataTable/Renderer/Csv.php
@@ -341,7 +341,7 @@ class Csv extends Renderer
             } else if (strpos($date, ',') !== false) {
                 $period = new Range('range', $date);
             } else {
-                $period = Period::factory($period, Date::factory($date));
+                $period = Period\Factory::build($period, Date::factory($date));
             }
 
             $prettyDate = $period->getLocalizedLongString();
diff --git a/core/Period.php b/core/Period.php
index f97fbcaa33..f224dfc326 100644
--- a/core/Period.php
+++ b/core/Period.php
@@ -11,9 +11,9 @@ namespace Piwik;
 use Exception;
 use Piwik\Period\Day;
 use Piwik\Period\Month;
-use Piwik\Period\Range;
 use Piwik\Period\Week;
 use Piwik\Period\Year;
+use Piwik\Period\Range;
 
 /**
  * Date range representation.
@@ -26,16 +26,8 @@ use Piwik\Period\Year;
  * There are five types of periods in Piwik: day, week, month, year and range,
  * where **range** is any date range. The reason the other periods exist instead
  * of just **range** is that Piwik will pre-archive reports for days, weeks, months
- * and years, while every other date range is archived on-demand.
- * 
- * ### Examples
- * 
- * **Building a period from 'date' and 'period' query parameters**
- * 
- *     $date = Common::getRequestVar('date', null, 'string');
- *     $period = Common::getRequestVar('period', null, 'string');
- *     $periodObject = Period::advancedFactory($period, $date);
- * 
+ * and years, while every custom date range is archived on-demand.
+ *
  * @api
  */
 abstract class Period
@@ -68,51 +60,6 @@ abstract class Period
         $this->date = clone $date;
     }
 
-    /**
-     * Creates a new Period instance with a period ID and {@link Date} instance.
-     * 
-     * _Note: This method cannot create {@link Period\Range} periods._
-     * 
-     * @param string $strPeriod `"day"`, `"week"`, `"month"`, `"year"`, `"range"`.
-     * @param Date|string $date A date within the period or the range of dates.
-     * @throws Exception If `$strPeriod` is invalid.
-     * @return \Piwik\Period
-     */
-    static public function factory($strPeriod, $date)
-    {
-        if (is_string($date)) {
-            if (Period::isMultiplePeriod($date, $strPeriod) || $strPeriod == 'range') {
-                return new Range($strPeriod, $date);
-            }
-
-            $date = Date::factory($date);
-        }
-
-        switch ($strPeriod) {
-            case 'day':
-                return new Day($date);
-                break;
-
-            case 'week':
-                return new Week($date);
-                break;
-
-            case 'month':
-                return new Month($date);
-                break;
-
-            case 'year':
-                return new Year($date);
-                break;
-
-            default:
-                $message = Piwik::translate(
-                    'General_ExceptionInvalidPeriod', array($strPeriod, 'day, week, month, year, range'));
-                throw new Exception($message);
-                break;
-        }
-    }
-
     /**
      * Returns true if `$dateString` and `$period` represent multiple periods.
      * 
@@ -126,8 +73,8 @@ abstract class Period
      * etc.
      * 
      * @static
-     * @param  $dateString The **date** query parameter value.
-     * @param  $period The **period** query parameter value.
+     * @param  $dateString string The **date** query parameter value.
+     * @param  $period string The **period** query parameter value.
      * @return boolean
      */
     public static function isMultiplePeriod($dateString, $period)
@@ -138,37 +85,6 @@ abstract class Period
             && $period != 'range';
     }
 
-    /**
-     * Creates a Period instance using a period, date and timezone.
-     *
-     * @param string $timezone The timezone of the date. Only used if `$date` is `'now'`, `'today'`,
-     *                         `'yesterday'` or `'yesterdaySameTime'`.
-     * @param string $period The period string: `"day"`, `"week"`, `"month"`, `"year"`, `"range"`.
-     * @param string $date The date or date range string. Can be a special value including
-     *                     `'now'`, `'today'`, `'yesterday'`, `'yesterdaySameTime'`.
-     * @return \Piwik\Period
-     */
-    public static function makePeriodFromQueryParams($timezone, $period, $date)
-    {
-        if (empty($timezone)) {
-            $timezone = 'UTC';
-        }
-
-        if ($period == 'range') {
-            $oPeriod = new Period\Range('range', $date, $timezone, Date::factory('today', $timezone));
-        } else {
-            if (!($date instanceof Date)) {
-                if ($date == 'now' || $date == 'today') {
-                    $date = date('Y-m-d', Date::factory('now', $timezone)->getTimestamp());
-                } elseif ($date == 'yesterday' || $date == 'yesterdaySameTime') {
-                    $date = date('Y-m-d', Date::factory('now', $timezone)->subDay(1)->getTimestamp());
-                }
-                $date = Date::factory($date);
-            }
-            $oPeriod = Period::factory($period, $date);
-        }
-        return $oPeriod;
-    }
 
     /**
      * Returns the first day of the period.
diff --git a/core/Period/Factory.php b/core/Period/Factory.php
new file mode 100644
index 0000000000..93cbe0fdef
--- /dev/null
+++ b/core/Period/Factory.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Period;
+
+use Exception;
+use Piwik\Date;
+use Piwik\Period;
+use Piwik\Piwik;
+
+class Factory
+{
+    /**
+     * Creates a new Period instance with a period ID and {@link Date} instance.
+     *
+     * _Note: This method cannot create {@link Period\Range} periods._
+     *
+     * @param string $period `"day"`, `"week"`, `"month"`, `"year"`, `"range"`.
+     * @param Date|string $date A date within the period or the range of dates.
+     * @throws Exception If `$strPeriod` is invalid.
+     * @return \Piwik\Period
+     */
+    static public function build($period, $date)
+    {
+        if (is_string($date)) {
+            if (Period::isMultiplePeriod($date, $period) || $period == 'range') {
+                self::checkPeriodIsEnabled('range');
+                return new Range($period, $date);
+            }
+            $date = Date::factory($date);
+        }
+
+        self::checkPeriodIsEnabled($period);
+        switch ($period) {
+            case 'day':
+                return new Day($date);
+                break;
+
+            case 'week':
+                return new Week($date);
+                break;
+
+            case 'month':
+                return new Month($date);
+                break;
+
+            case 'year':
+                return new Year($date);
+                break;
+        }
+
+        self::throwExceptionInvalidPeriod($period);
+    }
+
+    private static function checkPeriodIsEnabled($period)
+    {
+        $enabledPeriodsInAPI = array();
+        if(!in_array($period, $enabledPeriodsInAPI)) {
+            self::throwExceptionInvalidPeriod($period);
+        }
+    }
+
+    /**
+     * @param $strPeriod
+     * @throws \Exception
+     */
+    private static function throwExceptionInvalidPeriod($strPeriod)
+    {
+        $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, 'day, week, month, year, range'));
+        throw new Exception($message);
+    }
+
+
+    /**
+     * Creates a Period instance using a period, date and timezone.
+     *
+     * @param string $timezone The timezone of the date. Only used if `$date` is `'now'`, `'today'`,
+     *                         `'yesterday'` or `'yesterdaySameTime'`.
+     * @param string $period The period string: `"day"`, `"week"`, `"month"`, `"year"`, `"range"`.
+     * @param string $date The date or date range string. Can be a special value including
+     *                     `'now'`, `'today'`, `'yesterday'`, `'yesterdaySameTime'`.
+     * @return \Piwik\Period
+     */
+    public static function makePeriodFromQueryParams($timezone, $period, $date)
+    {
+        if (empty($timezone)) {
+            $timezone = 'UTC';
+        }
+
+        if ($period == 'range') {
+            $oPeriod = new Period\Range('range', $date, $timezone, Date::factory('today', $timezone));
+        } else {
+            if (!($date instanceof Date)) {
+                if ($date == 'now' || $date == 'today') {
+                    $date = date('Y-m-d', Date::factory('now', $timezone)->getTimestamp());
+                } elseif ($date == 'yesterday' || $date == 'yesterdaySameTime') {
+                    $date = date('Y-m-d', Date::factory('now', $timezone)->subDay(1)->getTimestamp());
+                }
+                $date = Date::factory($date);
+            }
+            $oPeriod = Factory::build($period, $date);
+        }
+        return $oPeriod;
+    }
+}
\ No newline at end of file
diff --git a/core/Period/Range.php b/core/Period/Range.php
index ab542fe838..b60cc4ca61 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -338,14 +338,14 @@ class Range extends Period
     protected function fillArraySubPeriods($startDate, $endDate, $period)
     {
         $arrayPeriods = array();
-        $endSubperiod = Period::factory($period, $endDate);
+        $endSubperiod = Period\Factory::build($period, $endDate);
         $arrayPeriods[] = $endSubperiod;
 
         // set end date to start of end period since we're comparing against start date.
         $endDate = $endSubperiod->getDateStart();
         while ($endDate->isLater($startDate)) {
             $endDate = $endDate->addPeriod(-1, $period);
-            $subPeriod = Period::factory($period, $endDate);
+            $subPeriod = Period\Factory::build($period, $endDate);
             $arrayPeriods[] = $subPeriod;
         }
         $arrayPeriods = array_reverse($arrayPeriods);
diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php
index 4cce5d0711..078188a4a6 100644
--- a/core/Plugin/Controller.php
+++ b/core/Plugin/Controller.php
@@ -189,6 +189,40 @@ abstract class Controller
         return $periods;
     }
 
+    /**
+     * @return array
+     */
+    private static function getEnabledPeriodsNames()
+    {
+        $availablePeriods = self::getEnabledPeriodsInUI();
+        $periodNames = array(
+            'day'   => array(
+                'singular' => Piwik::translate('CoreHome_PeriodDay'),
+                'plural' => Piwik::translate('CoreHome_PeriodDays')
+            ),
+            'week'  => array(
+                'singular' => Piwik::translate('CoreHome_PeriodWeek'),
+                'plural' => Piwik::translate('CoreHome_PeriodWeeks')
+            ),
+            'month' => array(
+                'singular' => Piwik::translate('CoreHome_PeriodMonth'),
+                'plural' => Piwik::translate('CoreHome_PeriodMonths')
+            ),
+            'year'  => array(
+                'singular' => Piwik::translate('CoreHome_PeriodYear'),
+                'plural' => Piwik::translate('CoreHome_PeriodYears')
+            ),
+            // Note: plural is not used for date range
+            'range' => array(
+                'singular' => Piwik::translate('General_DateRangeInPeriodList'),
+                'plural' => Piwik::translate('General_DateRangeInPeriodList')
+            ),
+        );
+
+        $periodNames = array_intersect_key($periodNames, array_fill_keys($availablePeriods, true));
+        return $periodNames;
+    }
+
     /**
      * Returns the name of the default method that will be called
      * when visiting: index.php?module=PluginName without the action parameter.
@@ -491,7 +525,7 @@ abstract class Controller
             $periodStr = Common::getRequestVar('period');
             if ($periodStr != 'range') {
                 $date = Date::factory($this->strDate);
-                $period = Period::factory($periodStr, $date);
+                $period = Period\Factory::build($periodStr, $date);
             } else {
                 $period = new Range($periodStr, $rawDate, $this->site->getTimezone());
             }
@@ -693,26 +727,14 @@ abstract class Controller
         $view->displayUniqueVisitors = SettingsPiwik::isUniqueVisitorsEnabled($currentPeriod);
         $availablePeriods = self::getEnabledPeriodsInUI();
         if (!in_array($currentPeriod, $availablePeriods)) {
-            throw new Exception("Period must be one of: " . implode(",", $availablePeriods));
+            throw new Exception("Period must be one of: " . implode(", ", $availablePeriods));
         }
-        $periodNames = array(
-            'day'   => array('singular' => Piwik::translate('CoreHome_PeriodDay'), 'plural' => Piwik::translate('CoreHome_PeriodDays')),
-            'week'  => array('singular' => Piwik::translate('CoreHome_PeriodWeek'), 'plural' => Piwik::translate('CoreHome_PeriodWeeks')),
-            'month' => array('singular' => Piwik::translate('CoreHome_PeriodMonth'), 'plural' => Piwik::translate('CoreHome_PeriodMonths')),
-            'year'  => array('singular' => Piwik::translate('CoreHome_PeriodYear'), 'plural' => Piwik::translate('CoreHome_PeriodYears')),
-            // Note: plural is not used for date range
-            'range' => array('singular' => Piwik::translate('General_DateRangeInPeriodList'), 'plural' => Piwik::translate('General_DateRangeInPeriodList')),
-        );
-
-        $periodNames = array_intersect_key($periodNames, array_fill_keys($availablePeriods, true));
-
         $found = array_search($currentPeriod, $availablePeriods);
-        if ($found !== false) {
-            unset($availablePeriods[$found]);
-        }
+        unset($availablePeriods[$found]);
+
         $view->period = $currentPeriod;
         $view->otherPeriods = $availablePeriods;
-        $view->periodsNames = $periodNames;
+        $view->periodsNames = self::getEnabledPeriodsNames();
     }
 
     /**
@@ -895,7 +917,7 @@ abstract class Controller
      */
     public static function getPrettyDate($date, $period)
     {
-        return self::getCalendarPrettyDate(Period::factory($period, Date::factory($date)));
+        return self::getCalendarPrettyDate(Period\Factory::build($period, Date::factory($date)));
     }
 
     /**
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index cf0908e3f3..702116b4e1 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -423,7 +423,7 @@ class ProcessedReport
         }
         $website = new Site($idSite);
 
-        $period = Period::factory($period, $date);
+        $period = Period\Factory::build($period, $date);
         $period = $period->getLocalizedLongString();
 
         $return = array(
diff --git a/plugins/Annotations/API.php b/plugins/Annotations/API.php
index a390f01883..605064bbec 100755
--- a/plugins/Annotations/API.php
+++ b/plugins/Annotations/API.php
@@ -326,7 +326,7 @@ class API extends \Piwik\Plugin\API
             if ($period == 'range') {
                 $oPeriod = new Range('day', $date);
             } else {
-                $oPeriod = Period::factory($period, Date::factory($date));
+                $oPeriod = Period\Factory::build($period, Date::factory($date));
             }
 
             $startDate = $oPeriod->getDateStart();
diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php
index 8a0f0ed8c9..0c106cbc04 100644
--- a/plugins/CoreAdminHome/API.php
+++ b/plugins/CoreAdminHome/API.php
@@ -123,7 +123,7 @@ class API extends \Piwik\Plugin\API
 
             // but also weeks overlapping several months stored in the month where the week is starting
             /* @var $week Week */
-            $week = Period::factory('week', $date);
+            $week = Period\Factory::build('week', $date);
             $weekAsString = $week->getDateStart()->toString('Y_m');
             $datesByMonth[$weekAsString][] = $date->toString();
 
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 15d3c3e78e..ce9dcb729c 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -626,7 +626,7 @@ class API extends \Piwik\Plugin\API
                 ) {
                     $processedDate = $processedDate->subDay(1);
                 }
-                $processedPeriod = Period::factory($period, $processedDate);
+                $processedPeriod = Period\Factory::build($period, $processedDate);
             }
             $dateStart = $processedPeriod->getDateStart()->setTimezone($currentTimezone);
             $where[] = "log_visit.visit_last_action_time >= ?";
diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php
index 382801d1d0..21cd3ff2a3 100644
--- a/plugins/Transitions/API.php
+++ b/plugins/Transitions/API.php
@@ -73,13 +73,13 @@ class API extends \Piwik\Plugin\API
         // prepare log aggregator
         $segment = new Segment($segment, $idSite);
         $site = new Site($idSite);
-        $period = Period::factory($period, $date);
+        $period = Period\Factory::build($period, $date);
         $params = new ArchiveProcessor\Parameters($site, $period, $segment);
         $logAggregator = new LogAggregator($params);
 
         // prepare the report
         $report = array(
-            'date' => Period::factory($period->getLabel(), $date)->getLocalizedShortString()
+            'date' => Period\Factory::build($period->getLabel(), $date)->getLocalizedShortString()
         );
 
         $partsArray = explode(',', $parts);
diff --git a/plugins/VisitTime/API.php b/plugins/VisitTime/API.php
index 9a53c4e42a..c2bf4241be 100644
--- a/plugins/VisitTime/API.php
+++ b/plugins/VisitTime/API.php
@@ -76,7 +76,7 @@ class API extends \Piwik\Plugin\API
         }
 
         // get metric data for every day within the supplied period
-        $oPeriod = Period::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
+        $oPeriod = Period\Factory::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
         $dateRange = $oPeriod->getDateStart()->toString() . ',' . $oPeriod->getDateEnd()->toString();
         $archive = Archive::build($idSite, 'day', $dateRange, $segment);
 
diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php
index fd09d70ae5..93e8d9ca35 100644
--- a/plugins/VisitTime/VisitTime.php
+++ b/plugins/VisitTime/VisitTime.php
@@ -201,7 +201,7 @@ class VisitTime extends \Piwik\Plugin
 
         // create a period instance
         try {
-            $oPeriod = Period::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
+            $oPeriod = Period\Factory::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
         } catch (Exception $ex) {
             return ''; // if query params are incorrect, forget about the footer message
         }
diff --git a/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php b/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php
index b15ec3068a..cfdea0fd34 100644
--- a/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php
+++ b/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php
@@ -41,7 +41,7 @@ class ArchiveQueryBenchmark extends BenchmarkTestCase
 
         Rules::$archivingDisabledByTests = true;
         
-        $period = Period::factory(self::$fixture->period, Date::factory(self::$fixture->date));
+        $period = Period\Factory::build(self::$fixture->period, Date::factory(self::$fixture->date));
         $dateRange = $period->getDateStart().','.$period->getDateEnd();
         
         API::getInstance()->get(self::$fixture->idSite, 'day', $dateRange);
diff --git a/tests/PHPUnit/Core/PeriodTest.php b/tests/PHPUnit/Core/PeriodTest.php
index 8839090f3d..f8321377d0 100644
--- a/tests/PHPUnit/Core/PeriodTest.php
+++ b/tests/PHPUnit/Core/PeriodTest.php
@@ -57,7 +57,7 @@ class PeriodTest extends PHPUnit_Framework_TestCase
      */
     public function testFactoryDay()
     {
-        $period = Period::factory('day', Date::today());
+        $period = Period\Factory::build('day', Date::today());
         $this->assertInstanceOf('\Piwik\Period\Day', $period);
     }
 
@@ -66,7 +66,7 @@ class PeriodTest extends PHPUnit_Framework_TestCase
      */
     public function testFactoryMonth()
     {
-        $period = Period::factory('month', Date::today());
+        $period = Period\Factory::build('month', Date::today());
         $this->assertInstanceOf('\Piwik\Period\Month', $period);
     }
 
@@ -75,7 +75,7 @@ class PeriodTest extends PHPUnit_Framework_TestCase
      */
     public function testFactoryWeek()
     {
-        $period = Period::factory('week', Date::today());
+        $period = Period\Factory::build('week', Date::today());
         $this->assertInstanceOf('\Piwik\Period\Week', $period);
     }
 
@@ -84,7 +84,7 @@ class PeriodTest extends PHPUnit_Framework_TestCase
      */
     public function testFactoryYear()
     {
-        $period = Period::factory('year', Date::today());
+        $period = Period\Factory::build('year', Date::today());
         $this->assertInstanceOf('\Piwik\Period\Year', $period);
     }
 
@@ -94,7 +94,7 @@ class PeriodTest extends PHPUnit_Framework_TestCase
     public function testFactoryInvalid()
     {
         try {
-            $period = Period::factory('inValid', Date::today());
+            $period = Period\Factory::build('inValid', Date::today());
         } catch (Exception $e) {
             return;
         }
diff --git a/tests/PHPUnit/Integration/Core/ArchiveProcessingTest.php b/tests/PHPUnit/Integration/Core/ArchiveProcessingTest.php
index 64aa187dd4..efaa567d24 100644
--- a/tests/PHPUnit/Integration/Core/ArchiveProcessingTest.php
+++ b/tests/PHPUnit/Integration/Core/ArchiveProcessingTest.php
@@ -88,7 +88,7 @@ class Core_ArchiveProcessingTest extends DatabaseTestCase
     {
         $site = $this->_createWebsite($siteTimezone);
         $date = Date::factory($dateLabel);
-        $period = Period::factory($periodLabel, $date);
+        $period = Period\Factory::build($periodLabel, $date);
         $segment = new Segment('', $site->getId());
 
         $params = new ArchiveProcessor\Parameters($site, $period, $segment);
-- 
GitLab