]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Profiler.php
Merge pull request #11973 from MrPetovan/task/test-fixDateFormat
[friendica.git] / src / Util / Profiler.php
index 23eb1d8c333e645fc9cba6d5a067f4af8239bf9d..a98e728928765fe6a61fd30d493ec5abecf20293 100644 (file)
@@ -69,21 +69,27 @@ class Profiler implements ContainerInterface
        /**
         * Updates the enabling of the current profiler
         *
+        * Note: The reason there are two different ways of updating the configuration of this class is because it can
+        * be used even with no available database connection which IManageConfigValues doesn't ensure.
+        *
         * @param IManageConfigValues $config
         */
        public function update(IManageConfigValues $config)
        {
-               $this->enabled = $config->get('system', 'profiler');
-               $this->rendertime = $config->get('rendertime', 'callstack');
+               $this->enabled = (bool) $config->get('system', 'profiler') ?? false;
+               $this->rendertime = (bool) $config->get('rendertime', 'callstack') ?? false;
        }
 
        /**
+        * Note: The reason we are using a Config Cache object to initialize this class is to ensure it'll work even with no
+        * available database connection.
+        *
         * @param \Friendica\Core\Config\ValueObject\Cache $configCache The configuration cache
         */
        public function __construct(Cache $configCache)
        {
-               $this->enabled = $configCache->get('system', 'profiler');
-               $this->rendertime = $configCache->get('rendertime', 'callstack');
+               $this->enabled = (bool) $configCache->get('system', 'profiler') ?? false;
+               $this->rendertime = (bool) $configCache->get('rendertime', 'callstack') ?? false;
                $this->reset();
        }
 
@@ -146,13 +152,13 @@ class Profiler implements ContainerInterface
         * Saves a timestamp for a value - f.e. a call
         * Necessary for profiling Friendica
         *
-        * @param int    $timestamp the Timestamp
+        * @param float  $timestamp the Timestamp
         * @param string $value     A value to profile
         * @param string $callstack A callstack string, generated if absent
         *
         * @return void
         */
-       public function saveTimestamp(int $timestamp, string $value, string $callstack = '')
+       public function saveTimestamp(float $timestamp, string $value, string $callstack = '')
        {
                if (!$this->enabled) {
                        return;
@@ -352,9 +358,9 @@ class Profiler implements ContainerInterface
         * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
         * @throws ContainerExceptionInterface Error while retrieving the entry.
         *
-        * @return int Entry.
+        * @return float Entry.
         */
-       public function get(string $id): int
+       public function get(string $id): float
        {
                if (!$this->has($id)) {
                        return 0;